gfx/layers/GLImages.cpp
author Ted Mielczarek <ted@mielczarek.org>
Fri, 06 Jan 2017 05:57:10 -0500
changeset 328603 dedf4f49b3756b09986e78dc5519a291b81f133f
parent 317758 c83a89713c3a595481ce96e623dcf9189c2b4781
child 356782 9badb2705567f5321f0094cdec659bc772c363c5
permissions -rw-r--r--
bug 1329320 - replace makecab with rust-makecab in symbolstore. r=gps It turns out that running makecab to compress PDB files takes a significant amount of time in the buildsymbols step. I wrote an implementation of makecab in Rust that implements only the subset of features we use and it's significantly faster: https://github.com/luser/rust-makecab This patch adds a makecab check to moz.configure, adds a release build of the makecab binary to the Windows tooltool manifests, points the build at it from mozconfig.win-common, and changes symbolstore.py to use MAKECAB from substs instead of calling `makecab.exe` directly. MozReview-Commit-ID: 76FHLIZFCXS


#include "GLImages.h"
#include "GLContext.h"
#include "GLContextProvider.h"
#include "ScopedGLHelpers.h"
#include "GLImages.h"
#include "GLBlitHelper.h"
#include "GLReadTexImageHelper.h"
#include "GLLibraryEGL.h"

using namespace mozilla;
using namespace mozilla::gl;

namespace mozilla {
namespace layers {

static RefPtr<GLContext> sSnapshotContext;

EGLImageImage::EGLImageImage(EGLImage aImage, EGLSync aSync,
                             const gfx::IntSize& aSize, const gl::OriginPos& aOrigin,
                             bool aOwns)
 : GLImage(ImageFormat::EGLIMAGE),
   mImage(aImage),
   mSync(aSync),
   mSize(aSize),
   mPos(aOrigin),
   mOwns(aOwns)
{
}

EGLImageImage::~EGLImageImage()
{
  if (!mOwns) {
    return;
  }

  if (mImage) {
    sEGLLibrary.fDestroyImage(EGL_DISPLAY(), mImage);
    mImage = nullptr;
  }

  if (mSync) {
    sEGLLibrary.fDestroySync(EGL_DISPLAY(), mSync);
    mSync = nullptr;
  }
}

already_AddRefed<gfx::SourceSurface>
GLImage::GetAsSourceSurface()
{
  MOZ_ASSERT(NS_IsMainThread(), "Should be on the main thread");

  if (!sSnapshotContext) {
    nsCString discardFailureId;
    sSnapshotContext = GLContextProvider::CreateHeadless(CreateContextFlags::NONE,
                                                         &discardFailureId);
    if (!sSnapshotContext) {
      NS_WARNING("Failed to create snapshot GLContext");
      return nullptr;
    }
  }

  sSnapshotContext->MakeCurrent();
  ScopedTexture scopedTex(sSnapshotContext);
  ScopedBindTexture boundTex(sSnapshotContext, scopedTex.Texture());

  gfx::IntSize size = GetSize();
  sSnapshotContext->fTexImage2D(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_RGBA,
                                size.width, size.height, 0,
                                LOCAL_GL_RGBA,
                                LOCAL_GL_UNSIGNED_BYTE,
                                nullptr);

  ScopedFramebufferForTexture autoFBForTex(sSnapshotContext, scopedTex.Texture());
  if (!autoFBForTex.IsComplete()) {
      gfxCriticalError() << "GetAsSourceSurface: ScopedFramebufferForTexture failed.";
      return nullptr;
  }

  const gl::OriginPos destOrigin = gl::OriginPos::TopLeft;

  if (!sSnapshotContext->BlitHelper()->BlitImageToFramebuffer(this, size,
                                                              autoFBForTex.FB(),
                                                              destOrigin))
  {
    return nullptr;
  }

  RefPtr<gfx::DataSourceSurface> source =
        gfx::Factory::CreateDataSourceSurface(size, gfx::SurfaceFormat::B8G8R8A8);
  if (NS_WARN_IF(!source)) {
    return nullptr;
  }

  ScopedBindFramebuffer bind(sSnapshotContext, autoFBForTex.FB());
  ReadPixelsIntoDataSurface(sSnapshotContext, source);
  return source.forget();
}

#ifdef MOZ_WIDGET_ANDROID
SurfaceTextureImage::SurfaceTextureImage(gl::AndroidSurfaceTexture* aSurfTex,
                                         const gfx::IntSize& aSize,
                                         gl::OriginPos aOriginPos)
 : GLImage(ImageFormat::SURFACE_TEXTURE),
   mSurfaceTexture(aSurfTex),
   mSize(aSize),
   mOriginPos(aOriginPos)
{
}
#endif

} // namespace layers
} // namespace mozilla