Bug 709490 - Part 9: Readback without blocking main thread. r=jgilbert

This commit is contained in:
Morris Tseng
2015-10-05 10:50:16 +08:00
parent 763f11b31c
commit 1e04cd9230
18 changed files with 477 additions and 24 deletions

View File

@@ -214,7 +214,7 @@ GetActualReadFormats(GLContext* gl,
}
}
static void
void
SwapRAndBComponents(DataSourceSurface* surf)
{
DataSourceSurface::MappedSurface map;
@@ -614,8 +614,7 @@ ReadBackSurface(GLContext* gl, GLuint aTexture, bool aYInvert, SurfaceFormat aFo
#define CLEANUP_IF_GLERROR_OCCURRED(x) \
if (DidGLErrorOccur(x)) { \
isurf = nullptr; \
break; \
return false; \
}
already_AddRefed<DataSourceSurface>
@@ -624,6 +623,31 @@ GLReadTexImageHelper::ReadTexImage(GLuint aTextureId,
const gfx::IntSize& aSize,
/* ShaderConfigOGL.mFeature */ int aConfig,
bool aYInvert)
{
/* Allocate resulting image surface */
int32_t stride = aSize.width * BytesPerPixel(SurfaceFormat::R8G8B8A8);
RefPtr<DataSourceSurface> isurf =
Factory::CreateDataSourceSurfaceWithStride(aSize,
SurfaceFormat::R8G8B8A8,
stride);
if (NS_WARN_IF(!isurf)) {
return nullptr;
}
if (!ReadTexImage(isurf, aTextureId, aTextureTarget, aSize, aConfig, aYInvert)) {
return nullptr;
}
return isurf.forget();
}
bool
GLReadTexImageHelper::ReadTexImage(DataSourceSurface* aDest,
GLuint aTextureId,
GLenum aTextureTarget,
const gfx::IntSize& aSize,
/* ShaderConfigOGL.mFeature */ int aConfig,
bool aYInvert)
{
MOZ_ASSERT(aTextureTarget == LOCAL_GL_TEXTURE_2D ||
aTextureTarget == LOCAL_GL_TEXTURE_EXTERNAL ||
@@ -631,16 +655,6 @@ GLReadTexImageHelper::ReadTexImage(GLuint aTextureId,
mGL->MakeCurrent();
/* Allocate resulting image surface */
int32_t stride = aSize.width * BytesPerPixel(SurfaceFormat::R8G8B8A8);
RefPtr<DataSourceSurface> isurf =
Factory::CreateDataSourceSurfaceWithStride(aSize,
SurfaceFormat::R8G8B8A8,
stride);
if (NS_WARN_IF(!isurf)) {
return nullptr;
}
GLint oldrb, oldfb, oldprog, oldTexUnit, oldTex;
GLuint rb, fb;
@@ -737,7 +751,7 @@ GLReadTexImageHelper::ReadTexImage(GLuint aTextureId,
CLEANUP_IF_GLERROR_OCCURRED("when drawing texture");
/* Read-back draw results */
ReadPixelsIntoDataSurface(mGL, isurf);
ReadPixelsIntoDataSurface(mGL, aDest);
CLEANUP_IF_GLERROR_OCCURRED("when reading pixels into surface");
} while (false);
@@ -756,7 +770,7 @@ GLReadTexImageHelper::ReadTexImage(GLuint aTextureId,
if (oldTexUnit != LOCAL_GL_TEXTURE0)
mGL->fActiveTexture(oldTexUnit);
return isurf.forget();
return true;
}
#undef CLEANUP_IF_GLERROR_OCCURRED