2014-10-21 17:53:02 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
|
|
|
|
#include "GLImages.h"
|
|
|
|
#include "GLContext.h"
|
|
|
|
#include "GLContextProvider.h"
|
|
|
|
#include "ScopedGLHelpers.h"
|
|
|
|
#include "GLImages.h"
|
|
|
|
#include "GLBlitHelper.h"
|
|
|
|
#include "GLReadTexImageHelper.h"
|
|
|
|
#include "AndroidSurfaceTexture.h"
|
2014-11-21 18:28:19 +03:00
|
|
|
#include "GLLibraryEGL.h"
|
2014-10-21 17:53:02 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gl;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
static nsRefPtr<GLContext> sSnapshotContext;
|
|
|
|
|
2014-11-21 18:28:19 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-21 18:28:21 +03:00
|
|
|
TemporaryRef<SourceSurface>
|
|
|
|
GLImage::GetAsSourceSurface()
|
2014-10-21 17:53:02 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on the main thread");
|
|
|
|
|
|
|
|
if (!sSnapshotContext) {
|
2014-11-21 18:28:21 +03:00
|
|
|
sSnapshotContext = GLContextProvider::CreateHeadless();
|
2014-10-21 17:53:02 +04:00
|
|
|
|
|
|
|
if (!sSnapshotContext) {
|
2014-11-21 18:28:21 +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-21 18:28:21 +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-21 18:28:21 +03:00
|
|
|
size.width, size.height, 0,
|
2014-10-21 17:53:02 +04:00
|
|
|
LOCAL_GL_RGBA,
|
|
|
|
LOCAL_GL_UNSIGNED_BYTE,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
ScopedFramebufferForTexture fb(sSnapshotContext, scopedTex.Texture());
|
|
|
|
|
|
|
|
GLBlitHelper helper(sSnapshotContext);
|
|
|
|
|
2014-11-21 18:28:21 +03:00
|
|
|
helper.BlitImageToFramebuffer(this, size, fb.FB(), false);
|
2014-10-21 17:53:02 +04:00
|
|
|
ScopedBindFramebuffer bind(sSnapshotContext, fb.FB());
|
|
|
|
|
|
|
|
RefPtr<gfx::DataSourceSurface> source =
|
2014-11-21 18:28:21 +03:00
|
|
|
gfx::Factory::CreateDataSourceSurface(size, gfx::SurfaceFormat::B8G8R8A8);
|
2014-10-21 17:53:02 +04:00
|
|
|
if (NS_WARN_IF(!source)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadPixelsIntoDataSurface(sSnapshotContext, source);
|
|
|
|
return source.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // layers
|
|
|
|
} // mozilla
|
|
|
|
|
|
|
|
#endif
|