1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2021 Google LLC. 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 10cb93a386Sopenharmony_ci#include "include/core/SkCanvas.h" 11cb93a386Sopenharmony_ci#include "include/core/SkPaint.h" 12cb93a386Sopenharmony_ci#include "include/core/SkPath.h" 13cb93a386Sopenharmony_ci#include "include/gpu/GrContextOptions.h" 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_cinamespace skiagm { 16cb93a386Sopenharmony_ci 17cb93a386Sopenharmony_ciclass BatchedConvexPathsGM : public GM { 18cb93a386Sopenharmony_ciprivate: 19cb93a386Sopenharmony_ci SkString onShortName() override { return SkString("batchedconvexpaths"); } 20cb93a386Sopenharmony_ci SkISize onISize() override { return SkISize::Make(512, 512); } 21cb93a386Sopenharmony_ci 22cb93a386Sopenharmony_ci void modifyGrContextOptions(GrContextOptions* ctxOptions) override { 23cb93a386Sopenharmony_ci // Ensure our paths don't go through the atlas path renderer. 24cb93a386Sopenharmony_ci ctxOptions->fGpuPathRenderers &= ~GpuPathRenderers::kAtlas; 25cb93a386Sopenharmony_ci } 26cb93a386Sopenharmony_ci 27cb93a386Sopenharmony_ci DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override { 28cb93a386Sopenharmony_ci canvas->clear(SK_ColorBLACK); 29cb93a386Sopenharmony_ci for (uint32_t i = 0; i < 10; ++i) { 30cb93a386Sopenharmony_ci SkAutoCanvasRestore acr(canvas, true); 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_ci int numPoints = (i + 3) * 3; 33cb93a386Sopenharmony_ci SkPath path; 34cb93a386Sopenharmony_ci path.moveTo(1, 0); 35cb93a386Sopenharmony_ci for (float j = 1; j < numPoints; j += 3) { 36cb93a386Sopenharmony_ci constexpr float k2PI = SK_ScalarPI * 2; 37cb93a386Sopenharmony_ci path.cubicTo(cosf(j/numPoints * k2PI), sinf(j/numPoints * k2PI), 38cb93a386Sopenharmony_ci cosf((j+1)/numPoints * k2PI), sinf((j+1)/numPoints * k2PI), 39cb93a386Sopenharmony_ci j+2 == numPoints ? 1 : cosf((j+2)/numPoints * k2PI), 40cb93a386Sopenharmony_ci j+2 == numPoints ? 0 : sinf((j+2)/numPoints * k2PI)); 41cb93a386Sopenharmony_ci } 42cb93a386Sopenharmony_ci float scale = 256 - i*24; 43cb93a386Sopenharmony_ci canvas->translate(scale + (256 - scale) * .33f, scale + (256 - scale) * .33f); 44cb93a386Sopenharmony_ci canvas->scale(scale, scale); 45cb93a386Sopenharmony_ci 46cb93a386Sopenharmony_ci SkPaint paint; 47cb93a386Sopenharmony_ci paint.setColor(((i + 123458383u) * 285018463u) | 0xff808080); 48cb93a386Sopenharmony_ci paint.setAlphaf(0.3f); 49cb93a386Sopenharmony_ci paint.setAntiAlias(true); 50cb93a386Sopenharmony_ci 51cb93a386Sopenharmony_ci canvas->drawPath(path, paint); 52cb93a386Sopenharmony_ci } 53cb93a386Sopenharmony_ci return DrawResult::kOk; 54cb93a386Sopenharmony_ci } 55cb93a386Sopenharmony_ci}; 56cb93a386Sopenharmony_ci 57cb93a386Sopenharmony_ciDEF_GM( return new BatchedConvexPathsGM; ) 58cb93a386Sopenharmony_ci 59cb93a386Sopenharmony_ci} // namespace skiagm 60