Bug 713774 - Fix crasher when changing orientation on Android r=blassey
authorJames Willcox <jwillcox@mozilla.com>
Wed, 04 Jan 2012 21:53:09 -0500
changeset 85051 df09a93f088775f8255c30cdaa62eccaf3d01518
parent 85050 4d652a824f11cd35ef1a9a93784586b7d906a899
child 85052 4d4a6450547766b22574deaa651caa0b0f50cf98
push idunknown
push userunknown
push dateunknown
reviewersblassey
bugs713774
milestone12.0a1
Bug 713774 - Fix crasher when changing orientation on Android r=blassey
widget/android/AndroidDirectTexture.cpp
widget/android/AndroidGraphicBuffer.cpp
widget/android/AndroidGraphicBuffer.h
widget/android/nsWindow.cpp
--- a/widget/android/AndroidDirectTexture.cpp
+++ b/widget/android/AndroidDirectTexture.cpp
@@ -121,16 +121,19 @@ AndroidDirectTexture::Reallocate(PRUint3
   MutexAutoLock lock(mLock);
 
   // We only reallocate the current back buffer. The front buffer is likely
   // in use, so we'll reallocate it on the first Lock() after it is rotated
   // to the back.
   bool result = mBackBuffer->Reallocate(aWidth, aHeight, aFormat);
   if (result) {
     mPendingReallocBuffer = mFrontBuffer;
+
+    mWidth = aWidth;
+    mHeight = aHeight;
   }
 
   return result;
 }
 
 bool
 AndroidDirectTexture::Bind()
 {
--- a/widget/android/AndroidGraphicBuffer.cpp
+++ b/widget/android/AndroidGraphicBuffer.cpp
@@ -298,34 +298,34 @@ AndroidGraphicBuffer::DestroyBuffer()
     }
     free(mHandle);
     mHandle = NULL;
   }
 
 }
 
 bool
-AndroidGraphicBuffer::EnsureBufferCreated(PRUint32 aWidth, PRUint32 aHeight, PRUint32 aUsage, gfxImageFormat aFormat)
+AndroidGraphicBuffer::EnsureBufferCreated()
 {
   if (!mHandle) {
     mHandle = malloc(GRAPHIC_BUFFER_SIZE);
-    sGLFunctions.fGraphicBufferCtor(mHandle, mWidth, mHeight, GetAndroidFormat(aFormat), GetAndroidUsage(aUsage));
+    sGLFunctions.fGraphicBufferCtor(mHandle, mWidth, mHeight, GetAndroidFormat(mFormat), GetAndroidUsage(mUsage));
   }
 
   return true;
 }
 
 bool
 AndroidGraphicBuffer::EnsureInitialized()
 {
   if (!sGLFunctions.EnsureInitialized()) {
     return false;
   }
 
-  EnsureBufferCreated(mWidth, mHeight, mUsage, mFormat);
+  EnsureBufferCreated();
   return true;
 }
 
 bool
 AndroidGraphicBuffer::Lock(PRUint32 aUsage, unsigned char **bits)
 {
   if (!EnsureInitialized())
     return true;
@@ -358,29 +358,29 @@ AndroidGraphicBuffer::Unlock()
 }
 
 bool
 AndroidGraphicBuffer::Reallocate(PRUint32 aWidth, PRUint32 aHeight, gfxImageFormat aFormat)
 {
   if (!EnsureInitialized())
     return false;
 
+  mWidth = aWidth;
+  mHeight = aHeight;
+  mFormat = aFormat;
+
   // Sometimes GraphicBuffer::reallocate just doesn't work. In those cases we'll just allocate a brand
   // new buffer. If reallocate fails once, never try it again.
   if (!gTryRealloc || sGLFunctions.fGraphicBufferReallocate(mHandle, aWidth, aHeight, GetAndroidFormat(aFormat)) != 0) {
     DestroyBuffer();
-    EnsureBufferCreated(aWidth, aHeight, mUsage, aFormat);
+    EnsureBufferCreated();
 
     gTryRealloc = false;
   }
 
-  mWidth = aWidth;
-  mHeight = aHeight;
-  mFormat = aFormat;
-
   return true;
 }
 
 PRUint32
 AndroidGraphicBuffer::GetAndroidUsage(PRUint32 aUsage)
 {
   PRUint32 flags = 0;
 
--- a/widget/android/AndroidGraphicBuffer.h
+++ b/widget/android/AndroidGraphicBuffer.h
@@ -81,17 +81,17 @@ private:
   PRUint32 mHeight;
   PRUint32 mUsage;
   gfxASurface::gfxImageFormat mFormat;
 
   bool EnsureInitialized();
   bool EnsureEGLImage();
 
   void DestroyBuffer();
-  bool EnsureBufferCreated(PRUint32 aWidth, PRUint32 aHeight, PRUint32 aUsage, gfxASurface::gfxImageFormat aFormat);
+  bool EnsureBufferCreated();
 
   PRUint32 GetAndroidUsage(PRUint32 aUsage);
   PRUint32 GetAndroidFormat(gfxASurface::gfxImageFormat aFormat);
 
   void *mHandle;
   void *mEGLImage;
 };
 
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -1186,19 +1186,18 @@ nsWindow::OnDraw(AndroidGeckoEvent *ae)
 
     AndroidGeckoSoftwareLayerClient &client =
         AndroidBridge::Bridge()->GetSoftwareLayerClient();
     client.BeginDrawing(gAndroidBounds.width, gAndroidBounds.height);
 
     nsAutoString metadata;
     unsigned char *bits = NULL;
     if (sHasDirectTexture) {
-      if ((sDirectTexture->Width() != gAndroidBounds.width ||
-           sDirectTexture->Height() != gAndroidBounds.height) &&
-          gAndroidBounds.width != 0 && gAndroidBounds.height != 0) {
+      if (sDirectTexture->Width() != gAndroidBounds.width ||
+          sDirectTexture->Height() != gAndroidBounds.height) {
         sDirectTexture->Reallocate(gAndroidBounds.width, gAndroidBounds.height);
       }
 
       sDirectTexture->Lock(AndroidGraphicBuffer::UsageSoftwareWrite, &bits);
     } else {
       bits = client.LockBufferBits();
     }
     if (!bits) {