Bug 75308 - [GTK] Add TextureMapperGL implementation
Summary: [GTK] Add TextureMapperGL implementation
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Linux
: P2 Normal
Assignee: Martin Robinson
URL:
Keywords:
Depends on: 75309
Blocks: 74087
  Show dependency treegraph
 
Reported: 2011-12-28 06:01 PST by ChangSeok Oh
Modified: 2012-02-07 03:36 PST (History)
4 users (show)

See Also:


Attachments
Preliminary patch (32.53 KB, patch)
2012-01-29 20:49 PST, Martin Robinson
no flags Details | Formatted Diff | Diff
Patch (44.27 KB, patch)
2012-02-05 18:56 PST, Martin Robinson
no flags Details | Formatted Diff | Diff
Patch with WebKit2 ChangeLog (45.37 KB, patch)
2012-02-05 19:12 PST, Martin Robinson
no flags Details | Formatted Diff | Diff
Properly handle little endian systems with OpenGL ES (45.62 KB, patch)
2012-02-06 01:06 PST, Martin Robinson
alex: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description ChangSeok Oh 2011-12-28 06:01:57 PST
This  bug is for adding initial TextureMapperGL implementation for WebKitGtk+.
Comment 1 Martin Robinson 2011-12-29 07:54:02 PST
Nayan and I are working on this one.
Comment 2 ChangSeok Oh 2012-01-01 07:34:50 PST
Oh. Really? I've been doing something on this, too.
So, I just hope to contribute it, if you and Nayan don't mind. :)
Comment 3 Joone Hur 2012-01-01 20:04:31 PST
(In reply to comment #2)
> Oh. Really? I've been doing something on this, too.
> So, I just hope to contribute it, if you and Nayan don't mind. :)

Hi ChangSeok,

Please take a look at:
http://blog.abandonedwig.info/2011/12/webkitgtk-hackfest-wrapup-accelerated.html

:-)
Comment 4 Martin Robinson 2012-01-29 20:49:08 PST
Created attachment 124489 [details]
Preliminary patch
Comment 5 Martin Robinson 2012-01-29 20:50:32 PST
Alex and No'am, would you mind taking a look at my first stab at this? It seems to work. :)
Comment 6 Noam Rosenthal 2012-01-29 21:05:25 PST
I'm ok with the TextureMapperGL changes!
Comment 7 Martin Robinson 2012-01-29 22:56:05 PST
(In reply to comment #6)
> I'm ok with the TextureMapperGL changes!

One thing I'm not certain about is the contract with TextureMapperGL about when the appropriate GL context should be active. I found that I needed to make it active when constructing the TextureMapper now, as that's when it creates the shaders.
Comment 8 Noam Rosenthal 2012-01-30 06:52:14 PST
(In reply to comment #7)
> (In reply to comment #6)
> > I'm ok with the TextureMapperGL changes!
> 
> One thing I'm not certain about is the contract with TextureMapperGL about when the appropriate GL context should be active. I found that I needed to make it active when constructing the TextureMapper now, as that's when it creates the shaders.

Yes, that should be changed, and is part of a patch ostap is working on. The GL context should be valid when running beginPainting(), but that would be true after it's fixed.
Comment 9 Alejandro G. Castro 2012-01-31 11:45:21 PST
Comment on attachment 124489 [details]
Preliminary patch

Great patch! I tested it and it works well, we can do more extensive testing with
the patch in the repository. I've added some small proposals for your consideration, also
I found compilation does not work if WK2 is activated, I guess we can create a different
patch to fix this compilation issues with texmap now.

I hope this helps.

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

> Source/WebCore/platform/graphics/cairo/TextureMapperGLCairo.cpp:40
> +    RefPtr<cairo_t> cr = adoptRef(cairo_create(m_surface.get()));

Small proposal :), considering we are going to store the cr in the m_context what do you think about using cr directly or storing it initially like:

m_context = adoptPtr(new PlatformContextCairo(cairo_create(m_surface.get())));

Later we could use m_context->cr().

> Source/WebCore/platform/graphics/cairo/TextureMapperGLCairo.cpp:43
> +    cairo_set_operator(cr.get(), CAIRO_OPERATOR_CLEAR);
> +    cairo_paint(cr.get());

Initially the surface create function adds all 0s, is this changing that?

> Source/WebCore/platform/graphics/cairo/TextureMapperGLCairo.cpp:-54
> -    notImplemented();

Would it make sense to call cairo_surface_flush to make sure all the operations are done?

> Source/WebCore/platform/graphics/gtk/WindowGLContextGLX.cpp:33
> +        return nullptr;

Does the style propose to use 0 to represent null pointer?

> Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContext.h:55
> +    // GraphicsLayerClient

We have to add a dot at the end of the comment.

> Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContext.h:56
> +    virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time);

Shoulswe remove the name of the variable 'time'?

> Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContext.h:58
> +    virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& rectToPaint);

Ditto.

> Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContextGL.cpp:121
> +    if (rect == IntRect())

Could we just do rect.isEmpty()?

> Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContextGL.cpp:186
> +#endif // USE(ACCELERATED_COMPOSITING)

Nitpick, we have to add && USE(TEXTURE_MAPPER_GL).

> Source/WebKit/gtk/webkit/webkitwebsettings.cpp:909
> +    * compositing uses the GPU to render animations on pages smoothly and also allows
> +    * propre rendering of 3D CSS transforms.

propre -> proper

> Source/WebKit/gtk/webkit/webkitwebview.cpp:661
> +        copyRectFromCairoSurfaceToContext(priv->backingStore->cairoSurface(), cr, IntSize(), 

Nitpick :), there is a space at the end of the line.

> Source/WebKit/gtk/webkit/webkitwebview.cpp:984
> +    gdk_window_ensure_native(window);

Could we disable AC if the function returns FALSE?

> configure.ac:404
> +if test "$enable_webgl" = "yes" ||  test "$with_accelerated_compositing" != "opengl" ; then

Did you add a ! in the opengl condition?
Comment 10 Martin Robinson 2012-02-05 18:56:05 PST
Created attachment 125550 [details]
Patch
Comment 11 Noam Rosenthal 2012-02-05 19:03:10 PST
Comment on attachment 125550 [details]
Patch

Another LGTM for the TextureMapper/LayerTreeHost changes.
Comment 12 Martin Robinson 2012-02-05 19:06:45 PST
(In reply to comment #9)
> (From update of attachment 124489 [details])
> Great patch! I tested it and it works well, we can do more extensive testing with
> the patch in the repository. I've added some small proposals for your consideration, also
> I found compilation does not work if WK2 is activated, I guess we can create a different
> patch to fix this compilation issues with texmap now.

Thanks for the review. I've fixed the WebKit2 compilation. I also updated the patch to reflect the new TextureMapper design. We'll need a little work in the future to implement TextureMapperImageBuffer and to fall back when necessary.

> > Source/WebCore/platform/graphics/gtk/WindowGLContextGLX.cpp:33
> > +        return nullptr;
> 
> Does the style propose to use 0 to represent null pointer?

nullptr is the new thing from C++0x. I believe that WebKit is switching to it gradually.

> 
> > Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContext.h:55
> > +    // GraphicsLayerClient
> 
> We have to add a dot at the end of the comment.

I think we can avoid it here, since this isn't a complete sentence. There are a few places where you can use one word. For instance, in this case it's just the name of the abstract class I'm implementing.


> > Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContext.h:56
> > +    virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time);
> 
> Shoulswe remove the name of the variable 'time'?

I think it's important to leave it here since double is such a generic type.

> > Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContext.h:58
> > +    virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& rectToPaint);
> 
> Ditto.

I think it's useful here too. :)

> > Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContextGL.cpp:121
> > +    if (rect == IntRect())
> 
> Could we just do rect.isEmpty()?

Yep! Fixed.

> > Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContextGL.cpp:186
> > +#endif // USE(ACCELERATED_COMPOSITING)
> 
> Nitpick, we have to add && USE(TEXTURE_MAPPER_GL).

Fixed.

> > Source/WebKit/gtk/webkit/webkitwebsettings.cpp:909
> > +    * compositing uses the GPU to render animations on pages smoothly and also allows
> > +    * propre rendering of 3D CSS transforms.
> 
> propre -> proper'

Fixed.

> > Source/WebKit/gtk/webkit/webkitwebview.cpp:661
> > +        copyRectFromCairoSurfaceToContext(priv->backingStore->cairoSurface(), cr, IntSize(), 
> 
> Nitpick :), there is a space at the end of the line.

Fixed.

> > Source/WebKit/gtk/webkit/webkitwebview.cpp:984
> > +    gdk_window_ensure_native(window);
> 
> Could we disable AC if the function returns FALSE?

Fixed.

> > configure.ac:404
> > +if test "$enable_webgl" = "yes" ||  test "$with_accelerated_compositing" != "opengl" ; then
> 
> Did you add a ! in the opengl condition?

Yeah. :/ Fixed.
Comment 13 Martin Robinson 2012-02-05 19:12:12 PST
Created attachment 125551 [details]
Patch with WebKit2 ChangeLog
Comment 14 Martin Robinson 2012-02-06 01:06:23 PST
Created attachment 125591 [details]
Properly handle little endian systems with OpenGL ES
Comment 15 Alejandro G. Castro 2012-02-06 05:30:33 PST
Comment on attachment 125591 [details]
Properly handle little endian systems with OpenGL ES

LGTM, works great :). I just had to add this code to make it compile. Noam are this ifdefs in DrawingAreaProxyImpl.cpp correct? I did not check much that code.

diff --git a/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp b/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
index 4c3447b..ba886a0 100644
--- a/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
+++ b/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp
@@ -1139,6 +1139,24 @@ InterpolationQuality GraphicsContext::imageInterpolationQuality() const
     return platformContext()->imageInterpolationQuality();
 }
 
+#if ENABLE(3D_RENDERING) && USE(TEXTURE_MAPPER)
+TransformationMatrix GraphicsContext::get3DTransform() const
+{
+    notImplemented();
+    return TransformationMatrix();
+}
+
+void GraphicsContext::concat3DTransform(const TransformationMatrix& transform)
+{
+    notImplemented();
+}
+
+void GraphicsContext::set3DTransform(const TransformationMatrix& transform)
+{
+    notImplemented();
+}
+#endif
+
 } // namespace WebCore
 
 #endif // USE(CAIRO)
diff --git a/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp b/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp
index 24a5aed..ffc60cf 100644
--- a/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp
+++ b/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp
@@ -36,7 +36,7 @@
 #include "WebProcessProxy.h"
 #include <WebCore/Region.h>
 
-#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
+#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER) && USE(TILED_BACKING_STORE)
 #include "LayerTreeHostProxy.h"
 #endif
 
@@ -58,7 +58,7 @@ DrawingAreaProxyImpl::DrawingAreaProxyImpl(WebPageProxy* webPageProxy)
     , m_isBackingStoreDiscardable(true)
     , m_discardBackingStoreTimer(RunLoop::current(), this, &DrawingAreaProxyImpl::discardBackingStore)
 {
-#if USE(TEXTURE_MAPPER)
+#if USE(TEXTURE_MAPPER) && USE(TILED_BACKING_STORE)
     // Construct the proxy early to allow messages to be sent to the web process while AC is entered there.
     if (webPageProxy->pageGroup()->preferences()->forceCompositingMode())
         m_layerTreeHostProxy = adoptPtr(new LayerTreeHostProxy(this));
@@ -335,7 +335,7 @@ void DrawingAreaProxyImpl::enterAcceleratedCompositingMode(const LayerTreeContex
     m_backingStore = nullptr;
     m_layerTreeContext = layerTreeContext;
     m_webPageProxy->enterAcceleratedCompositingMode(layerTreeContext);
-#if USE(TEXTURE_MAPPER)
+#if USE(TEXTURE_MAPPER) && USE(TILED_BACKING_STORE)
     if (!m_layerTreeHostProxy)
         m_layerTreeHostProxy = adoptPtr(new LayerTreeHostProxy(this));
 #endif
Comment 16 Gustavo Noronha (kov) 2012-02-06 11:51:51 PST
Comment on attachment 125591 [details]
Properly handle little endian systems with OpenGL ES

Re API: simple and effective, looks great to me.
Comment 17 Martin Robinson 2012-02-06 20:35:30 PST
(In reply to comment #15)

> diff --git a/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp b/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp
> index 24a5aed..ffc60cf 100644
> --- a/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp
> +++ b/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp
> @@ -36,7 +36,7 @@
>  #include "WebProcessProxy.h"
>  #include <WebCore/Region.h>
> 
> -#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER)
> +#if USE(ACCELERATED_COMPOSITING) && USE(TEXTURE_MAPPER) && USE(TILED_BACKING_STORE)
>  #include "LayerTreeHostProxy.h"
>  #endif
> 
> @@ -58,7 +58,7 @@ DrawingAreaProxyImpl::DrawingAreaProxyImpl(WebPageProxy* webPageProxy)
>      , m_isBackingStoreDiscardable(true)
>      , m_discardBackingStoreTimer(RunLoop::current(), this, &DrawingAreaProxyImpl::discardBackingStore)
>  {
> -#if USE(TEXTURE_MAPPER)
> +#if USE(TEXTURE_MAPPER) && USE(TILED_BACKING_STORE)
>      // Construct the proxy early to allow messages to be sent to the web process while AC is entered there.
>      if (webPageProxy->pageGroup()->preferences()->forceCompositingMode())
>          m_layerTreeHostProxy = adoptPtr(new LayerTreeHostProxy(this));
> @@ -335,7 +335,7 @@ void DrawingAreaProxyImpl::enterAcceleratedCompositingMode(const LayerTreeContex
>      m_backingStore = nullptr;
>      m_layerTreeContext = layerTreeContext;
>      m_webPageProxy->enterAcceleratedCompositingMode(layerTreeContext);
> -#if USE(TEXTURE_MAPPER)
> +#if USE(TEXTURE_MAPPER) && USE(TILED_BACKING_STORE)
>      if (!m_layerTreeHostProxy)
>          m_layerTreeHostProxy = adoptPtr(new LayerTreeHostProxy(this));
>  #endif

I don't seem to need this bit to build. What options are you passing to build-webkit?
Comment 18 Martin Robinson 2012-02-06 20:41:58 PST
Committed r106901: <http://trac.webkit.org/changeset/106901>
Comment 19 Alejandro G. Castro 2012-02-06 23:47:52 PST
(In reply to comment #17)
> (In reply to comment #15)
> 
> [...]
>
> > +#if USE(TEXTURE_MAPPER) && USE(TILED_BACKING_STORE)
> >      if (!m_layerTreeHostProxy)
> >          m_layerTreeHostProxy = adoptPtr(new LayerTreeHostProxy(this));
> >  #endif
> 
> I don't seem to need this bit to build. What options are you passing to build-webkit?

Hrm, basically no options: build-webkit --gtk --debug --prefix=/blah. I'll update the repository to check if it works for me.
Comment 20 Alejandro G. Castro 2012-02-07 03:36:13 PST
(In reply to comment #19)
> (In reply to comment #17)
> > (In reply to comment #15)
> > 
> > [...]
> >
> > > +#if USE(TEXTURE_MAPPER) && USE(TILED_BACKING_STORE)
> > >      if (!m_layerTreeHostProxy)
> > >          m_layerTreeHostProxy = adoptPtr(new LayerTreeHostProxy(this));
> > >  #endif
> > 
> > I don't seem to need this bit to build. What options are you passing to build-webkit?
> 
> Hrm, basically no options: build-webkit --gtk --debug --prefix=/blah. I'll update the repository to check if it works for me.

I've just tested it and it still fails for me in linking stage:

./.libs/libwebkit2gtk-3.0.so: undefined reference to `WebKit::LayerTreeHostProxy::LayerTreeHostProxy(WebKit::DrawingAreaProxy*)'
collect2: ld returned 1 exit status

The compilation line is:

build-webkit --gtk --debug --prefix=/home/alex/install --with-accelerated-compositing=opengl

I guess it makes sense because we are compiling DrawingAreaProxyImpl.cpp and it uses LayerTreeHostProxy that it is not compiled.