Drawing lines with hairline enabled does not respect alpha

75 views
Skip to first unread message

Jona

unread,
Nov 5, 2021, 11:53:37 AM11/5/21
to skia-discuss
I found a very interesting bug when drawing lines with an SkPaint with hairline stroke size of 0 and changing the paint alpha and trying to draw again. This issue does not happen if I try drawing a circle with the same paint or setting the stroke size to something greater than 0.

My setup:
1. Android app with Skia implementation using GPU.
2. The drawing request happens right before the surface changes. This process recreates the SkSurface and causes to redraw the contents into the new surface.
3. After that zooming into the content causes eventually the content to draw with the set alpha but zooming out causes the alpha to return back to the prior wrong state.

I'm not sure what's happening? I'm on m92.


Jona

unread,
Nov 5, 2021, 12:23:03 PM11/5/21
to skia-discuss
Not sure if it helps but here is a video of the app. You can see enabling the grid and changing the alpha is not changing the grid opacity. It does when zooming in.
https://drive.google.com/file/d/1VUx5p86hYPaXLndcASdx2DR8zaK3MYd3/view?usp=sharing

Greg Daniel

unread,
Nov 5, 2021, 12:34:57 PM11/5/21
to skia-discuss
Can you reproduce the bug in fiddle.skia.org? Or at least write out your code there.

--
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 on the web visit https://groups.google.com/d/msgid/skia-discuss/a0ec3b70-4940-4148-841d-3c3ff94ced56n%40googlegroups.com.

Jona

unread,
Nov 5, 2021, 12:44:56 PM11/5/21
to skia-discuss
I could not reproduce there. The code below is really pretty much how I draw. Nothing complex.
https://fiddle.skia.org/c/ab2bcc93f556cc883cc909fb1213b7c9

 What's missing is recreating the SkSurface before trying to draw again with the different alpha.

This is how I recreate the SkSurface. It works flawlessly for everything just not this particular weird scenario.
void AndroidDeviceManager::jniSurfaceChanged(int width, int height)
{
if (mSurfaceCreated)
{
// Clear the color and stencil buffers here to ensure Skia receives them in the expected state.
glClearColor(0, 0, 0, 0);
glClearStencil(0);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
//mContext->resetContext(kRenderTarget_GrGLBackendState | kMisc_GrGLBackendState);

mEGLDisplay = eglGetCurrentDisplay();
mEGLSurface = eglGetCurrentSurface(EGL_DRAW);

EGLint swapBehavior = 0;
eglQuerySurface(mEGLDisplay, mEGLSurface, EGL_SWAP_BEHAVIOR, &swapBehavior);
LOGW("swapBehavior=0x%X", swapBehavior);

if (eglSurfaceAttrib(mEGLDisplay, mEGLSurface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED) == EGL_FALSE)
{
LOGE("Could not enable buffer preserved swap behavior (0x%X)", eglGetError());
}

GrGLint frameBuffer;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &frameBuffer);
LOGW("frameBuffer=%d", frameBuffer);

// Make sure to set MSAA to 0 to disable GPU based antialiasing and let Skia do it via software.
// This leads to a much nicer quality antialiasing. GPU MSAA is just not that great.
GrGLint samplesCount = 0;
//glGetIntegerv(GL_SAMPLES, &samplesCount);
LOGW("samplesCount=%d", samplesCount);

GrGLint stencilBits = 0;
glGetIntegerv(GL_STENCIL_BITS, &stencilBits);
LOGW("stencilBits=%d", stencilBits);

GrGLFramebufferInfo glInfo;
glInfo.fFBOID = (GrGLuint) frameBuffer;
glInfo.fFormat = 0x8058; //GR_GL_RGBA8: this definition inside in a header in skia's src folder.

GrBackendRenderTarget target(width, height, samplesCount, stencilBits, glInfo);

mSurface = SkSurface::MakeFromBackendRenderTarget(mContext.get(),
target,
kBottomLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,
nullptr,
nullptr);
if (!mSurface) {
LOGW("SkSurface::MakeFromBackendRenderTarget() Failed!");
}

reportSurfaceChanged(width, height);
}
}



Greg Daniel

unread,
Nov 5, 2021, 1:38:20 PM11/5/21
to skia-d...@googlegroups.com
Is the samplesCount value that you are passing into MakeFromBackendRenderTarget the actual sample count of the FBO? You need to pass into Skia the sample count that matches the FBO.

Jona

unread,
Nov 5, 2021, 2:50:16 PM11/5/21
to skia-discuss
Yes, I'm setting the GPU to use msaa=0. Can confirm it returns 0 with this call:

GrGLint frameBuffer;
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &frameBuffer);
LOGW("frameBuffer=%d", frameBuffer);

I just updated to m97 and I'm still seeing the issue.

Jona

unread,
Nov 11, 2021, 10:05:05 AM11/11/21
to skia-discuss
It's really hard to report this bug on this... I'm available to chat with anyone offline and provide any details required. But in my eyes this is super weird bug.

Nooniam Kiangkai

unread,
Nov 11, 2021, 12:04:15 PM11/11/21
to skia-d...@googlegroups.com
อินเตอร์เนตอ่อนมาก ที่แอพริกา

ในวันที่ พฤ. 11 พ.ย. 2021 17:05 น. Jona <medica...@gmail.com> เขียนว่า:
Reply all
Reply to author
Forward
0 new messages