Bug 734081 - Check pixel depth when choosing config on egl, r=cjones

This commit is contained in:
Michael Wu
2012-03-08 17:06:54 -05:00
parent 559433bc44
commit d152d3ffa3
3 changed files with 36 additions and 48 deletions

View File

@@ -42,6 +42,9 @@
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/Util.h" #include "mozilla/Util.h"
#include "nsIScreen.h"
#include "nsIScreenManager.h"
#if defined(XP_UNIX) #if defined(XP_UNIX)
#ifdef MOZ_WIDGET_GTK2 #ifdef MOZ_WIDGET_GTK2
@@ -2190,13 +2193,6 @@ static const EGLint kEGLConfigAttribsRGBA32[] = {
LOCAL_EGL_NONE LOCAL_EGL_NONE
}; };
// This struct is used only by CreateConfig below, but ISO C++98 forbids
// instantiating a template dependent on a locally-defined type. Boo-urns!
struct EGLAttribs {
gfxASurface::gfxImageFormat mFormat;
const EGLint* mAttribs;
};
// Return true if a suitable EGLConfig was found and pass it out // Return true if a suitable EGLConfig was found and pass it out
// through aConfig. Return false otherwise. // through aConfig. Return false otherwise.
// //
@@ -2205,25 +2201,22 @@ struct EGLAttribs {
static bool static bool
CreateConfig(EGLConfig* aConfig) CreateConfig(EGLConfig* aConfig)
{ {
EGLAttribs attribsToTry[] = { nsCOMPtr<nsIScreenManager> screenMgr = do_GetService("@mozilla.org/gfx/screenmanager;1");
#ifdef MOZ_GFX_OPTIMIZE_MOBILE nsCOMPtr<nsIScreen> screen;
// Prefer r5g6b5 for potential savings in memory bandwidth. screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
// This needs to be reevaluated for newer devices. PRInt32 depth = 24;
{ gfxASurface::ImageFormatRGB16_565, kEGLConfigAttribsRGB16 }, screen->GetColorDepth(&depth);
#endif
{ gfxASurface::ImageFormatARGB32, kEGLConfigAttribsRGBA32 },
};
EGLConfig configs[64]; EGLConfig configs[64];
for (unsigned i = 0; i < ArrayLength(attribsToTry); ++i) { gfxASurface::gfxImageFormat format;
const EGLAttribs& attribs = attribsToTry[i]; const EGLint* attribs = depth == 16 ? kEGLConfigAttribsRGB16 :
kEGLConfigAttribsRGBA32;
EGLint ncfg = ArrayLength(configs); EGLint ncfg = ArrayLength(configs);
if (!sEGLLibrary.fChooseConfig(EGL_DISPLAY(), attribs.mAttribs, if (!sEGLLibrary.fChooseConfig(EGL_DISPLAY(), attribs,
configs, ncfg, &ncfg) || configs, ncfg, &ncfg) ||
ncfg < 1) ncfg < 1) {
{ return false;
continue;
} }
for (int j = 0; j < ncfg; ++j) { for (int j = 0; j < ncfg; ++j) {
@@ -2238,16 +2231,13 @@ CreateConfig(EGLConfig* aConfig)
LOCAL_EGL_BLUE_SIZE, &b) && LOCAL_EGL_BLUE_SIZE, &b) &&
sEGLLibrary.fGetConfigAttrib(EGL_DISPLAY(), config, sEGLLibrary.fGetConfigAttrib(EGL_DISPLAY(), config,
LOCAL_EGL_ALPHA_SIZE, &a) && LOCAL_EGL_ALPHA_SIZE, &a) &&
((gfxASurface::ImageFormatRGB16_565 == attribs.mFormat && ((depth == 16 && r == 5 && g == 6 && b == 5) ||
r == 5 && g == 6 && b == 5) || (depth == 24 && r == 8 && g == 8 && b == 8 && a == 8)))
(gfxASurface::ImageFormatARGB32 == attribs.mFormat &&
r == 8 && g == 8 && b == 8 && a == 8)))
{ {
*aConfig = config; *aConfig = config;
return true; return true;
} }
} }
}
return false; return false;
} }

View File

@@ -78,7 +78,7 @@ nsScreenAndroid::GetPixelDepth(PRInt32 *aPixelDepth)
{ {
// XXX do we need to lie here about 16bpp? Or // XXX do we need to lie here about 16bpp? Or
// should we actually check and return the right thing? // should we actually check and return the right thing?
*aPixelDepth = 24; *aPixelDepth = 16;
return NS_OK; return NS_OK;
} }

View File

@@ -510,9 +510,7 @@ nsScreenGonk::GetAvailRect(PRInt32 *outLeft, PRInt32 *outTop,
NS_IMETHODIMP NS_IMETHODIMP
nsScreenGonk::GetPixelDepth(PRInt32 *aPixelDepth) nsScreenGonk::GetPixelDepth(PRInt32 *aPixelDepth)
{ {
// XXX do we need to lie here about 16bpp? Or *aPixelDepth = gNativeWindow->getDevice()->format == GGL_PIXEL_FORMAT_RGB_565 ? 16 : 24;
// should we actually check and return the right thing?
*aPixelDepth = 24;
return NS_OK; return NS_OK;
} }