2014-10-21 17:53:02 +04:00
|
|
|
|
|
|
|
#include "GLImages.h"
|
|
|
|
#include "GLContext.h"
|
|
|
|
#include "GLContextProvider.h"
|
|
|
|
#include "ScopedGLHelpers.h"
|
|
|
|
#include "GLImages.h"
|
|
|
|
#include "GLBlitHelper.h"
|
|
|
|
#include "GLReadTexImageHelper.h"
|
2014-11-27 00:16:07 +03:00
|
|
|
#include "GLLibraryEGL.h"
|
2014-10-21 17:53:02 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gl;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
static RefPtr<GLContext> sSnapshotContext;
|
2014-10-21 17:53:02 +04:00
|
|
|
|
2014-11-27 00:16:07 +03:00
|
|
|
EGLImageImage::~EGLImageImage()
|
|
|
|
{
|
|
|
|
if (!mData.mOwns) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mData.mImage) {
|
|
|
|
sEGLLibrary.fDestroyImage(EGL_DISPLAY(), mData.mImage);
|
|
|
|
mData.mImage = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mData.mSync) {
|
|
|
|
sEGLLibrary.fDestroySync(EGL_DISPLAY(), mData.mSync);
|
|
|
|
mData.mSync = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<gfx::SourceSurface>
|
2014-11-27 00:16:08 +03:00
|
|
|
GLImage::GetAsSourceSurface()
|
2014-10-21 17:53:02 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on the main thread");
|
|
|
|
|
|
|
|
if (!sSnapshotContext) {
|
2015-07-29 23:35:55 +03:00
|
|
|
sSnapshotContext = GLContextProvider::CreateHeadless(CreateContextFlags::NONE);
|
2014-10-21 17:53:02 +04:00
|
|
|
if (!sSnapshotContext) {
|
2014-11-27 00:16:08 +03:00
|
|
|
NS_WARNING("Failed to create snapshot GLContext");
|
2014-10-21 17:53:02 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sSnapshotContext->MakeCurrent();
|
|
|
|
ScopedTexture scopedTex(sSnapshotContext);
|
|
|
|
ScopedBindTexture boundTex(sSnapshotContext, scopedTex.Texture());
|
2014-11-27 00:16:08 +03:00
|
|
|
|
|
|
|
gfx::IntSize size = GetSize();
|
2014-10-21 17:53:02 +04:00
|
|
|
sSnapshotContext->fTexImage2D(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_RGBA,
|
2014-11-27 00:16:08 +03:00
|
|
|
size.width, size.height, 0,
|
2014-10-21 17:53:02 +04:00
|
|
|
LOCAL_GL_RGBA,
|
|
|
|
LOCAL_GL_UNSIGNED_BYTE,
|
|
|
|
nullptr);
|
|
|
|
|
2015-04-21 03:49:25 +03:00
|
|
|
ScopedFramebufferForTexture autoFBForTex(sSnapshotContext, scopedTex.Texture());
|
|
|
|
if (!autoFBForTex.IsComplete()) {
|
|
|
|
MOZ_CRASH("ScopedFramebufferForTexture failed.");
|
|
|
|
}
|
2014-10-21 17:53:02 +04:00
|
|
|
|
2015-04-21 03:49:25 +03:00
|
|
|
const gl::OriginPos destOrigin = gl::OriginPos::TopLeft;
|
2014-10-21 17:53:02 +04:00
|
|
|
|
2015-04-21 03:49:25 +03:00
|
|
|
if (!sSnapshotContext->BlitHelper()->BlitImageToFramebuffer(this, size,
|
|
|
|
autoFBForTex.FB(),
|
|
|
|
destOrigin))
|
|
|
|
{
|
2015-02-03 00:25:22 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-10-21 17:53:02 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfx::DataSourceSurface> source =
|
2014-11-27 00:16:08 +03:00
|
|
|
gfx::Factory::CreateDataSourceSurface(size, gfx::SurfaceFormat::B8G8R8A8);
|
2014-10-21 17:53:02 +04:00
|
|
|
if (NS_WARN_IF(!source)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-04-21 03:49:25 +03:00
|
|
|
ScopedBindFramebuffer bind(sSnapshotContext, autoFBForTex.FB());
|
2014-10-21 17:53:02 +04:00
|
|
|
ReadPixelsIntoDataSurface(sSnapshotContext, source);
|
|
|
|
return source.forget();
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|