Bug 106508

Summary: [EFL] [WebGL] Add support for bliting texture contents to FBO.
Product: WebKit Reporter: Kalyan <kalyan.kondapally>
Component: WebKit EFLAssignee: Kalyan <kalyan.kondapally>
Status: RESOLVED FIXED    
Severity: Normal CC: dino, lucas.de.marchi, noam, webkit.review.bot, zeno
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: Linux   
Bug Depends on: 109988, 110616    
Bug Blocks: 105659    
Attachments:
Description Flags
WIP
none
WIP
none
WIP
none
WIP
none
patch
none
patchv2
none
patchv3
none
patchv4
noam: review-
patchv5 none

Description Kalyan 2013-01-09 17:12:17 PST
We currently rely on EXT_framebuffer_blit to copy contents from one FBO to another. This extension is not exposed on GLES1.1 or 2.0. ANGLE_framebuffer_blit seems to provide similar interactions. I am not sure how well it is supported.

Does Angle included as part of WebKit include support for the extension ??
 
One possibility is to use this extension when available and provide a fall back mechanism.
Comment 1 Kalyan 2013-01-09 17:14:32 PST
Created attachment 182022 [details]
WIP
Comment 2 Kalyan 2013-01-09 17:22:01 PST
Initial Approach:

what the patch does is basically check for the availability of the blit extension. If the extension is unavailable it falls back to use shaders.
Comment 3 Zeno Albisser 2013-01-14 03:50:31 PST
It seems the WIP patch is mostly based on what GraphicsSurfaceWin does. Do you think it would be possible to adopt this code instead of duplicating it?
If it is just about naming, we could probably rename it to GraphicsSurfaceEGL or similar. ;)
Comment 4 Kalyan 2013-01-14 04:18:19 PST
(In reply to comment #3)
> It seems the WIP patch is mostly based on what GraphicsSurfaceWin does. Do you think it would be possible to adopt this code instead of duplicating it?
> If it is just about naming, we could probably rename it to GraphicsSurfaceEGL or similar. ;)

It does do something similar to what is done in GraphicsSurfaceWin. I would be more than happy to get the common elements (copytexture parts out) and create something common to be used by all surface implementations. 

I can get rid of the Angle part from this patch. 

some differences:
1)This patch tries to make use of OES_vertex_array_object if supported.
2)Take Sampler objects into use(if supported).
3)Save and restore previous VBO state, program etc.
Comment 5 Kalyan 2013-01-14 11:12:37 PST
Created attachment 182603 [details]
WIP
Comment 6 Kalyan 2013-01-29 14:08:06 PST
Created attachment 185304 [details]
WIP
Comment 7 Kalyan 2013-02-08 07:15:46 PST
Created attachment 187316 [details]
WIP

Trying to use TextureMapperGL to achieve the same. Doesn't work yet
Comment 8 Kalyan 2013-02-09 08:03:26 PST
(In reply to comment #7)
> Created an attachment (id=187316) [details]
> WIP
> 
> Trying to use TextureMapperGL to achieve the same. Doesn't work yet

k, having it working now. Issue with TextureMapperGL is that it doesn't keep track of  vertex array object. This was k as on it was mostly used in UI process. With WebGL apps this is needed, we could do this in our side so it doesn't add any overhead for other use cases.
Comment 9 Kalyan 2013-02-09 10:13:54 PST
Created attachment 187435 [details]
patch
Comment 10 Kalyan 2013-02-09 10:22:27 PST
Made changes to use TextureMapperGL to draw texture content to surface.
Comment 11 Kalyan 2013-02-10 04:12:17 PST
Created attachment 187475 [details]
patchv2
Comment 12 Kalyan 2013-02-10 07:09:01 PST
Created attachment 187480 [details]
patchv3

minor cleanup.
Comment 13 WebKit Review Bot 2013-02-10 07:12:07 PST
Attachment 187480 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/ChangeLog', u'Source/WebCore/platform/graphics/efl/GraphicsContext3DPrivate.cpp', u'Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp', u'Source/WebCore/platform/graphics/opengl/GLPlatformSurface.h']" exit_code: 1
Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp:72:  This { should be at the end of the previous line  [whitespace/braces] [4]
Total errors found: 1 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 14 Kalyan 2013-02-10 09:19:46 PST
Created attachment 187483 [details]
patchv4

style fix
Comment 15 Noam Rosenthal 2013-02-10 10:34:49 PST
Comment on attachment 187483 [details]
patchv4

View in context: https://bugs.webkit.org/attachment.cgi?id=187483&action=review

> Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp:167
> +    // Save any current bound vertex array to restore after updating surface with texture content.
> +    // This is needed as TextureMapperGL doesn't track and restore current bound vertex array.
> +    ScopedStateSaver stateSaver;
> +    ::glBindFramebuffer(GL_FRAMEBUFFER, 0);
> +    ::glColorMask(true, true, true, true);
> +    m_textureBlitter->beginPainting();
> +    m_textureBlitter->drawTexture(texture, m_flags, textureSize, m_rect, m_identityMatrix, 1.0, 0);
> +    m_textureBlitter->endPainting();

This looks flaky.
TextureMapperGL may change other attributes in the future and this would break.
Why not use TextureMapperShaderProgram directly? That class has a more deterministic API than TMGL.

> Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp:169
> +    ::glFlush();

You probably don't want to flush with every frame...
Comment 16 Kalyan 2013-02-10 12:26:32 PST
(In reply to comment #15)
> (From update of attachment 187483 [details])
> TextureMapperGL may change other attributes in the future and this would break.
> Why not use TextureMapperShaderProgram directly? That class has a more deterministic API than TMGL.

Good point. Will try to do that.

> > Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp:169
> > +    ::glFlush();
> 
> You probably don't want to flush with every frame...

It is needed for certain backends. (I.e using EGL and EGLImage). I do agree, this might not be the right place for it as on GLX you don't need to do this. I will get rid of it.
Comment 17 Kalyan 2013-02-11 17:00:04 PST
Created attachment 187728 [details]
patchv5

Removes dependency on TextureMapperGL
Comment 18 Zeno Albisser 2013-02-13 03:35:54 PST
Comment on attachment 187728 [details]
patchv5

View in context: https://bugs.webkit.org/attachment.cgi?id=187728&action=review

> Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp:73
> +class GLStateTracker {

I am somewhat skeptical to the concept of tracking gl states. How do you make sure that you track all the necessary states?
Or in other words, how do you know that there is nothing else you have to save and restore?
I know we have different concepts here between EFL and Qt. So just to make it clear, I am not objecting... just raising a concern, that might need to be adressed in future.

> Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp:234
> +    else

I would remove the "else" here.
It seems not logical to have a conditional push() but a non-conditional pop(). But i see that it would not matter in case m_shaderProgram has not been initialized before.
Comment 19 Kalyan 2013-02-13 04:24:15 PST
(In reply to comment #18)
> (From update of attachment 187728 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=187728&action=review
> I know we have different concepts here between EFL and Qt. So just to make it clear, I am not objecting... just raising a concern, that might need to be adressed in future.

We only track things which we manipulate on our side(i.e disable blend, depth, vbo etc) and not everything. I do agree that it might not be needed with a shared context in place. Support for that is not yet there, we can get rid of state tracking once we have it in place.
Comment 20 Kalyan 2013-02-16 03:01:50 PST
Comment on attachment 187728 [details]
patchv5

Removing request for review till 109988 is done.