Antialiasing bug

82 views
Skip to first unread message

Mungai Brian

unread,
Aug 6, 2025, 9:29:06 AMAug 6
to skia-discuss

Args
skia_enable_tools = false
target_cpu="arm64"
is_trivial_abi = false
skia_enable_ganesh = false
skia_enable_graphite = true
skia_use_dawn = true
is_official_build = true
is_component_build = false  
skia_use_freetype = true
skia_use_system_freetype2 = false
skia_use_harfbuzz = false
skia_use_icu = false
skia_use_ffmpeg = false
skia_use_libjpeg_turbo_decode = false
skia_use_libjpeg_turbo_encode = false
skia_use_libwebp_decode = false
skia_use_libwebp_encode = false
skia_use_xps = false
skia_enable_pdf = false
skia_enable_skottie = false
skia_use_expat = false
skia_enable_svg = false
skia_use_perfetto = false
skia_use_system_libpng = false
skia_use_system_zlib = false
skia_use_cpp20 = true


Michael Ludwig

unread,
Aug 6, 2025, 9:30:15 AMAug 6
to skia-discuss
Can you provide more details about what kind of surface you're rendering into and how you are implementing the inversion effect?

Mungai Brian

unread,
Aug 6, 2025, 10:12:33 AMAug 6
to skia-d...@googlegroups.com
# Context & Recorder

skgpu::graphite::DawnBackendContext backend_context = {
.fInstance = wgpu::Instance(instance),
.fDevice = wgpu::Device(device),
.fQueue = wgpu::Queue(queue),
};

skgpu::graphite::ContextOptions options;

auto context = skgpu::graphite::ContextFactory::MakeDawn(backend_context, options);
auto recorder = internal.context->makeRecorder();


# Surface

skgpu::graphite::DawnTextureInfo info(1,
skgpu::Mipmapped::kNo,
wgpu::TextureFormat(format),
wgpu::TextureUsage(usage),
wgpu::TextureAspect::All);
auto backend_texture = skgpu::graphite::BackendTextures::MakeDawn(texture);

return SkSurfaces::WrapBackendTexture(internal.recorder.get(),
backend_texture,
kBGRA_8888_SkColorType,
SkColorSpace::MakeSRGB(),
nullptr);


# Inversion effect done by simply changing SkPaint's color as below
canvas->clear(bg_color.ToSkColor4f());

canvas->setMatrix(SkMatrix::Translate(200, 200));
run.Paint(canvas);

canvas->setMatrix(SkMatrix::Translate(200, 300));
SkPaint paint(text_color.ToSkColor4f());
canvas->drawRoundRect(SkRect::MakeXYWH(0, 0, 200, 100), 24, 24, paint);

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/skia-discuss/764ae212-f5b9-4ecd-8c29-03e04dcb6adbn%40googlegroups.com.

Mungai Brian

unread,
Aug 6, 2025, 10:12:38 AMAug 6
to skia-discuss
Here is how i create the context and the recorder:


skgpu::graphite::DawnBackendContext backend_context = {
.fInstance = wgpu::Instance(instance),
.fDevice = wgpu::Device(device),
.fQueue = wgpu::Queue(queue),
};

skgpu::graphite::ContextOptions options;
auto context = skgpu::graphite::ContextFactory::MakeDawn(backend_context, options);
auto recorder = internal.context->makeRecorder();

Here is how i create the surface:
skgpu::graphite::DawnTextureInfo info(1,
skgpu::Mipmapped::kNo,
wgpu::TextureFormat(format),
wgpu::TextureUsage(usage),
wgpu::TextureAspect::All);
auto backend_texture = skgpu::graphite::BackendTextures::MakeDawn(texture);

return SkSurfaces::WrapBackendTexture(internal.recorder.get(),
backend_texture,
kBGRA_8888_SkColorType,
SkColorSpace::MakeSRGB(),
nullptr);

I perform the inversion effect by simply changing the paint (bg_color & text_color below). Nothing else:
canvas->clear(bg_color.ToSkColor4f());

canvas->setMatrix(SkMatrix::Translate(200, 200));
run.Paint(canvas);

canvas->setMatrix(SkMatrix::Translate(200, 300));
SkPaint paint(text_color.ToSkColor4f());
canvas->drawRoundRect(SkRect::MakeXYWH(0, 0, 200, 100), 24, 24, paint);

Michael Ludwig

unread,
Aug 6, 2025, 10:51:43 AMAug 6
to skia-discuss
Unfortunately I am unable to reproduce in our internal tools by drawing text or round rects with black vs. white foreground and background colors.  Are some of these cases fully transparent instead of opaque black?  It could also be an issue with how you are presenting or interpreting the final image in your application window if it is transparent and not opaque.

Mungai Brian

unread,
Aug 6, 2025, 12:26:21 PMAug 6
to skia-discuss
Found the issue

struct SkRGBA4f {
    float fR;  //!< red component (was passing 0-255 instead of 0-1)
    float fG;  //!< green component (was passing 0-255 instead of 0-1)
    float fB;  //!< blue component (was passing 0-255 instead of 0-1)
    float fA;  //!< alpha component (was passing 0-255 instead of 0-1)
}

This will silently result in some very strange values in the fragment shader

Fragment shader returning [96733,96733,96733,0.184]
Screenshot 2025-08-06 at 18.45.26.png

Michael Ludwig

unread,
Aug 6, 2025, 12:28:50 PMAug 6
to skia-discuss
Ah yes, SkColor4f is assumed to have a normal component range of [0, 1] but does not clamp values because extended gamut colorspaces or HDR can produce perfectly legal color values that are outside of [0, 1].  [0,255] is only for SkColor which is an unsigned normalized bit representation that is not capable of representing any HDR or extended color values.
Reply all
Reply to author
Forward
0 new messages