Bug 1583731 - [Wayland] Implement RenderWaylandDMABUFTextureHostOGL based on WaylandDMABUFSurface, r=sotaro
authorMartin Stransky <stransky@redhat.com>
Thu, 17 Oct 2019 11:28:56 +0000
changeset 498033 10315b0f4304e3e4a41def4ea51c3186685e3d78
parent 498032 927679118b142b0bbb77a6795f55e98936d9a2b4
child 498034 1dfc280e1f0eef9966ff438f51729576247cde29
push id98233
push userbtara@mozilla.com
push dateThu, 17 Oct 2019 16:53:25 +0000
treeherderautoland@1dfc280e1f0e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro
bugs1583731
milestone71.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1583731 - [Wayland] Implement RenderWaylandDMABUFTextureHostOGL based on WaylandDMABUFSurface, r=sotaro Depends on D49263 Differential Revision: https://phabricator.services.mozilla.com/D49264
gfx/layers/opengl/WaylandDMABUFTextureHostOGL.cpp
gfx/webrender_bindings/RenderWaylandDMABUFTextureHostOGL.cpp
gfx/webrender_bindings/RenderWaylandDMABUFTextureHostOGL.h
gfx/webrender_bindings/moz.build
--- a/gfx/layers/opengl/WaylandDMABUFTextureHostOGL.cpp
+++ b/gfx/layers/opengl/WaylandDMABUFTextureHostOGL.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WaylandDMABUFTextureHostOGL.h"
 #include "mozilla/widget/WaylandDMABufSurface.h"
+#include "mozilla/webrender/RenderWaylandDMABUFTextureHostOGL.h"
 #include "mozilla/webrender/RenderThread.h"
 #include "mozilla/webrender/WebRenderAPI.h"
 #include "GLContextEGL.h"
 
 namespace mozilla {
 namespace layers {
 
 WaylandDMABUFTextureHostOGL::WaylandDMABUFTextureHostOGL(
@@ -87,22 +88,20 @@ gfx::IntSize WaylandDMABUFTextureHostOGL
 }
 
 gl::GLContext* WaylandDMABUFTextureHostOGL::gl() const {
   return mProvider ? mProvider->GetGLContext() : nullptr;
 }
 
 void WaylandDMABUFTextureHostOGL::CreateRenderTexture(
     const wr::ExternalImageId& aExternalImageId) {
-  /* TODO
-    RefPtr<wr::RenderTextureHost> texture =
-        new wr::RenderWaylandDMABUFTextureHostOGL(mImage, mSync, mSize);
-    wr::RenderThread::Get()->RegisterExternalImage(wr::AsUint64(aExternalImageId),
-                                                   texture.forget());
-  */
+  RefPtr<wr::RenderTextureHost> texture =
+      new wr::RenderWaylandDMABUFTextureHostOGL(mSurface);
+  wr::RenderThread::Get()->RegisterExternalImage(wr::AsUint64(aExternalImageId),
+                                                 texture.forget());
 }
 
 void WaylandDMABUFTextureHostOGL::PushResourceUpdates(
     wr::TransactionBuilder& aResources, ResourceUpdateOp aOp,
     const Range<wr::ImageKey>& aImageKeys, const wr::ExternalImageId& aExtID) {
   MOZ_ASSERT(mSurface);
 
   auto method = aOp == TextureHost::ADD_IMAGE
new file mode 100644
--- /dev/null
+++ b/gfx/webrender_bindings/RenderWaylandDMABUFTextureHostOGL.cpp
@@ -0,0 +1,101 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "RenderWaylandDMABUFTextureHostOGL.h"
+
+#include "GLContextEGL.h"
+#include "mozilla/gfx/Logging.h"
+#include "ScopedGLHelpers.h"
+
+namespace mozilla {
+namespace wr {
+
+RenderWaylandDMABUFTextureHostOGL::RenderWaylandDMABUFTextureHostOGL(
+    WaylandDMABufSurface* aSurface)
+    : mSurface(aSurface),
+      mTextureTarget(LOCAL_GL_TEXTURE_2D),
+      mTextureHandle(0) {
+  MOZ_COUNT_CTOR_INHERITED(RenderWaylandDMABUFTextureHostOGL,
+                           RenderTextureHostOGL);
+}
+
+RenderWaylandDMABUFTextureHostOGL::~RenderWaylandDMABUFTextureHostOGL() {
+  MOZ_COUNT_DTOR_INHERITED(RenderWaylandDMABUFTextureHostOGL,
+                           RenderTextureHostOGL);
+  DeleteTextureHandle();
+}
+
+GLuint RenderWaylandDMABUFTextureHostOGL::GetGLHandle(
+    uint8_t aChannelIndex) const {
+  MOZ_ASSERT(mSurface);
+  return mTextureHandle;
+}
+
+gfx::IntSize RenderWaylandDMABUFTextureHostOGL::GetSize(
+    uint8_t aChannelIndex) const {
+  if (!mSurface) {
+    return gfx::IntSize();
+  }
+  return gfx::IntSize(mSurface->GetWidth(), mSurface->GetHeight());
+}
+
+wr::WrExternalImage RenderWaylandDMABUFTextureHostOGL::Lock(
+    uint8_t aChannelIndex, gl::GLContext* aGL, wr::ImageRendering aRendering) {
+  MOZ_ASSERT(aChannelIndex == 0);
+
+  if (mGL.get() != aGL) {
+    if (mGL) {
+      // This should not happen. EGLImage is created only in
+      // parent process.
+      MOZ_ASSERT_UNREACHABLE("Unexpected GL context");
+      return InvalidToWrExternalImage();
+    }
+    mGL = aGL;
+  }
+
+  if (!mGL || !mGL->MakeCurrent()) {
+    return InvalidToWrExternalImage();
+  }
+
+  if (!mTextureHandle) {
+    if (!mSurface->CreateEGLImage(mGL)) {
+      return InvalidToWrExternalImage();
+    }
+
+    mTextureTarget = mGL->GetPreferredEGLImageTextureTarget();
+    MOZ_ASSERT(mTextureTarget == LOCAL_GL_TEXTURE_2D ||
+               mTextureTarget == LOCAL_GL_TEXTURE_EXTERNAL);
+
+    mGL->fGenTextures(1, &mTextureHandle);
+    // Cache rendering filter.
+    mCachedRendering = aRendering;
+    ActivateBindAndTexParameteri(mGL, LOCAL_GL_TEXTURE0, mTextureTarget,
+                                 mTextureHandle, aRendering);
+    mGL->fEGLImageTargetTexture2D(mTextureTarget, mSurface->GetEGLImage());
+  } else if (IsFilterUpdateNecessary(aRendering)) {
+    // Cache new rendering filter.
+    mCachedRendering = aRendering;
+    ActivateBindAndTexParameteri(mGL, LOCAL_GL_TEXTURE0, mTextureTarget,
+                                 mTextureHandle, aRendering);
+  }
+
+  return NativeTextureToWrExternalImage(
+      mTextureHandle, 0, 0, mSurface->GetWidth(), mSurface->GetHeight());
+}
+
+void RenderWaylandDMABUFTextureHostOGL::Unlock() {}
+
+void RenderWaylandDMABUFTextureHostOGL::DeleteTextureHandle() {
+  if (mTextureHandle) {
+    // XXX recycle gl texture, since SharedSurface_EGLImage and
+    // RenderEGLImageTextureHost is not recycled.
+    mGL->fDeleteTextures(1, &mTextureHandle);
+    mTextureHandle = 0;
+  }
+}
+
+}  // namespace wr
+}  // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/gfx/webrender_bindings/RenderWaylandDMABUFTextureHostOGL.h
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef MOZILLA_GFX_RENDERWAYLANDDMABUFTEXTUREHOSTOGL_H
+#define MOZILLA_GFX_RENDERWAYLANDDMABUFTEXTUREHOSTOGL_H
+
+#include "mozilla/layers/TextureHostOGL.h"
+#include "RenderTextureHostOGL.h"
+#include "mozilla/widget/WaylandDMABufSurface.h"
+
+namespace mozilla {
+
+namespace layers {
+class SurfaceDescriptorDMABuf;
+}
+
+namespace wr {
+
+class RenderWaylandDMABUFTextureHostOGL final : public RenderTextureHostOGL {
+ public:
+  explicit RenderWaylandDMABUFTextureHostOGL(WaylandDMABufSurface* aSurface);
+
+  wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL,
+                           wr::ImageRendering aRendering) override;
+  void Unlock() override;
+
+  gfx::IntSize GetSize(uint8_t aChannelIndex) const override;
+  GLuint GetGLHandle(uint8_t aChannelIndex) const override;
+
+ private:
+  virtual ~RenderWaylandDMABUFTextureHostOGL();
+  void DeleteTextureHandle();
+
+  RefPtr<WaylandDMABufSurface> mSurface;
+  RefPtr<gl::GLContext> mGL;
+  GLenum mTextureTarget;
+  GLuint mTextureHandle;
+};
+
+}  // namespace wr
+}  // namespace mozilla
+
+#endif  // MOZILLA_GFX_RENDERWAYLANDDMABUFTEXTUREHOSTOGL_H
--- a/gfx/webrender_bindings/moz.build
+++ b/gfx/webrender_bindings/moz.build
@@ -70,19 +70,21 @@ if CONFIG['MOZ_ENABLE_D3D10_LAYER']:
     SOURCES += [
         'DCLayerTree.cpp',
         'RenderCompositorANGLE.cpp',
     ]
 
 if CONFIG['MOZ_WAYLAND']:
     EXPORTS.mozilla.webrender += [
         'RenderCompositorEGL.h',
+        'RenderWaylandDMABUFTextureHostOGL.h',
     ]
     SOURCES += [
         'RenderCompositorEGL.cpp',
+        'RenderWaylandDMABUFTextureHostOGL.cpp',
     ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk'):
     CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
     CXXFLAGS += CONFIG['CAIRO_FT_CFLAGS']
 
 if CONFIG['COMPILE_ENVIRONMENT']:
     EXPORTS.mozilla.webrender += [