2013-08-05 13:28:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
#include "SkTypes.h"
|
|
|
|
|
2013-08-05 13:28:55 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
|
|
|
|
#include "GrContext.h"
|
2015-11-19 15:28:50 +00:00
|
|
|
#include "GrPath.h"
|
|
|
|
#include "GrStrokeInfo.h"
|
2013-08-05 13:28:55 +00:00
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColor.h"
|
|
|
|
#include "SkPaint.h"
|
2015-11-19 04:12:56 +00:00
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkDashPathEffect.h"
|
2013-08-05 13:28:55 +00:00
|
|
|
#include "SkRRect.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "SkRect.h"
|
2014-09-18 13:09:44 +00:00
|
|
|
#include "SkSurface.h"
|
2013-08-05 13:28:55 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
#include <initializer_list>
|
|
|
|
|
2014-01-10 22:08:27 +00:00
|
|
|
static void test_drawPathEmpty(skiatest::Reporter*, SkCanvas* canvas) {
|
2013-08-05 13:28:55 +00:00
|
|
|
// Filling an empty path should not crash.
|
|
|
|
SkPaint paint;
|
2015-11-19 04:12:56 +00:00
|
|
|
SkRect emptyRect = SkRect::MakeEmpty();
|
|
|
|
canvas->drawRect(emptyRect, paint);
|
2013-08-05 13:28:55 +00:00
|
|
|
canvas->drawPath(SkPath(), paint);
|
2015-11-19 04:12:56 +00:00
|
|
|
canvas->drawOval(emptyRect, paint);
|
|
|
|
canvas->drawRect(emptyRect, paint);
|
|
|
|
canvas->drawRRect(SkRRect::MakeRect(emptyRect), paint);
|
2013-08-05 13:28:55 +00:00
|
|
|
|
|
|
|
// Stroking an empty path should not crash.
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setColor(SK_ColorGRAY);
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(20));
|
|
|
|
paint.setStrokeJoin(SkPaint::kRound_Join);
|
2015-11-19 04:12:56 +00:00
|
|
|
canvas->drawRect(emptyRect, paint);
|
2013-08-05 13:28:55 +00:00
|
|
|
canvas->drawPath(SkPath(), paint);
|
2015-11-19 04:12:56 +00:00
|
|
|
canvas->drawOval(emptyRect, paint);
|
|
|
|
canvas->drawRect(emptyRect, paint);
|
|
|
|
canvas->drawRRect(SkRRect::MakeRect(emptyRect), paint);
|
2013-08-05 13:28:55 +00:00
|
|
|
}
|
|
|
|
|
2015-11-19 04:12:56 +00:00
|
|
|
static void fill_and_stroke(SkCanvas* canvas, const SkPath& p1, const SkPath& p2,
|
|
|
|
SkPathEffect* effect) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setPathEffect(effect);
|
|
|
|
|
|
|
|
canvas->drawPath(p1, paint);
|
|
|
|
canvas->drawPath(p2, paint);
|
|
|
|
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
canvas->drawPath(p1, paint);
|
|
|
|
canvas->drawPath(p2, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_drawSameRectOvals(skiatest::Reporter*, SkCanvas* canvas) {
|
|
|
|
// Drawing ovals with similar bounds but different points order should not crash.
|
|
|
|
|
|
|
|
SkPath oval1, oval2;
|
|
|
|
const SkRect rect = SkRect::MakeWH(100, 50);
|
|
|
|
oval1.addOval(rect, SkPath::kCW_Direction);
|
|
|
|
oval2.addOval(rect, SkPath::kCCW_Direction);
|
|
|
|
|
|
|
|
fill_and_stroke(canvas, oval1, oval2, nullptr);
|
|
|
|
|
|
|
|
const SkScalar intervals[] = { 1, 1 };
|
|
|
|
SkAutoTUnref<SkPathEffect> dashEffect(SkDashPathEffect::Create(intervals, 2, 0));
|
|
|
|
fill_and_stroke(canvas, oval1, oval2, dashEffect);
|
|
|
|
}
|
2015-11-18 22:07:13 +00:00
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
DEF_GPUTEST_FOR_ALL_CONTEXTS(GpuDrawPath, reporter, context) {
|
|
|
|
for (auto& test_func : { &test_drawPathEmpty, &test_drawSameRectOvals }) {
|
|
|
|
for (auto& sampleCount : {0, 4, 16}) {
|
2014-09-18 13:09:44 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(255, 255);
|
2015-01-16 15:32:33 +00:00
|
|
|
SkAutoTUnref<SkSurface> surface(
|
2016-02-25 16:33:02 +00:00
|
|
|
SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info,
|
2015-12-01 12:35:26 +00:00
|
|
|
sampleCount, nullptr));
|
2015-11-19 17:37:02 +00:00
|
|
|
if (!surface) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-12-01 12:35:26 +00:00
|
|
|
test_func(reporter, surface->getCanvas());
|
2013-08-05 13:28:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-01 12:35:26 +00:00
|
|
|
DEF_GPUTEST(GrPathKeys, reporter, /*factory*/) {
|
2015-11-19 15:28:50 +00:00
|
|
|
// Keys should not ignore conic weights.
|
|
|
|
SkPath path1, path2;
|
|
|
|
path1.setIsVolatile(true);
|
|
|
|
path2.setIsVolatile(true);
|
|
|
|
SkPoint p0 = SkPoint::Make(100, 0);
|
|
|
|
SkPoint p1 = SkPoint::Make(100, 100);
|
|
|
|
|
|
|
|
path1.conicTo(p0, p1, .5f);
|
|
|
|
path2.conicTo(p0, p1, .7f);
|
|
|
|
|
|
|
|
bool isVolatile;
|
|
|
|
GrUniqueKey key1, key2;
|
|
|
|
GrStrokeInfo stroke(SkStrokeRec::kFill_InitStyle);
|
|
|
|
GrPath::ComputeKey(path1, stroke, &key1, &isVolatile);
|
|
|
|
GrPath::ComputeKey(path2, stroke, &key2, &isVolatile);
|
2015-11-26 09:51:44 +00:00
|
|
|
REPORTER_ASSERT(reporter, key1 != key2);
|
2015-11-19 15:28:50 +00:00
|
|
|
}
|
|
|
|
|
2013-08-05 13:28:55 +00:00
|
|
|
#endif
|