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
|
|
|
|
2016-03-05 18:20:47 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gl;
|
|
|
|
|
2014-10-21 17:53:02 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
static RefPtr<GLContext> sSnapshotContext;
|
2014-10-21 17:53:02 +04:00
|
|
|
|
2015-11-17 11:09:00 +03:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-11-27 00:16:07 +03:00
|
|
|
EGLImageImage::~EGLImageImage()
|
|
|
|
{
|
2015-11-17 11:09:00 +03:00
|
|
|
if (!mOwns) {
|
2014-11-27 00:16:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-17 11:09:00 +03:00
|
|
|
if (mImage) {
|
|
|
|
sEGLLibrary.fDestroyImage(EGL_DISPLAY(), mImage);
|
|
|
|
mImage = nullptr;
|
2014-11-27 00:16:07 +03:00
|
|
|
}
|
|
|
|
|
2015-11-17 11:09:00 +03:00
|
|
|
if (mSync) {
|
|
|
|
sEGLLibrary.fDestroySync(EGL_DISPLAY(), mSync);
|
|
|
|
mSync = nullptr;
|
2014-11-27 00:16:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2016-06-06 20:20:13 +03:00
|
|
|
nsCString discardFailureId;
|
|
|
|
sSnapshotContext = GLContextProvider::CreateHeadless(CreateContextFlags::NONE,
|
|
|
|
discardFailureId);
|
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()) {
|
2015-12-10 15:01:00 +03:00
|
|
|
MOZ_CRASH("GFX: ScopedFramebufferForTexture failed.");
|
2015-04-21 03:49:25 +03:00
|
|
|
}
|
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-11-17 11:09:00 +03:00
|
|
|
#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
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|