Add a new Image class that wraps drawable TextureClients. (bug 1217665 part 4, r=nical)
authorDavid Anderson <danderson@mozilla.com>
Wed, 02 Dec 2015 11:31:17 -0800
changeset 309452 1079b6b580c2a749ee470981a7458e8351b3960e
parent 309451 9e77cc23c491b89bc7051c670266247f1ec491d3
child 309453 1b245f8b7feaacf8ef80bce4afa1871e6714a88d
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1217665
milestone45.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
Add a new Image class that wraps drawable TextureClients. (bug 1217665 part 4, r=nical)
gfx/layers/ImageTypes.h
gfx/layers/TextureWrapperImage.cpp
gfx/layers/TextureWrapperImage.h
gfx/layers/client/TextureClient.cpp
gfx/layers/composite/PaintedLayerComposite.cpp
gfx/layers/ipc/ImageContainerParent.cpp
gfx/layers/moz.build
--- a/gfx/layers/ImageTypes.h
+++ b/gfx/layers/ImageTypes.h
@@ -81,17 +81,22 @@ enum class ImageFormat {
    * An Image type carries an opaque handle once for each stream.
    * The opaque handle would be a platform specific identifier.
    */
   OVERLAY_IMAGE,
 
   /**
    * A share handle to a ID3D11Texture2D.
    */
-  D3D11_SHARE_HANDLE_TEXTURE
+  D3D11_SHARE_HANDLE_TEXTURE,
+
+  /**
+   * A wrapper around a drawable TextureClient.
+   */
+  TEXTURE_WRAPPER
 };
 
 enum class StereoMode {
   MONO,
   LEFT_RIGHT,
   RIGHT_LEFT,
   BOTTOM_TOP,
   TOP_BOTTOM
new file mode 100644
--- /dev/null
+++ b/gfx/layers/TextureWrapperImage.cpp
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * 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 "TextureWrapperImage.h"
+
+namespace mozilla {
+namespace layers {
+
+using namespace mozilla::gfx;
+
+TextureWrapperImage::TextureWrapperImage(TextureClient* aClient, const IntRect& aPictureRect)
+ : Image(nullptr, ImageFormat::TEXTURE_WRAPPER),
+   mPictureRect(aPictureRect),
+   mTextureClient(aClient)
+{
+}
+
+TextureWrapperImage::~TextureWrapperImage()
+{
+}
+
+gfx::IntSize
+TextureWrapperImage::GetSize()
+{
+  return mTextureClient->GetSize();
+}
+
+gfx::IntRect
+TextureWrapperImage::GetPictureRect()
+{
+  return mPictureRect;
+}
+
+already_AddRefed<gfx::SourceSurface>
+TextureWrapperImage::GetAsSourceSurface()
+{
+  TextureClientAutoLock autoLock(mTextureClient, OpenMode::OPEN_READ);
+  if (!autoLock.Succeeded()) {
+    return nullptr;
+  }
+
+  return mTextureClient->BorrowDrawTarget()->Snapshot();
+}
+
+TextureClient*
+TextureWrapperImage::GetTextureClient(CompositableClient* aClient)
+{
+  return mTextureClient;
+}
+
+} // namespace layers
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/gfx/layers/TextureWrapperImage.h
@@ -0,0 +1,37 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * 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 GFX_LAYERS_TEXTUREWRAPPINGIMAGE_H_
+#define GFX_LAYERS_TEXTUREWRAPPINGIMAGE_H_
+
+#include "mozilla/RefPtr.h"
+#include "ImageContainer.h"
+#include "mozilla/layers/TextureClient.h"
+
+namespace mozilla {
+namespace layers {
+
+// Wraps a TextureClient into an Image. This may only be used on the main
+// thread, and only with TextureClients that support BorrowDrawTarget().
+class TextureWrapperImage final : public Image
+{
+public:
+  TextureWrapperImage(TextureClient* aClient, const gfx::IntRect& aPictureRect);
+  ~TextureWrapperImage() override;
+
+  gfx::IntSize GetSize() override;
+  gfx::IntRect GetPictureRect() override;
+  already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override;
+  TextureClient* GetTextureClient(CompositableClient* aClient) override;
+
+private:
+  gfx::IntRect mPictureRect;
+  RefPtr<TextureClient> mTextureClient;
+};
+
+} // namespace layers
+} // namespace mozilla
+
+#endif // GFX_LAYERS_TEXTUREWRAPPINGIMAGE_H_
--- a/gfx/layers/client/TextureClient.cpp
+++ b/gfx/layers/client/TextureClient.cpp
@@ -5,33 +5,36 @@
 
 #include "mozilla/layers/TextureClient.h"
 #include <stdint.h>                     // for uint8_t, uint32_t, etc
 #include "Layers.h"                     // for Layer, etc
 #include "gfx2DGlue.h"
 #include "gfxPlatform.h"                // for gfxPlatform
 #include "mozilla/Atomics.h"
 #include "mozilla/ipc/SharedMemory.h"   // for SharedMemory, etc
+#include "mozilla/layers/AsyncTransactionTracker.h"
 #include "mozilla/layers/CompositableForwarder.h"
 #include "mozilla/layers/ISurfaceAllocator.h"
 #include "mozilla/layers/ImageDataSerializer.h"
+#include "mozilla/layers/TextureClientRecycleAllocator.h"
 #include "mozilla/layers/YCbCrImageDataSerializer.h"
 #include "nsDebug.h"                    // for NS_ASSERTION, NS_WARNING, etc
 #include "nsISupportsImpl.h"            // for MOZ_COUNT_CTOR, etc
 #include "ImageContainer.h"             // for PlanarYCbCrData, etc
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/Logging.h"        // for gfxDebug
 #include "mozilla/layers/TextureClientOGL.h"
 #include "mozilla/layers/PTextureChild.h"
 #include "mozilla/gfx/DataSurfaceHelpers.h" // for CreateDataSourceSurfaceByCloning
 #include "nsPrintfCString.h"            // for nsPrintfCString
 #include "LayersLogging.h"              // for AppendToString
 #include "gfxUtils.h"                   // for gfxUtils::GetAsLZ4Base64Str
 #include "IPDLActor.h"
 #include "BufferTexture.h"
+#include "gfxPrefs.h"
 
 #ifdef XP_WIN
 #include "mozilla/layers/TextureD3D9.h"
 #include "mozilla/layers/TextureD3D11.h"
 #include "mozilla/layers/TextureDIB.h"
 #include "gfxWindowsPlatform.h"
 #include "gfx2DGlue.h"
 #endif
--- a/gfx/layers/composite/PaintedLayerComposite.cpp
+++ b/gfx/layers/composite/PaintedLayerComposite.cpp
@@ -120,17 +120,17 @@ PaintedLayerComposite::RenderLayer(const
     if (surf) {
       WriteSnapshotToDumpFile(this, surf);
     }
   }
 #endif
 
 
   RenderWithAllMasks(this, compositor, aClipRect,
-                     [&](EffectChain& effectChain, const Rect& clipRect) {
+                     [&](EffectChain& effectChain, const gfx::Rect& clipRect) {
     mBuffer->SetPaintWillResample(MayResample());
 
     mBuffer->Composite(this, effectChain,
                        GetEffectiveOpacity(),
                        GetEffectiveTransform(),
                        GetEffectFilter(),
                        clipRect,
                        &visibleRegion);
--- a/gfx/layers/ipc/ImageContainerParent.cpp
+++ b/gfx/layers/ipc/ImageContainerParent.cpp
@@ -4,16 +4,17 @@
 /* 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 "ImageContainerParent.h"
 
 #include "nsThreadUtils.h"
 #include "mozilla/layers/ImageHost.h"
+#include "mozilla/unused.h"
 
 namespace mozilla {
 namespace layers {
 
 ImageContainerParent::~ImageContainerParent()
 {
   while (!mImageHosts.IsEmpty()) {
     mImageHosts[mImageHosts.Length() - 1]->SetImageContainer(nullptr);
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -172,16 +172,17 @@ EXPORTS.mozilla.layers += [
     'opengl/GrallocTextureClient.h',
     'opengl/GrallocTextureHost.h',
     'opengl/MacIOSurfaceTextureClientOGL.h',
     'opengl/MacIOSurfaceTextureHostOGL.h',
     'opengl/TextureClientOGL.h',
     'opengl/TextureHostOGL.h',
     'PersistentBufferProvider.h',
     'RenderTrace.h',
+    'TextureWrapperImage.h',
     'TransactionIdAllocator.h',
     'YCbCrImageDataSerializer.h',
 ]
 
 if CONFIG['MOZ_X11']:
     EXPORTS.mozilla.layers += [
         'basic/TextureClientX11.h',
         'basic/X11TextureSourceBasic.h',
@@ -343,16 +344,17 @@ UNIFIED_SOURCES += [
     'opengl/OGLShaderProgram.cpp',
     'opengl/TextureClientOGL.cpp',
     'opengl/TextureHostOGL.cpp',
     'opengl/TexturePoolOGL.cpp',
     'protobuf/LayerScopePacket.pb.cc',
     'ReadbackProcessor.cpp',
     'RenderTrace.cpp',
     'RotatedBuffer.cpp',
+    'TextureWrapperImage.cpp',
     'YCbCrImageDataSerializer.cpp',
 ]
 
 SOURCES += [
     'basic/BasicImageLayer.cpp',
     'ImageContainer.cpp',
     'Layers.cpp',
     'LayerTreeInvalidation.cpp',