4 #include "GLContextProvider.h"
5 #include "ScopedGLHelpers.h"
7 #include "GLBlitHelper.h"
8 #include "GLReadTexImageHelper.h"
9 #include "GLLibraryEGL.h"
11 using namespace mozilla
;
12 using namespace mozilla::gl
;
17 static nsRefPtr
<GLContext
> sSnapshotContext
;
19 EGLImageImage::~EGLImageImage()
26 sEGLLibrary
.fDestroyImage(EGL_DISPLAY(), mData
.mImage
);
27 mData
.mImage
= nullptr;
31 sEGLLibrary
.fDestroySync(EGL_DISPLAY(), mData
.mSync
);
32 mData
.mSync
= nullptr;
36 TemporaryRef
<gfx::SourceSurface
>
37 GLImage::GetAsSourceSurface()
39 MOZ_ASSERT(NS_IsMainThread(), "Should be on the main thread");
41 if (!sSnapshotContext
) {
42 sSnapshotContext
= GLContextProvider::CreateHeadless();
43 if (!sSnapshotContext
) {
44 NS_WARNING("Failed to create snapshot GLContext");
49 sSnapshotContext
->MakeCurrent();
50 ScopedTexture
scopedTex(sSnapshotContext
);
51 ScopedBindTexture
boundTex(sSnapshotContext
, scopedTex
.Texture());
53 gfx::IntSize size
= GetSize();
54 sSnapshotContext
->fTexImage2D(LOCAL_GL_TEXTURE_2D
, 0, LOCAL_GL_RGBA
,
55 size
.width
, size
.height
, 0,
57 LOCAL_GL_UNSIGNED_BYTE
,
60 ScopedFramebufferForTexture
fb(sSnapshotContext
, scopedTex
.Texture());
62 GLBlitHelper
helper(sSnapshotContext
);
64 if (!helper
.BlitImageToFramebuffer(this, size
, fb
.FB(), true)) {
68 RefPtr
<gfx::DataSourceSurface
> source
=
69 gfx::Factory::CreateDataSourceSurface(size
, gfx::SurfaceFormat::B8G8R8A8
);
70 if (NS_WARN_IF(!source
)) {
74 ScopedBindFramebuffer
bind(sSnapshotContext
, fb
.FB());
75 ReadPixelsIntoDataSurface(sSnapshotContext
, source
);
76 return source
.forget();