Bug 721467 - Add an optional codepath (currently enabled only for Adreno 200 GPUs) to only use glTexImage2D for texture uploads as glTexSubImage2D can be slow and/or buggy r=joe,BenWa

--HG--
extra : rebase_source : 0f2903fe23edf3b191ae5dcfa7df6d9066d1d952
This commit is contained in:
George Wright 2012-01-24 19:44:48 -05:00
parent 24e53f97aa
commit 841e24a315
6 changed files with 86 additions and 18 deletions

View File

@ -382,6 +382,7 @@ GLContext::InitWithPrefix(const char *prefix, bool trygl)
}
const char *glVendorString;
const char *glRendererString;
if (mInitialized) {
glVendorString = (const char *)fGetString(LOCAL_GL_VENDOR);
@ -393,11 +394,23 @@ GLContext::InitWithPrefix(const char *prefix, bool trygl)
};
mVendor = VendorOther;
for (int i = 0; i < VendorOther; ++i) {
if (DoesVendorStringMatch(glVendorString, vendorMatchStrings[i])) {
if (DoesStringMatch(glVendorString, vendorMatchStrings[i])) {
mVendor = i;
break;
}
}
glRendererString = (const char *)fGetString(LOCAL_GL_RENDERER);
const char *rendererMatchStrings[RendererOther] = {
"Adreno 200"
};
mRenderer = RendererOther;
for (int i = 0; i < RendererOther; ++i) {
if (DoesStringMatch(glRendererString, rendererMatchStrings[i])) {
mRenderer = i;
break;
}
}
}
if (mInitialized) {
@ -590,6 +603,15 @@ GLContext::IsExtensionSupported(const char *extension)
return ListHasExtension(fGetString(LOCAL_GL_EXTENSIONS), extension);
}
bool
GLContext::CanUploadSubTextures()
{
// There are certain GPUs that we don't want to use glTexSubImage2D on
// because that function can be very slow and/or buggy
return !(Renderer() == RendererAdreno200);
}
// Common code for checking for both GL extensions and GLX extensions.
bool
GLContext::ListHasExtension(const GLubyte *extensions, const char *extension)
@ -688,7 +710,12 @@ BasicTextureImage::BeginUpdate(nsIntRegion& aRegion)
NS_ASSERTION(!mUpdateSurface, "BeginUpdate() without EndUpdate()?");
// determine the region the client will need to repaint
GetUpdateRegion(aRegion);
if (!mGLContext->CanUploadSubTextures()) {
aRegion = nsIntRect(nsIntPoint(0, 0), mSize);
} else {
GetUpdateRegion(aRegion);
}
mUpdateRegion = aRegion;
nsIntRect rgnSize = mUpdateRegion.GetBounds();
@ -740,6 +767,7 @@ BasicTextureImage::EndUpdate()
mGLContext->UploadSurfaceToTexture(mUpdateSurface,
mUpdateRegion,
mTexture,
mSize,
mTextureState == Created,
mUpdateOffset,
relative);
@ -798,6 +826,7 @@ BasicTextureImage::DirectUpdate(gfxASurface* aSurf, const nsIntRegion& aRegion,
mGLContext->UploadSurfaceToTexture(aSurf,
region,
mTexture,
mSize,
mTextureState == Created,
bounds.TopLeft() + aFrom,
false);
@ -851,7 +880,8 @@ bool
TiledTextureImage::DirectUpdate(gfxASurface* aSurf, const nsIntRegion& aRegion, const nsIntPoint& aFrom /* = nsIntPoint(0, 0) */)
{
nsIntRegion region;
if (mTextureState != Valid) {
if (mTextureState != Valid || !mGL->CanUploadSubTextures()) {
nsIntRect bounds = nsIntRect(0, 0, mSize.width, mSize.height);
region = nsIntRegion(bounds);
} else {
@ -1922,6 +1952,7 @@ ShaderProgramType
GLContext::UploadSurfaceToTexture(gfxASurface *aSurface,
const nsIntRegion& aDstRegion,
GLuint& aTexture,
const nsIntSize& aTextureSize,
bool aOverwrite,
const nsIntPoint& aSrcPoint,
bool aPixelBuffer)
@ -1985,6 +2016,7 @@ GLContext::UploadSurfaceToTexture(gfxASurface *aSurface,
if (!aPixelBuffer) {
data = imageSurface->Data();
}
data += DataOffset(imageSurface, aSrcPoint);
}
@ -2049,7 +2081,20 @@ GLContext::UploadSurfaceToTexture(gfxASurface *aSurface,
NS_ASSERTION(textureInited || (iterRect->x == 0 && iterRect->y == 0),
"Must be uploading to the origin when we don't have an existing texture");
if (textureInited) {
bool useTexSubImage2D = true;
nsIntRect bounds = aDstRegion.GetBounds();
// Only use glTexSubImage2D when we aren't rendering
// the entire texture
if (iterRect->x == 0 &&
iterRect->y == 0 &&
iterRect->width >= aTextureSize.width &&
iterRect->height >= aTextureSize.height) {
useTexSubImage2D = false;
}
if (textureInited && useTexSubImage2D) {
TexSubImage2D(LOCAL_GL_TEXTURE_2D,
0,
iterRect->x,
@ -2100,6 +2145,10 @@ GLContext::TexImage2D(GLenum target, GLint level, GLint internalformat,
GLenum type, const GLvoid *pixels)
{
#ifdef USE_GLES2
NS_ASSERTION(format == internalformat,
"format and internalformat not the same for glTexImage2D on GLES2");
// Use GLES-specific workarounds for GL_UNPACK_ROW_LENGTH; these are
// implemented in TexSubImage2D.
fTexImage2D(target,

View File

@ -545,6 +545,7 @@ public:
mHasRobustness(false),
mContextLost(false),
mVendor(-1),
mRenderer(-1),
mDebugMode(0),
mCreationFormat(aFormat),
mSharedContext(aSharedContext),
@ -688,10 +689,21 @@ public:
VendorOther
};
enum {
RendererAdreno200,
RendererOther
};
int Vendor() const {
return mVendor;
}
int Renderer() const {
return mRenderer;
}
bool CanUploadSubTextures();
/**
* If this context wraps a double-buffered target, swap the back
* and front buffers. It should be assumed that after a swap, the
@ -767,6 +779,7 @@ protected:
bool mFlushGuaranteesResolve;
public:
void SetFlushGuaranteesResolve(bool aFlushGuaranteesResolve) {
mFlushGuaranteesResolve = aFlushGuaranteesResolve;
}
@ -1188,6 +1201,7 @@ public:
* \param aSurface Surface to upload.
* \param aDstRegion Region of texture to upload to.
* \param aTexture Texture to use, or 0 to have one created for you.
* \param aTextureSize The size of the texture to use.
* \param aOverwrite Over an existing texture with a new one.
* \param aSrcPoint Offset into aSrc where the region's bound's
* TopLeft() sits.
@ -1199,6 +1213,7 @@ public:
ShaderProgramType UploadSurfaceToTexture(gfxASurface *aSurface,
const nsIntRegion& aDstRegion,
GLuint& aTexture,
const nsIntSize& aTextureSize,
bool aOverwrite = false,
const nsIntPoint& aSrcPoint = nsIntPoint(0, 0),
bool aPixelBuffer = false);
@ -1381,6 +1396,7 @@ protected:
bool mContextLost;
PRInt32 mVendor;
PRInt32 mRenderer;
enum {
DebugEnabled = 1 << 0,
@ -2683,23 +2699,23 @@ public:
};
inline bool
DoesVendorStringMatch(const char* aVendorString, const char *aWantedVendor)
DoesStringMatch(const char* aString, const char *aWantedString)
{
if (!aVendorString || !aWantedVendor)
if (!aString || !aWantedString)
return false;
const char *occurrence = strstr(aVendorString, aWantedVendor);
const char *occurrence = strstr(aString, aWantedString);
// aWantedVendor not found
// aWanted not found
if (!occurrence)
return false;
// aWantedVendor preceded by alpha character
if (occurrence != aVendorString && isalpha(*(occurrence-1)))
// aWantedString preceded by alpha character
if (occurrence != aString && isalpha(*(occurrence-1)))
return false;
// aWantedVendor followed by alpha character
const char *afterOccurrence = occurrence + strlen(aWantedVendor);
const char *afterOccurrence = occurrence + strlen(aWantedString);
if (isalpha(*afterOccurrence))
return false;

View File

@ -1474,6 +1474,7 @@ public:
mGLContext->UploadSurfaceToTexture(aSurf,
region,
mTexture,
mSize,
mTextureState == Created,
bounds.TopLeft() + aFrom,
false);

View File

@ -261,11 +261,11 @@ GLXLibrary::EnsureInitialized()
mHasRobustness = true;
}
gIsATI = serverVendor && DoesVendorStringMatch(serverVendor, "ATI");
gIsATI = serverVendor && DoesStringMatch(serverVendor, "ATI");
gIsChromium = (serverVendor &&
DoesVendorStringMatch(serverVendor, "Chromium")) ||
DoesStringMatch(serverVendor, "Chromium")) ||
(serverVersionStr &&
DoesVendorStringMatch(serverVersionStr, "Chromium"));
DoesStringMatch(serverVersionStr, "Chromium"));
mInitialized = true;
return true;

View File

@ -212,6 +212,7 @@ CanvasLayerOGL::UpdateSurface()
gl()->UploadSurfaceToTexture(updatedAreaSurface,
mBounds,
mTexture,
nsIntSize(mBounds.width, mBounds.height),
false,
nsIntPoint(0, 0));
}
@ -260,6 +261,7 @@ CanvasLayerOGL::RenderLayer(int aPreviousDestination,
gl()->UploadSurfaceToTexture(surf,
nsIntRect(0, 0, drawRect.width, drawRect.height),
mTexture,
nsIntSize(mBounds.width, mBounds.height),
true,
drawRect.TopLeft());
}

View File

@ -727,7 +727,7 @@ UploadYUVToTexture(GLContext* gl, const PlanarYCbCrImage::Data& aData,
aData.mYSize,
aData.mYStride,
gfxASurface::ImageFormatA8);
gl->UploadSurfaceToTexture(surf, size, texture, true);
gl->UploadSurfaceToTexture(surf, size, texture, aData.mYSize, true);
size = nsIntRect(0, 0, aData.mCbCrSize.width, aData.mCbCrSize.height);
texture = aUTexture->GetTextureID();
@ -735,14 +735,14 @@ UploadYUVToTexture(GLContext* gl, const PlanarYCbCrImage::Data& aData,
aData.mCbCrSize,
aData.mCbCrStride,
gfxASurface::ImageFormatA8);
gl->UploadSurfaceToTexture(surf, size, texture, true);
gl->UploadSurfaceToTexture(surf, size, texture, aData.mCbCrSize, true);
texture = aVTexture->GetTextureID();
surf = new gfxImageSurface(aData.mCrChannel,
aData.mCbCrSize,
aData.mCbCrStride,
gfxASurface::ImageFormatA8);
gl->UploadSurfaceToTexture(surf, size, texture, true);
gl->UploadSurfaceToTexture(surf, size, texture, aData.mCbCrSize, true);
}
void
@ -797,7 +797,7 @@ CairoImageOGL::SetData(const CairoImage::Data &aData)
mLayerProgram =
gl->UploadSurfaceToTexture(aData.mSurface,
nsIntRect(0,0, mSize.width, mSize.height),
tex, true);
tex, mSize, true);
}
void CairoImageOGL::SetTiling(bool aTiling)