Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
DefaultPathRendererTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
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 "include/core/SkPath.h"
15#include "include/core/SkRect.h"
30#include "tests/Test.h"
32
33#include <memory>
34#include <utility>
35
37 options->fGpuPathRenderers = GpuPathRenderers::kNone;
38}
39
42 int width,
43 int height) {
45
46 SkBitmap bm;
47 bm.allocPixels(dstII);
48
49 sdc->readPixels(dContext, bm.pixmap(), {0, 0});
50
51 return bm;
52}
53
54static SkPath make_path(const SkRect& outer, int inset, SkPathFillType fill) {
55 SkPath p;
56
57 p.addRect(outer, SkPathDirection::kCW);
58 p.addRect(outer.makeInset(inset, inset), SkPathDirection::kCCW);
59 p.setFillType(fill);
60 return p;
61}
62
63
64static const int kBigSize = 64; // This should be a power of 2
65static const int kPad = 3;
66
67// From crbug.com/769898:
68// create an approx fit render target context that will have extra space (i.e., npot)
69// draw an inverse wound concave path into it - forcing use of the stencil-using path renderer
70// throw the RTC away so the backing GrSurface/GrStencilBuffer can be reused
71// create a new render target context that will reuse the prior GrSurface
72// draw a normally wound concave path that touches outside of the approx fit RTC's content rect
73//
74// When the bug manifests the DefaultPathRenderer/GrMSAAPathRenderer is/was leaving the stencil
75// buffer outside of the first content rect in a bad state and the second draw would be incorrect.
76
82
84
85 {
88 nullptr,
90 {kBigSize / 2 + 1, kBigSize / 2 + 1},
92 /*label=*/{});
93
94 sdc->clear(SK_PMColor4fBLACK);
95
97
98 const SkPMColor4f color = { 1.0f, 0.0f, 0.0f, 1.0f };
100 paint.setColorFragmentProcessor(std::move(fp));
101
102 sdc->drawPath(nullptr, std::move(paint), GrAA::kNo, SkMatrix::I(), invPath, style);
103
104 dContext->priv().flushSurface(sdc->asSurfaceProxy());
105 }
106
107 {
108 auto sdc = skgpu::ganesh::SurfaceDrawContext::Make(dContext,
110 nullptr,
114 /*label=*/{});
115
116 sdc->clear(SK_PMColor4fBLACK);
117
119
120 const SkPMColor4f color = { 0.0f, 1.0f, 0.0f, 1.0f };
122 paint.setColorFragmentProcessor(std::move(fp));
123
124 sdc->drawPath(nullptr, std::move(paint), GrAA::kNo,
125 SkMatrix::I(), path, style);
126
127 SkBitmap bm = read_back(dContext, sdc.get(), kBigSize, kBigSize);
128
129 bool correct = true;
130 for (int y = kBigSize/2+1; y < kBigSize-kPad-1 && correct; ++y) {
131 for (int x = kPad+1; x < kBigSize-kPad-1 && correct; ++x) {
132 correct = bm.getColor(x, y) == SK_ColorBLACK;
133 REPORTER_ASSERT(reporter, correct);
134 }
135 }
136 }
137}
138
139DEF_GANESH_TEST_FOR_CONTEXTS(DefaultPathRendererTest,
141 reporter,
142 ctxInfo,
145 auto ctx = ctxInfo.directContext();
146
147 run_test(ctx, reporter);
148}
const char * options
static SkBitmap read_back(GrDirectContext *dContext, skgpu::ganesh::SurfaceDrawContext *sdc, int width, int height)
static void only_allow_default(GrContextOptions *options)
static void run_test(GrDirectContext *dContext, skiatest::Reporter *reporter)
static const int kPad
static const int kBigSize
reporter
SkColor4f color
constexpr SkPMColor4f SK_PMColor4fBLACK
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
SkPathFillType
Definition SkPathTypes.h:11
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define DEF_GANESH_TEST_FOR_CONTEXTS( name, context_filter, reporter, context_info, options_filter, ctsEnforcement)
Definition Test.h:426
GrSemaphoresSubmitted flushSurface(GrSurfaceProxy *proxy, SkSurfaces::BackendSurfaceAccess access=SkSurfaces::BackendSurfaceAccess::kNoAccess, const GrFlushInfo &info={}, const skgpu::MutableTextureState *newState=nullptr)
GrDirectContextPriv priv()
static std::unique_ptr< GrFragmentProcessor > MakeColor(SkPMColor4f color)
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
SkColor getColor(int x, int y) const
Definition SkBitmap.h:874
const SkPixmap & pixmap() const
Definition SkBitmap.h:133
static const SkMatrix & I()
bool readPixels(GrDirectContext *dContext, GrPixmap dst, SkIPoint srcPt)
static std::unique_ptr< SurfaceDrawContext > Make(GrRecordingContext *, GrColorType, sk_sp< GrSurfaceProxy >, sk_sp< SkColorSpace >, GrSurfaceOrigin, const SkSurfaceProps &)
const Paint & paint
double y
double x
bool IsRenderingContext(skgpu::ContextType type)
static SkRect inset(const SkRect &r)
static SkPath make_path()
int32_t height
int32_t width
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659
SkRect makeInset(float dx, float dy) const
Definition SkRect.h:987