| 1 |
From 17b4bab488449ed4aaca0a406bc950dcc88fa357 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Thomas Smith <[email protected]> |
| 3 |
Date: Tue, 19 May 2026 15:33:06 -0400 |
| 4 |
Subject: [PATCH] [graphite] correctly advance index in drawEdgeAAImageSet |
| 5 |
|
| 6 |
Bug: https://issues.chromium.org/issues/513836996 |
| 7 |
Change-Id: Iff633e0d99443cfc431352cea05051ff567b8f64 |
| 8 |
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1238179 |
| 9 |
Reviewed-by: Kaylee Lubick <[email protected]> |
| 10 |
Reviewed-by: Michael Ludwig <[email protected]> |
| 11 |
--- |
| 12 |
gn/tests.gni | 1 + |
| 13 |
src/gpu/graphite/Device.cpp | 49 +++++++++-------- |
| 14 |
tests/graphite/crbug_513836996.cpp | 84 ++++++++++++++++++++++++++++++ |
| 15 |
3 files changed, 109 insertions(+), 25 deletions(-) |
| 16 |
create mode 100644 tests/graphite/crbug_513836996.cpp |
| 17 |
|
| 18 |
diff --git a/gn/tests.gni b/gn/tests.gni |
| 19 |
index f4a4605d78..3430e2d5b3 100644 |
| 20 |
--- a/gn/tests.gni |
| 21 |
+++ b/gn/tests.gni |
| 22 |
@@ -336,6 +336,7 @@ graphite_tests_sources = [ |
| 23 |
"$_tests/graphite/UpdateBackendTextureTest.cpp", |
| 24 |
"$_tests/graphite/UploadBufferManagerTest.cpp", |
| 25 |
"$_tests/graphite/VerticesPaddingTest.cpp", |
| 26 |
+ "$_tests/graphite/crbug_513836996.cpp", |
| 27 |
] |
| 28 |
|
| 29 |
precompile_tests_sources = [ |
| 30 |
diff --git a/src/gpu/graphite/Device.cpp b/src/gpu/graphite/Device.cpp |
| 31 |
index 218c76349e..c75b096f3e 100644 |
| 32 |
--- a/src/gpu/graphite/Device.cpp |
| 33 |
+++ b/src/gpu/graphite/Device.cpp |
| 34 |
@@ -1309,32 +1309,31 @@ void Device::drawEdgeAAImageSet(const SkCanvas::ImageSetEntry set[], int count, |
| 35 |
dstToDraw.setEmpty(); |
| 36 |
} |
| 37 |
} |
| 38 |
- if (dstToDraw.isEmpty()) { |
| 39 |
- continue; // Nothing to draw for this set entry |
| 40 |
+ if (!dstToDraw.isEmpty()) { |
| 41 |
+ PaintParams::SimpleImage imageShader{ |
| 42 |
+ set[i].fImage.get(), |
| 43 |
+ &localMatrix, |
| 44 |
+ constraint == SkCanvas::kStrict_SrcRectConstraint ? subset : imageBounds, |
| 45 |
+ sampling}; |
| 46 |
+ |
| 47 |
+ // NOTE: See drawEdgeAAQuad for details, we do not snap non-AA quads. |
| 48 |
+ SkEnumBitMask<EdgeAAQuad::Flags> flags = |
| 49 |
+ static_cast<EdgeAAQuad::Flags>(set[i].fAAFlags); |
| 50 |
+ EdgeAAQuad quad = set[i].fHasClip ? EdgeAAQuad(dstClips + dstClipIndex, flags) |
| 51 |
+ : EdgeAAQuad(dstToDraw, flags); |
| 52 |
+ |
| 53 |
+ // TODO: Calling drawGeometry() for each entry re-evaluates the clip stack every time, |
| 54 |
+ // which is consistent with Ganesh's behavior. It also matches the behavior if edge-AA |
| 55 |
+ // images were submitted one at a time by SkiaRenderer (a nice client simplification). |
| 56 |
+ // However, we should explore the performance trade off with doing one bulk evaluation |
| 57 |
+ // for the whole set |
| 58 |
+ const SkMatrix* xtraXform = |
| 59 |
+ set[i].fMatrixIndex < 0 ? nullptr : &preViewMatrices[set[i].fMatrixIndex]; |
| 60 |
+ this->drawGeometry(xtraXform ? localToDevice.concat(SkM44(*xtraXform)) : localToDevice, |
| 61 |
+ Geometry(quad), |
| 62 |
+ PaintParams(paint, imageShader, set[i].fAlpha), |
| 63 |
+ DefaultFillStyle()); |
| 64 |
} |
| 65 |
- |
| 66 |
- PaintParams::SimpleImage imageShader{set[i].fImage.get(), |
| 67 |
- &localMatrix, |
| 68 |
- constraint == SkCanvas::kStrict_SrcRectConstraint ? |
| 69 |
- subset : imageBounds, |
| 70 |
- sampling}; |
| 71 |
- |
| 72 |
- // NOTE: See drawEdgeAAQuad for details, we do not snap non-AA quads. |
| 73 |
- SkEnumBitMask<EdgeAAQuad::Flags> flags = static_cast<EdgeAAQuad::Flags>(set[i].fAAFlags); |
| 74 |
- EdgeAAQuad quad = set[i].fHasClip ? EdgeAAQuad(dstClips + dstClipIndex, flags) |
| 75 |
- : EdgeAAQuad(dstToDraw, flags); |
| 76 |
- |
| 77 |
- // TODO: Calling drawGeometry() for each entry re-evaluates the clip stack every time, which |
| 78 |
- // is consistent with Ganesh's behavior. It also matches the behavior if edge-AA images were |
| 79 |
- // submitted one at a time by SkiaRenderer (a nice client simplification). However, we |
| 80 |
- // should explore the performance trade off with doing one bulk evaluation for the whole set |
| 81 |
- const SkMatrix* xtraXform = set[i].fMatrixIndex < 0 ? nullptr |
| 82 |
- : &preViewMatrices[set[i].fMatrixIndex]; |
| 83 |
- this->drawGeometry(xtraXform ? localToDevice.concat(SkM44(*xtraXform)) : localToDevice, |
| 84 |
- Geometry(quad), |
| 85 |
- PaintParams(paint, imageShader, set[i].fAlpha), |
| 86 |
- DefaultFillStyle()); |
| 87 |
- |
| 88 |
dstClipIndex += 4 * set[i].fHasClip; |
| 89 |
} |
| 90 |
} |
| 91 |
diff --git a/tests/graphite/crbug_513836996.cpp b/tests/graphite/crbug_513836996.cpp |
| 92 |
new file mode 100644 |
| 93 |
index 0000000000..436468fd23 |
| 94 |
--- /dev/null |
| 95 |
+++ b/tests/graphite/crbug_513836996.cpp |
| 96 |
@@ -0,0 +1,84 @@ |
| 97 |
+/* |
| 98 |
+ * Copyright 2026 Google LLC |
| 99 |
+ * |
| 100 |
+ * Use of this source code is governed by a BSD-style license that can be |
| 101 |
+ * found in the LICENSE file. |
| 102 |
+ */ |
| 103 |
+ |
| 104 |
+#include "include/core/SkBitmap.h" |
| 105 |
+#include "include/core/SkCanvas.h" |
| 106 |
+#include "include/core/SkColor.h" |
| 107 |
+#include "include/core/SkImageInfo.h" |
| 108 |
+#include "include/core/SkPoint.h" |
| 109 |
+#include "include/core/SkRect.h" |
| 110 |
+#include "include/core/SkRefCnt.h" |
| 111 |
+#include "include/core/SkSamplingOptions.h" |
| 112 |
+#include "include/core/SkSurface.h" |
| 113 |
+#include "include/gpu/graphite/Context.h" |
| 114 |
+#include "include/gpu/graphite/Image.h" |
| 115 |
+#include "include/gpu/graphite/Recorder.h" |
| 116 |
+#include "include/gpu/graphite/Recording.h" |
| 117 |
+#include "include/gpu/graphite/Surface.h" |
| 118 |
+#include "tests/Test.h" |
| 119 |
+ |
| 120 |
+using namespace skgpu::graphite; |
| 121 |
+ |
| 122 |
+DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(crbug_513836996, reporter, context, CtsEnforcement::kNever) { |
| 123 |
+ constexpr int kW = 200; |
| 124 |
+ constexpr int kH = 100; |
| 125 |
+ const SkImageInfo ii = SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 126 |
+ |
| 127 |
+ std::unique_ptr<Recorder> recorder = context->makeRecorder(); |
| 128 |
+ sk_sp<SkSurface> surface = SkSurfaces::RenderTarget(recorder.get(), ii); |
| 129 |
+ SkCanvas* canvas = surface->getCanvas(); |
| 130 |
+ canvas->clear(SK_ColorBLACK); |
| 131 |
+ |
| 132 |
+ auto src_ii = SkImageInfo::Make(32, 32, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 133 |
+ SkBitmap src_bm; |
| 134 |
+ src_bm.allocPixels(src_ii); |
| 135 |
+ src_bm.eraseColor(SK_ColorGREEN); |
| 136 |
+ |
| 137 |
+ sk_sp<SkImage> rasterImage = SkImages::RasterFromBitmap(src_bm); |
| 138 |
+ sk_sp<SkImage> green = SkImages::TextureFromImage(recorder.get(), rasterImage); |
| 139 |
+ |
| 140 |
+ const SkPoint dstClips[8] = { |
| 141 |
+ {10, 10}, {60, 10}, {60, 60}, {10, 60}, // LEFT |
| 142 |
+ {110, 10}, {190, 10}, {190, 90}, {110, 90}, // RIGHT |
| 143 |
+ }; |
| 144 |
+ |
| 145 |
+ SkCanvas::ImageSetEntry entries[2]; |
| 146 |
+ entries[0].fImage = green; |
| 147 |
+ entries[0].fSrcRect = SkRect::MakeLTRB(-100, -100, -50, -50); |
| 148 |
+ entries[0].fDstRect = SkRect::MakeWH(kW, kH); |
| 149 |
+ entries[0].fMatrixIndex = -1; |
| 150 |
+ entries[0].fAlpha = 1.f; |
| 151 |
+ entries[0].fAAFlags = SkCanvas::kNone_QuadAAFlags; |
| 152 |
+ entries[0].fHasClip = true; |
| 153 |
+ |
| 154 |
+ entries[1].fImage = green; |
| 155 |
+ entries[1].fSrcRect = SkRect::MakeWH(32, 32); |
| 156 |
+ entries[1].fDstRect = SkRect::MakeWH(kW, kH); |
| 157 |
+ entries[1].fMatrixIndex = -1; |
| 158 |
+ entries[1].fAlpha = 1.f; |
| 159 |
+ entries[1].fAAFlags = SkCanvas::kNone_QuadAAFlags; |
| 160 |
+ entries[1].fHasClip = true; |
| 161 |
+ |
| 162 |
+ canvas->experimental_DrawEdgeAAImageSet( |
| 163 |
+ entries, 2, dstClips, nullptr, SkSamplingOptions(), |
| 164 |
+ nullptr, SkCanvas::kFast_SrcRectConstraint); |
| 165 |
+ |
| 166 |
+ std::unique_ptr<Recording> recording = recorder->snap(); |
| 167 |
+ context->insertRecording({recording.get()}); |
| 168 |
+ |
| 169 |
+ SkBitmap bm; |
| 170 |
+ bm.allocPixels(ii); |
| 171 |
+ REPORTER_ASSERT(reporter, surface->readPixels(bm, 0, 0), "Failed to read pixels"); |
| 172 |
+ |
| 173 |
+ SkColor left_px = bm.getColor(35, 35); |
| 174 |
+ SkColor right_px = bm.getColor(150, 50); |
| 175 |
+ |
| 176 |
+ REPORTER_ASSERT(reporter, left_px == SK_ColorBLACK, |
| 177 |
+ "Left pixel should be BLACK, got 0x%08x", left_px); |
| 178 |
+ REPORTER_ASSERT(reporter, right_px == SK_ColorGREEN, |
| 179 |
+ "Right pixel should be GREEN, got 0x%08x", right_px); |
| 180 |
+} |
| 181 |
-- |
| 182 |
2.53.0 |
| 183 |
|