2020-06-16 21:56:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
2020-09-17 18:16:54 +00:00
|
|
|
#include "include/gpu/GrContextOptions.h"
|
2021-06-03 14:14:16 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2021-07-23 21:33:09 +00:00
|
|
|
#include "include/utils/SkRandom.h"
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrCaps.h"
|
|
|
|
#include "src/gpu/ganesh/GrDirectContextPriv.h"
|
|
|
|
#include "src/gpu/ganesh/GrDrawingManager.h"
|
|
|
|
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
|
|
|
|
#include "src/gpu/ganesh/ops/TessellationPathRenderer.h"
|
2020-06-16 21:56:16 +00:00
|
|
|
|
|
|
|
static constexpr float kStrokeWidth = 100;
|
2020-09-17 18:16:54 +00:00
|
|
|
static constexpr int kTestWidth = 120 * 4;
|
|
|
|
static constexpr int kTestHeight = 120 * 3 + 140;
|
|
|
|
|
2021-05-11 18:36:51 +00:00
|
|
|
static void draw_strokes(SkCanvas* canvas, SkRandom* rand, const SkPath& path,
|
2020-09-17 18:16:54 +00:00
|
|
|
const SkPath& cubic) {
|
|
|
|
SkPaint strokePaint;
|
|
|
|
strokePaint.setAntiAlias(true);
|
|
|
|
strokePaint.setStrokeWidth(kStrokeWidth);
|
|
|
|
strokePaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
SkAutoCanvasRestore arc(canvas, true);
|
|
|
|
strokePaint.setStrokeJoin(SkPaint::kBevel_Join);
|
2021-05-11 18:36:51 +00:00
|
|
|
strokePaint.setColor(rand->nextU() | 0xff808080);
|
2020-09-17 18:16:54 +00:00
|
|
|
canvas->drawPath(path, strokePaint);
|
|
|
|
|
|
|
|
canvas->translate(120, 0);
|
|
|
|
strokePaint.setStrokeJoin(SkPaint::kRound_Join);
|
2021-05-11 18:36:51 +00:00
|
|
|
strokePaint.setColor(rand->nextU() | 0xff808080);
|
2020-09-17 18:16:54 +00:00
|
|
|
canvas->drawPath(path, strokePaint);
|
|
|
|
|
|
|
|
canvas->translate(120, 0);
|
|
|
|
strokePaint.setStrokeJoin(SkPaint::kMiter_Join);
|
2021-05-11 18:36:51 +00:00
|
|
|
strokePaint.setColor(rand->nextU() | 0xff808080);
|
2020-09-17 18:16:54 +00:00
|
|
|
canvas->drawPath(path, strokePaint);
|
|
|
|
|
|
|
|
canvas->translate(120, 0);
|
2021-05-11 18:36:51 +00:00
|
|
|
strokePaint.setColor(rand->nextU() | 0xff808080);
|
2020-09-17 18:16:54 +00:00
|
|
|
canvas->drawPath(cubic, strokePaint);
|
|
|
|
}
|
|
|
|
|
2021-05-11 18:36:51 +00:00
|
|
|
static void draw_test(SkCanvas* canvas) {
|
|
|
|
SkRandom rand;
|
|
|
|
|
|
|
|
if (canvas->recordingContext() &&
|
|
|
|
canvas->recordingContext()->priv().caps()->shaderCaps()->tessellationSupport() &&
|
2021-05-26 05:49:39 +00:00
|
|
|
canvas->recordingContext()->priv().caps()->shaderCaps()->maxTessellationSegments() == 5) {
|
|
|
|
// The caller successfully overrode the max tessellation segments to 5. Indicate this in the
|
|
|
|
// background color.
|
2021-05-11 18:36:51 +00:00
|
|
|
canvas->clear(SkColorSetARGB(255, 64, 0, 0));
|
|
|
|
} else {
|
|
|
|
canvas->clear(SK_ColorBLACK);
|
|
|
|
}
|
|
|
|
|
2020-09-17 18:16:54 +00:00
|
|
|
SkAutoCanvasRestore arc(canvas, true);
|
|
|
|
canvas->translate(60, 60);
|
|
|
|
|
2021-05-11 18:36:51 +00:00
|
|
|
draw_strokes(canvas, &rand,
|
2020-09-17 18:16:54 +00:00
|
|
|
SkPath().lineTo(10,0).lineTo(10,10),
|
|
|
|
SkPath().cubicTo(10,0, 10,0, 10,10));
|
|
|
|
canvas->translate(0, 120);
|
|
|
|
|
2021-05-11 18:36:51 +00:00
|
|
|
draw_strokes(canvas, &rand,
|
2020-09-17 18:16:54 +00:00
|
|
|
SkPath().lineTo(0,-10).lineTo(0,10),
|
|
|
|
SkPath().cubicTo(0,-10, 0,-10, 0,10));
|
|
|
|
canvas->translate(0, 120);
|
|
|
|
|
2021-05-11 18:36:51 +00:00
|
|
|
draw_strokes(canvas, &rand,
|
2020-09-17 18:16:54 +00:00
|
|
|
SkPath().lineTo(0,-10).lineTo(10,-10).lineTo(10,10).lineTo(0,10),
|
|
|
|
SkPath().cubicTo(0,-10, 10,10, 0,10));
|
|
|
|
canvas->translate(0, 140);
|
|
|
|
|
2021-05-11 18:36:51 +00:00
|
|
|
draw_strokes(canvas, &rand,
|
2020-09-17 18:16:54 +00:00
|
|
|
SkPath().lineTo(0,-10).lineTo(10,-10).lineTo(10,0).lineTo(0,0),
|
|
|
|
SkPath().cubicTo(0,-10, 10,0, 0,0));
|
|
|
|
canvas->translate(0, 120);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_SIMPLE_GM(widebuttcaps, canvas, kTestWidth, kTestHeight) {
|
2021-05-11 18:36:51 +00:00
|
|
|
canvas->clear(SK_ColorBLACK);
|
|
|
|
draw_test(canvas);
|
2020-09-17 18:16:54 +00:00
|
|
|
}
|