82 line[0] = p0 - v * 10.f;
83 line[1] = p1 + v * 10.f;
90 static constexpr SkScalar kHorizontalTolerance = 0.01f;
94 double pY = (double) p1.
fY - (
double) p0.
fY;
95 double pX = (double) p1.
fX - (
double) p0.
fX;
96 double lY = (double) l1.
fY - (
double) l0.
fY;
97 double lX = (double) l1.
fX - (
double) l0.
fX;
98 double plY = (double) p0.
fY - (
double) l0.
fY;
99 double plX = (double) p0.
fX - (
double) l0.
fX;
111 double lNumerator = plX * pY - plY * pX;
112 double lDenom = lX * pY - lY * pX;
119 double alphaL = lNumerator / lDenom;
120 if (alphaL < 0.0 || alphaL > 1.0) {
127 double alphaP = (alphaL * lY - plY) / pY;
128 if (alphaP < 0.0 || alphaP > 1.0) {
141 static constexpr SkScalar kLineOutset = 10.f;
143 local.mapPoints(mapped, pts, 2);
152 paint.setAntiAlias(
true);
155 paint.setStrokeWidth(0.f);
169 paint.setAntiAlias(
true);
172 paint.setStrokeWidth(0.f);
215 const bool edgeAA[4],
int tileID,
int quadID) = 0;
244 drawCount += this->
clipTile(canvas, tileID, tile,
nullptr, edgeAA,
lines, 3,
266 const bool edgeAA[4],
const SkPoint lines[],
int lineCount,
int* quadCount) {
267 if (lineCount == 0) {
270 int draws = this->
drawTile(canvas, baseRect, quad, edgeAA, tileID, *quadCount);
271 *quadCount = *quadCount + 1;
275 static constexpr int kTL = 0;
276 static constexpr int kTR = 1;
277 static constexpr int kBR = 2;
278 static constexpr int kBL = 3;
279 static constexpr int kS0 = 4;
280 static constexpr int kS1 = 5;
285 for (
int i = 0;
i < 4; ++
i) {
296 int intersectionCount = 0;
297 for (
int i = 0;
i < 4; ++
i) {
303 bool duplicate =
false;
304 for (
int j = 0; j < intersectionCount; ++j) {
312 splitIndices[intersectionCount] =
i;
318 if (intersectionCount < 2) {
322 canvas, tileID, baseRect, quad, edgeAA,
lines + 2, lineCount - 1, quadCount);
333 if (splitIndices[1] - splitIndices[0] == 2) {
335 if (splitIndices[0] == 0) {
347 switch(splitIndices[0]) {
350 if (splitIndices[1] == 1) {
391 for (
int i = 0;
i < subtiles.
size(); ++
i) {
393 for (
int j = 0; j < 4; ++j) {
394 int p = subtiles[
i][j];
397 int np = j == 3 ? subtiles[
i][0] : subtiles[
i][j + 1];
401 if ((
p >= kS0 && (np == s2 || np >= kS0)) ||
402 ((np >= kS0) && (
p == s2 ||
p >= kS0))) {
408 subAA[j] = edgeAA[j];
413 draws += this->
clipTile(canvas, tileID, baseRect, sub, subAA,
lines + 2, lineCount - 1,
425 : fMakeRendererFn(
std::move(makeRendererFn))
451 fRenderers = fMakeRendererFn();
452 this->configureMatrices();
456 static constexpr SkScalar kGap = 40.f;
457 static constexpr SkScalar kBannerWidth = 120.f;
465 for (
int i = 0;
i < fMatrices.
size(); ++
i) {
470 for (
int j = 0; j < fRenderers.
size(); ++j) {
476 drawCounts[j] += fRenderers[j]->drawTiles(canvas);
492 for (
int j = 0; j < fRenderers.
size(); ++j) {
493 fRenderers[j]->drawBanner(canvas);
509 void configureMatrices() {
511 fMatrixNames.
clear();
515 fMatrices[0].setIdentity();
519 fMatrices[1].setTranslate(5.5f, 20.25f);
520 fMatrices[1].postScale(.9f, .7f);
524 fMatrices[2].setRotate(20.0f);
525 fMatrices[2].preTranslate(15.f, -20.f);
529 fMatrices[3].setSkew(.5f, .25f);
530 fMatrices[3].preTranslate(-30.f, 0.f);
541 fMatrices[4].preTranslate(0.f, 10.f);
571 int tileID,
int quadID)
override {
577 float alpha = quadID / 10.f;
578 c.fR = c.fR * (1 - alpha) + alpha;
579 c.fG = c.fG * (1 - alpha) + alpha;
580 c.fB = c.fB * (1 - alpha) + alpha;
581 c.fA = c.fA * (1 - alpha) + alpha;
594 constexpr char kFormat[] =
"Ext(%s) - Int(%s)";
595 if (fEnableAAOverride) {
599 config.
appendf(kFormat,
"yes",
"yes");
601 config.
appendf(kFormat,
"no",
"no");
604 config.
appendf(kFormat,
"yes",
"no");
611 bool fEnableAAOverride;
615 , fEnableAAOverride(enableAAOverrde) {}
629 int tileID,
int quadID)
override {
652 return Make(
"Texture",
"", std::move(
image),
nullptr,
nullptr,
nullptr,
nullptr,
657 const char* subtitle = transformCount == 0 ?
"" :
"w/ xforms";
658 return Make(
"Texture Set", subtitle, std::move(
image),
nullptr,
nullptr,
nullptr,
nullptr,
659 1.f,
false, transformCount);
664 return Make(
"Shader",
name, std::move(
image), std::move(shader),
665 nullptr,
nullptr,
nullptr, 1.f,
local, 0);
670 return Make(
"Color Filter",
name, std::move(
image),
nullptr, std::move(filter),
nullptr,
671 nullptr, 1.f,
false, 0);
676 return Make(
"Image Filter",
name, std::move(
image),
nullptr,
nullptr, std::move(filter),
677 nullptr, 1.f,
false, 0);
682 return Make(
"Mask Filter",
name, std::move(
image),
nullptr,
nullptr,
nullptr,
683 std::move(filter), 1.f,
false, 0);
688 nullptr,
nullptr,
nullptr, alpha,
false, 0);
696 bool resetAfterEachQuad,
int transformCount) {
698 std::move(
image), std::move(shader), std::move(colorFilter), std::move(imageFilter),
699 std::move(maskFilter), paintAlpha, resetAfterEachQuad, transformCount));
705 draws += this->drawAndReset(canvas);
710 int tileID,
int quadID)
override {
712 bool hasClip =
false;
720 if (!fResetEachQuad && fTransformBatchCount > 0) {
723 if (fPreViewMatrices.
size() == 0) {
730 if (!fBaseCTM.
invert(&invBase)) {
731 SkDebugf(
"Cannot invert CTM, transform batching will not be correct.\n");
734 if (preView != fPreViewMatrices[fPreViewMatrices.
size() - 1]) {
738 matrixIdx = fPreViewMatrices.
size() - 1;
754 {fImage, localRect,
rect, matrixIdx, 1.f, this->
maskToFlags(edgeAA), hasClip});
756 if (fResetEachQuad) {
758 return this->drawAndReset(canvas);
765 if (fTopBanner.
size() > 0) {
769 if (fBottomBanner.
size() > 0) {
787 int fTransformBatchCount;
797 const char* bottomBanner,
805 int transformBatchCount)
806 : fTopBanner(topBanner)
807 , fBottomBanner(bottomBanner)
809 , fShader(
std::move(shader))
810 , fColorFilter(
std::move(colorFilter))
811 , fImageFilter(
std::move(imageFilter))
812 , fMaskFilter(
std::move(maskFilter))
813 , fPaintAlpha(paintAlpha)
814 , fResetEachQuad(resetEachQuad)
815 , fTransformBatchCount(transformBatchCount)
817 SkASSERT(transformBatchCount >= 0 && (!resetEachQuad || transformBatchCount == 0));
821 paint->setAntiAlias(
true);
825 paint->setColor4f({1.f, 0.4f, 0.25f, fPaintAlpha},
nullptr);
829 if (fResetEachQuad) {
835 paint->setShader(fShader);
839 paint->setColorFilter(fColorFilter);
840 paint->setImageFilter(fImageFilter);
841 paint->setMaskFilter(fMaskFilter);
844 int drawAndReset(
SkCanvas* canvas) {
846 if (fSetEntries.
size() == 0) {
851 if (!fResetEachQuad && fTransformBatchCount > 0) {
854 if (fBatchCount < fTransformBatchCount) {
865 int expectedDstClipCount = 0;
866 for (
int i = 0;
i < fSetEntries.
size(); ++
i) {
867 expectedDstClipCount += 4 * fSetEntries[
i].fHasClip;
868 SkASSERT(fSetEntries[
i].fMatrixIndex < 0 ||
869 fSetEntries[
i].fMatrixIndex < fPreViewMatrices.
size());
875 SkRect lastTileRect = fSetEntries[fSetEntries.
size() - 1].fDstRect;
876 this->configureTilePaint(lastTileRect, &
paint);
885 fPreViewMatrices.
clear();
913 draws += this->drawAndReset(canvas);
918 int tileID,
int quadID)
override {
921 bool hasClip =
false;
939 {fImage, localRect,
rect, -1, .5f, this->
maskToFlags(edgeAA), hasClip});
946 draw_text(canvas,
"YUV + alpha - GPU Only");
950 std::unique_ptr<sk_gpu_test::LazyYUVImage> fYUVData;
961 int drawAndReset(
SkCanvas* canvas) {
963 if (fSetEntries.
size() == 0) {
969 int expectedDstClipCount = 0;
970 for (
int i = 0;
i < fSetEntries.
size(); ++
i) {
971 expectedDstClipCount += 4 * fSetEntries[
i].fHasClip;
977 paint.setAntiAlias(
true);
981 fSetEntries.
begin(), fSetEntries.
size(), fDstClips.
begin(),
nullptr,
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static constexpr uint64_t kOffset
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
static bool intersect(const SkPoint &p0, const SkPoint &n0, const SkPoint &p1, const SkPoint &n1, SkScalar *t)
static const uint16_t kTL
static const uint16_t kBL
static const uint16_t kBR
static const uint16_t kTR
static const int points[]
sk_sp< SkData > GetResourceAsData(const char *resource)
@ kOpaque_SkAlphaType
pixel is opaque
@ kSrcOver
r = s + (1-sa)*d
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
constexpr SkColor SK_ColorTRANSPARENT
constexpr SkColor SK_ColorBLUE
constexpr SkColor SK_ColorRED
constexpr SkColor SK_ColorBLACK
constexpr SkColor SK_ColorGREEN
constexpr SkColor SK_ColorWHITE
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
#define SkScalarRoundToInt(x)
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
static const SkScalar kCellWidth
virtual int drawTile(SkCanvas *canvas, const SkRect &rect, const SkPoint clip[4], const bool edgeAA[4], int tileID, int quadID)=0
SkCanvas::QuadAAFlags maskToFlags(const bool edgeAA[4]) const
virtual int drawTiles(SkCanvas *canvas)
int clipTile(SkCanvas *canvas, int tileID, const SkRect &baseRect, const SkPoint quad[4], const bool edgeAA[4], const SkPoint lines[], int lineCount, int *quadCount)
virtual void drawBanner(SkCanvas *canvas)=0
void onOnceBeforeDraw() override
CompositorGM(const char *name, std::function< ClipTileRendererArray()> makeRendererFn)
SkISize getISize() override
SkString getName() const override
void onDraw(SkCanvas *canvas) override
int drawTile(SkCanvas *canvas, const SkRect &rect, const SkPoint clip[4], const bool edgeAA[4], int tileID, int quadID) override
static sk_sp< ClipTileRenderer > MakeNonAA()
static sk_sp< ClipTileRenderer > Make()
static sk_sp< ClipTileRenderer > MakeAA()
void drawBanner(SkCanvas *canvas) override
void allocPixels(const SkImageInfo &info, size_t rowBytes)
sk_sp< SkImage > asImage() const
void eraseColor(SkColor4f) const
void translate(SkScalar dx, SkScalar dy)
virtual GrRecordingContext * recordingContext() const
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
@ kFast_SrcRectConstraint
sample outside bounds; faster
void experimental_DrawEdgeAAQuad(const SkRect &rect, const SkPoint clip[4], QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode)
void experimental_DrawEdgeAAImageSet(const ImageSetEntry imageSet[], int cnt, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkSamplingOptions &, const SkPaint *paint=nullptr, SrcRectConstraint constraint=kStrict_SrcRectConstraint)
SkMatrix getTotalMatrix() const
void setMatrix(const SkM44 &matrix)
void concat(const SkMatrix &matrix)
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
void setSaturation(float sat)
static sk_sp< SkShader > MakeRadial(const SkPoint ¢er, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
static sk_sp< SkImageFilter > Dilate(SkScalar radiusX, SkScalar radiusY, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static bool IntersectLine(const SkPoint src[2], const SkRect &clip, SkPoint dst[2])
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
static SkMatrix Concat(const SkMatrix &a, const SkMatrix &b)
bool invert(SkMatrix *inverse) const
static const SkMatrix & I()
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
@ kStroke_Style
set to stroke geometry
static sk_sp< SkMaskFilter > Make(sk_sp< SkShader > shader)
sk_sp< SkShader > makeWithLocalMatrix(const SkMatrix &) const
const char * c_str() const
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
static sk_sp< ClipTileRenderer > Make(const SkColor4f &color)
int drawTile(SkCanvas *canvas, const SkRect &rect, const SkPoint clip[4], const bool edgeAA[4], int tileID, int quadID) override
void drawBanner(SkCanvas *canvas) override
static sk_sp< ClipTileRenderer > MakeColorFilter(const char *name, sk_sp< SkImage > image, sk_sp< SkColorFilter > filter)
static sk_sp< ClipTileRenderer > Make(const char *topBanner, const char *bottomBanner, sk_sp< SkImage > image, sk_sp< SkShader > shader, sk_sp< SkColorFilter > colorFilter, sk_sp< SkImageFilter > imageFilter, sk_sp< SkMaskFilter > maskFilter, SkScalar paintAlpha, bool resetAfterEachQuad, int transformCount)
int drawTiles(SkCanvas *canvas) override
static sk_sp< ClipTileRenderer > MakeShader(const char *name, sk_sp< SkImage > image, sk_sp< SkShader > shader, bool local)
static sk_sp< ClipTileRenderer > MakeUnbatched(sk_sp< SkImage > image)
static sk_sp< ClipTileRenderer > MakeImageFilter(const char *name, sk_sp< SkImage > image, sk_sp< SkImageFilter > filter)
int drawTile(SkCanvas *canvas, const SkRect &rect, const SkPoint clip[4], const bool edgeAA[4], int tileID, int quadID) override
static sk_sp< ClipTileRenderer > MakeAlpha(sk_sp< SkImage > image, SkScalar alpha)
static sk_sp< ClipTileRenderer > MakeBatched(sk_sp< SkImage > image, int transformCount)
void drawBanner(SkCanvas *canvas) override
static sk_sp< ClipTileRenderer > MakeMaskFilter(const char *name, sk_sp< SkImage > image, sk_sp< SkMaskFilter > filter)
int drawTile(SkCanvas *canvas, const SkRect &rect, const SkPoint clip[4], const bool edgeAA[4], int tileID, int quadID) override
static sk_sp< ClipTileRenderer > MakeFromJPEG(sk_sp< SkData > imageData)
void drawBanner(SkCanvas *canvas) override
int drawTiles(SkCanvas *canvas) override
static constexpr int kMatrixCount
static void clipping_line_segment(const SkPoint &p0, const SkPoint &p1, SkPoint line[2])
static ClipTileRendererArray make_debug_renderers()
static bool intersect_line_segments(const SkPoint &p0, const SkPoint &p1, const SkPoint &l0, const SkPoint &l1, SkPoint *intersect)
static ClipTileRendererArray make_image_renderers()
static ClipTileRendererArray make_filtered_renderers()
static ClipTileRendererArray make_shader_renderers()
static ClipTileRendererArray make_solid_color_renderers()
static constexpr SkPoint kClipP2
static constexpr SkScalar kTileHeight
static constexpr SkScalar kTileWidth
static void draw_clipping_boundaries(SkCanvas *canvas, const SkMatrix &local)
static constexpr int kRowCount
static void draw_outset_line(SkCanvas *canvas, const SkMatrix &local, const SkPoint pts[2], const SkPaint &paint)
static constexpr SkPoint kClipP3
TArray< sk_sp< ClipTileRenderer > > ClipTileRendererArray
static constexpr int kColCount
static void draw_text(SkCanvas *canvas, const char *text)
static constexpr SkPoint kClipP1
static void draw_tile_boundaries(SkCanvas *canvas, const SkMatrix &local)
FlutterSemanticsFlag flags
Dart_NativeFunction function
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
sk_sp< const SkImage > image
sk_sp< SkBlender > blender SkRect rect
DEF_SWITCHES_START aot vmservice shared library name
font
Font Metadata and Metrics.
static constexpr SkPoint kPts[kPtsCount]
static constexpr SkISize Make(int32_t w, int32_t h)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
bool setLength(float length)
void toQuad(SkPoint quad[4]) const
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
static constexpr SkRect MakeWH(float w, float h)