Bug 1014614 - Fix readback of SurfaceTextureImage r=jgilbert

--HG--
extra : rebase_source : 3580c219b47615d55bfa3d1c672d017dd67ef0a1
extra : histedit_source : 24c932ac4ebabad7d706fa5599d5f32762ce5a02
This commit is contained in:
James Willcox 2014-10-17 10:35:13 -05:00
parent 95f737ee34
commit ca475bfea2
3 changed files with 62 additions and 4 deletions

60
gfx/layers/GLImages.cpp Normal file
View File

@ -0,0 +1,60 @@
#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"
using namespace mozilla;
using namespace mozilla::gl;
static Mutex sSnapshotMutex("SurfaceTextureImage::sSnapshotMutex");
static nsRefPtr<GLContext> sSnapshotContext;
TemporaryRef<gfx::SourceSurface>
SurfaceTextureImage::GetAsSourceSurface()
{
MutexAutoLock lock(sSnapshotMutex);
MOZ_ASSERT(NS_IsMainThread(), "Should be on the main thread");
if (!sSnapshotContext) {
SurfaceCaps caps = SurfaceCaps::ForRGBA();
sSnapshotContext = GLContextProvider::CreateOffscreen(gfxIntSize(16, 16), caps);
if (!sSnapshotContext) {
return nullptr;
}
}
sSnapshotContext->MakeCurrent();
ScopedTexture scopedTex(sSnapshotContext);
ScopedBindTexture boundTex(sSnapshotContext, scopedTex.Texture());
sSnapshotContext->fTexImage2D(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_RGBA,
mData.mSize.width, mData.mSize.height, 0,
LOCAL_GL_RGBA,
LOCAL_GL_UNSIGNED_BYTE,
nullptr);
ScopedFramebufferForTexture fb(sSnapshotContext, scopedTex.Texture());
GLBlitHelper helper(sSnapshotContext);
helper.BlitImageToFramebuffer(this, mData.mSize, fb.FB(), false);
ScopedBindFramebuffer bind(sSnapshotContext, fb.FB());
RefPtr<DataSourceSurface> source =
Factory::CreateDataSourceSurface(mData.mSize, gfx::SurfaceFormat::B8G8R8A8);
if (NS_WARN_IF(!source)) {
return nullptr;
}
ReadPixelsIntoDataSurface(sSnapshotContext, source);
return source.forget();
}
#endif

View File

@ -57,10 +57,7 @@ public:
gfx::IntSize GetSize() { return mData.mSize; }
virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE
{
return nullptr;
}
virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE;
SurfaceTextureImage() : Image(nullptr, ImageFormat::SURFACE_TEXTURE) {}

View File

@ -288,6 +288,7 @@ UNIFIED_SOURCES += [
'Compositor.cpp',
'CopyableCanvasLayer.cpp',
'Effects.cpp',
'GLImages.cpp',
'ImageDataSerializer.cpp',
'ImageLayers.cpp',
'ipc/AsyncTransactionTracker.cpp',