OSDN Git Service

Prevent preparing a page with an invalid size.
authorTeng-Hui Zhu <ztenghui@google.com>
Tue, 23 Aug 2011 23:18:08 +0000 (16:18 -0700)
committerTeng-Hui Zhu <ztenghui@google.com>
Wed, 24 Aug 2011 20:19:10 +0000 (13:19 -0700)
bug:5185840
Change-Id: I9ac0ad0fcee76be8864494fd55398edf1e68506f

Source/WebCore/platform/graphics/android/TiledPage.cpp

index a69f9d1..600b3f1 100644 (file)
 #include "PaintTileOperation.h"
 #include "TilesManager.h"
 
-#ifdef DEBUG
-
 #include <cutils/log.h>
 #include <wtf/CurrentTime.h>
 #include <wtf/text/CString.h>
 
+#undef XLOGC
+#define XLOGC(...) android_printLog(ANDROID_LOG_DEBUG, "TiledPage", __VA_ARGS__)
+
+#ifdef DEBUG
+
 #undef XLOG
 #define XLOG(...) android_printLog(ANDROID_LOG_DEBUG, "TiledPage", __VA_ARGS__)
 
@@ -248,7 +251,6 @@ void TiledPage::prepare(bool goingDown, bool goingLeft, const SkIRect& tileBound
     TilesManager::instance()->gatherTextures();
     // update the tiles distance from the viewport
     updateTileState(tileBounds);
-    m_prepare = true;
     m_scrollingDown = goingDown;
 
     int firstTileX = tileBounds.fLeft;
@@ -279,8 +281,15 @@ void TiledPage::prepare(bool goingDown, bool goingLeft, const SkIRect& tileBound
     m_expandedTileBounds.fRight = lastTileX;
     m_expandedTileBounds.fBottom = lastTileY;
 
+    if (nbTilesHeight * nbTilesWidth > TilesManager::getMaxTextureAllocation() + 1) {
+        XLOGC("ERROR: We don't have enough tiles for this page!"
+              " nbTilesHeight %d nbTilesWidth %d", nbTilesHeight, nbTilesWidth);
+        return;
+    }
     for (int i = 0; i < nbTilesHeight; i++)
         prepareRow(goingLeft, nbTilesWidth, firstTileX, firstTileY + i, tileBounds);
+
+    m_prepare = true;
 }
 
 bool TiledPage::ready(const SkIRect& tileBounds, float scale)