2017-10-30 18:02:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkColorSpace.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkStrokeRec.h"
|
2019-05-06 21:17:19 +00:00
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContextOptions.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-05-06 21:17:19 +00:00
|
|
|
#include "include/gpu/GrTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/private/GrTypesPriv.h"
|
2019-05-06 21:17:19 +00:00
|
|
|
#include "include/private/SkColorData.h"
|
|
|
|
#include "src/gpu/GrCaps.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrFragmentProcessor.h"
|
2019-09-30 16:15:30 +00:00
|
|
|
#include "src/gpu/GrImageInfo.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrPaint.h"
|
|
|
|
#include "src/gpu/GrStyle.h"
|
2021-07-28 19:13:20 +00:00
|
|
|
#include "src/gpu/v1/SurfaceDrawContext_v1.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tools/gpu/GrContextFactory.h"
|
2018-04-17 21:42:08 +00:00
|
|
|
|
2018-05-22 14:48:08 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2017-10-30 18:02:48 +00:00
|
|
|
static void only_allow_default(GrContextOptions* options) {
|
|
|
|
options->fGpuPathRenderers = GpuPathRenderers::kNone;
|
|
|
|
}
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
static SkBitmap read_back(GrDirectContext* dContext,
|
|
|
|
skgpu::v1::SurfaceDrawContext* sdc,
|
2020-08-11 16:02:22 +00:00
|
|
|
int width, int height) {
|
2017-10-30 18:02:48 +00:00
|
|
|
|
|
|
|
SkImageInfo dstII = SkImageInfo::MakeN32Premul(width, height);
|
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(dstII);
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->readPixels(dContext, bm.pixmap(), {0, 0});
|
2017-10-30 18:02:48 +00:00
|
|
|
|
|
|
|
return bm;
|
|
|
|
}
|
|
|
|
|
2019-11-26 17:17:17 +00:00
|
|
|
static SkPath make_path(const SkRect& outer, int inset, SkPathFillType fill) {
|
2017-10-30 18:02:48 +00:00
|
|
|
SkPath p;
|
|
|
|
|
2019-11-22 18:34:02 +00:00
|
|
|
p.addRect(outer, SkPathDirection::kCW);
|
|
|
|
p.addRect(outer.makeInset(inset, inset), SkPathDirection::kCCW);
|
2017-10-30 18:02:48 +00:00
|
|
|
p.setFillType(fill);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const int kBigSize = 64; // This should be a power of 2
|
|
|
|
static const int kPad = 3;
|
|
|
|
|
|
|
|
// From crbug.com/769898:
|
|
|
|
// create an approx fit render target context that will have extra space (i.e., npot)
|
|
|
|
// draw an inverse wound concave path into it - forcing use of the stencil-using path renderer
|
|
|
|
// throw the RTC away so the backing GrSurface/GrStencilBuffer can be reused
|
|
|
|
// create a new render target context that will reuse the prior GrSurface
|
|
|
|
// draw a normally wound concave path that touches outside of the approx fit RTC's content rect
|
|
|
|
//
|
2021-08-17 20:42:51 +00:00
|
|
|
// When the bug manifests the DefaultPathRenderer/GrMSAAPathRenderer is/was leaving the stencil
|
2017-10-30 18:02:48 +00:00
|
|
|
// buffer outside of the first content rect in a bad state and the second draw would be incorrect.
|
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
static void run_test(GrDirectContext* dContext, skiatest::Reporter* reporter) {
|
2017-10-30 18:02:48 +00:00
|
|
|
SkPath invPath = make_path(SkRect::MakeXYWH(0, 0, kBigSize, kBigSize),
|
2019-11-26 17:17:17 +00:00
|
|
|
kBigSize/2-1, SkPathFillType::kInverseWinding);
|
2017-10-30 18:02:48 +00:00
|
|
|
SkPath path = make_path(SkRect::MakeXYWH(0, 0, kBigSize, kBigSize),
|
2019-11-26 17:17:17 +00:00
|
|
|
kPad, SkPathFillType::kWinding);
|
2017-10-30 18:02:48 +00:00
|
|
|
|
|
|
|
GrStyle style(SkStrokeRec::kFill_InitStyle);
|
|
|
|
|
|
|
|
{
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc = skgpu::v1::SurfaceDrawContext::Make(dContext, GrColorType::kRGBA_8888, nullptr,
|
|
|
|
SkBackingFit::kApprox,
|
|
|
|
{kBigSize/2 + 1, kBigSize/2 + 1},
|
|
|
|
SkSurfaceProps());
|
2017-10-30 18:02:48 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(SK_PMColor4fBLACK);
|
2017-10-30 18:02:48 +00:00
|
|
|
|
|
|
|
GrPaint paint;
|
|
|
|
|
2018-10-03 20:35:54 +00:00
|
|
|
const SkPMColor4f color = { 1.0f, 0.0f, 0.0f, 1.0f };
|
2021-04-14 15:15:05 +00:00
|
|
|
auto fp = GrFragmentProcessor::MakeColor(color);
|
2020-07-21 16:28:35 +00:00
|
|
|
paint.setColorFragmentProcessor(std::move(fp));
|
2017-10-30 18:02:48 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->drawPath(nullptr, std::move(paint), GrAA::kNo, SkMatrix::I(), invPath, style);
|
2017-10-30 18:02:48 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
dContext->priv().flushSurface(sdc->asSurfaceProxy());
|
2017-10-30 18:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-28 19:13:20 +00:00
|
|
|
auto sdc = skgpu::v1::SurfaceDrawContext::Make(dContext, GrColorType::kRGBA_8888, nullptr,
|
|
|
|
SkBackingFit::kExact, {kBigSize, kBigSize},
|
|
|
|
SkSurfaceProps());
|
2017-10-30 18:02:48 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(SK_PMColor4fBLACK);
|
2017-10-30 18:02:48 +00:00
|
|
|
|
|
|
|
GrPaint paint;
|
|
|
|
|
2018-10-03 20:35:54 +00:00
|
|
|
const SkPMColor4f color = { 0.0f, 1.0f, 0.0f, 1.0f };
|
2021-04-14 15:15:05 +00:00
|
|
|
auto fp = GrFragmentProcessor::MakeColor(color);
|
2020-07-21 16:28:35 +00:00
|
|
|
paint.setColorFragmentProcessor(std::move(fp));
|
2017-10-30 18:02:48 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->drawPath(nullptr, std::move(paint), GrAA::kNo,
|
2017-10-30 18:02:48 +00:00
|
|
|
SkMatrix::I(), path, style);
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
SkBitmap bm = read_back(dContext, sdc.get(), kBigSize, kBigSize);
|
2017-10-30 18:02:48 +00:00
|
|
|
|
|
|
|
bool correct = true;
|
|
|
|
for (int y = kBigSize/2+1; y < kBigSize-kPad-1 && correct; ++y) {
|
|
|
|
for (int x = kPad+1; x < kBigSize-kPad-1 && correct; ++x) {
|
|
|
|
correct = bm.getColor(x, y) == SK_ColorBLACK;
|
|
|
|
REPORTER_ASSERT(reporter, correct);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-17 20:42:51 +00:00
|
|
|
DEF_GPUTEST_FOR_CONTEXTS(DefaultPathRendererTest,
|
2017-10-30 18:02:48 +00:00
|
|
|
sk_gpu_test::GrContextFactory::IsRenderingContext,
|
|
|
|
reporter, ctxInfo, only_allow_default) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto ctx = ctxInfo.directContext();
|
2017-10-30 18:02:48 +00:00
|
|
|
|
|
|
|
run_test(ctx, reporter);
|
|
|
|
}
|