Flutter Engine
The Flutter Engine
DashPathEffectTestGanesh.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 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
13#include "tests/Test.h"
14
15// Draws a dashed circle with circumference 100, with an on-interval of 90 and an off-interval of
16// 10, offset into the intervals by 25. This should draw a dash clockwise from 3:00 ending around
17// 11:00, then the start of a second dash from 12:00 back to 3:00. In https://crbug.com/1495670, the
18// math for intervals ending very near 2*pi introduced floating point error that prevented drawing
19// the second dash.
20DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(DashPathEffectTest_2PiInterval,
22 contextInfo,
24 const float r = 50.0f / SK_ScalarPI;
25 const float centerX = ceilf(0.5f * r);
26 const float centerY = ceilf(r);
27 const float dashWidth = 10.0f;
28
32 GrDirectContext* context = contextInfo.directContext();
34 SkCanvas* canvas = surface->getCanvas();
35
37 paint.setAntiAlias(true);
38 paint.setColor(SK_ColorRED);
40 paint.setStrokeWidth(dashWidth);
41
42 constexpr float intervals[2] = {90.0f, 10.0f};
43 paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 25.0f));
44 canvas->drawCircle(centerX, centerY, r, paint);
45
46 // Check that we drew the second dash, which starts at the top of the circle.
48 SkPixmap pixmap;
49 bitmap.allocPixels(surface->imageInfo());
50 SkAssertResult(bitmap.peekPixels(&pixmap));
51 if (!surface->readPixels(pixmap, 0, 0)) {
52 ERRORF(reporter, "readPixels failed");
53 return;
54 }
55 SkColor topColor = pixmap.getColor(centerX + 1.0f, centerY - r);
57}
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(DashPathEffectTest_2PiInterval, reporter, contextInfo, CtsEnforcement::kNextRelease)
reporter
Definition: FontMgrTest.cpp:39
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
#define SK_ScalarPI
Definition: SkScalar.h:21
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define ERRORF(r,...)
Definition: Test.h:293
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
static sk_sp< SkPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
SkColor getColor(int x, int y) const
Definition: SkPixmap.cpp:187
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
Definition: bitmap.py:1
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)