Bug 1304291 - Move driver workaround code into fReadPixels and remove alpha check. r=jgilbert

--HG--
extra : rebase_source : 6389bf82f86441cf0413dd15df3a81cf4decfa4c
This commit is contained in:
Chih-Yi Leu 2016-10-27 23:23:00 -04:00
Родитель 24bda82351
Коммит 33fd01fd18
2 изменённых файлов: 29 добавлений и 30 удалений

Просмотреть файл

@ -2880,6 +2880,35 @@ GLContext::fReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum f
}
AfterGLReadCall();
// Check if GL is giving back 1.0 alpha for
// RGBA reads to RGBA images from no-alpha buffers.
#ifdef XP_MACOSX
if (WorkAroundDriverBugs() &&
Vendor() == gl::GLVendor::NVIDIA &&
format == LOCAL_GL_RGBA &&
type == LOCAL_GL_UNSIGNED_BYTE &&
!IsCoreProfile() &&
width && height)
{
GLint alphaBits = 0;
fGetIntegerv(LOCAL_GL_ALPHA_BITS, &alphaBits);
if (!alphaBits) {
const uint32_t alphaMask = 0xff000000;
uint32_t* itr = (uint32_t*)pixels;
uint32_t testPixel = *itr;
if ((testPixel & alphaMask) != alphaMask) {
// We need to set the alpha channel to 1.0 manually.
uint32_t* itrEnd = itr + width*height; // Stride is guaranteed to be width*4.
for (; itr != itrEnd; itr++) {
*itr |= alphaMask;
}
}
}
}
#endif
}
void

Просмотреть файл

@ -411,36 +411,6 @@ ReadPixelsIntoDataSurface(GLContext* gl, DataSourceSurface* dest)
MOZ_ASSERT(readType == LOCAL_GL_UNSIGNED_BYTE);
gfx::Factory::CopyDataSourceSurface(readSurf, dest);
}
// Check if GL is giving back 1.0 alpha for
// RGBA reads to RGBA images from no-alpha buffers.
#ifdef XP_MACOSX
if (gl->WorkAroundDriverBugs() &&
gl->Vendor() == gl::GLVendor::NVIDIA &&
!gl->IsCoreProfile() &&
hasAlpha &&
width && height)
{
GLint alphaBits = 0;
gl->fGetIntegerv(LOCAL_GL_ALPHA_BITS, &alphaBits);
if (!alphaBits) {
const uint32_t alphaMask = gfxPackedPixelNoPreMultiply(0xff,0,0,0);
MOZ_ASSERT(dest->GetSize().width * destPixelSize == dest->Stride());
uint32_t* itr = (uint32_t*)dest->GetData();
uint32_t testPixel = *itr;
if ((testPixel & alphaMask) != alphaMask) {
// We need to set the alpha channel to 1.0 manually.
uint32_t* itrEnd = itr + width*height; // Stride is guaranteed to be width*4.
for (; itr != itrEnd; itr++) {
*itr |= alphaMask;
}
}
}
}
#endif
}
already_AddRefed<gfx::DataSourceSurface>