Cherry-pick: Clear m_lastImageId for software compositor
Cherry-pick with conflict of
http://src.chromium.org/viewvc/blink?view=revision&revision=167365
Conflicts:
Source/web/tests/Canvas2DLayerBridgeTest.cpp
Original description:
When android webview swith to software only mode, all mailboxes are
returned to Canvas2DLayerBridge. In this case, if the canvas is static,
then prepareMailbox will never return a new mailbox. So clear m_lastImageId
in this case.
BUG: 13328348
Change-Id: I5d8ec2cb5c613b0991bc66df29a0ff17441f018c
diff --git a/Source/platform/graphics/Canvas2DLayerBridge.cpp b/Source/platform/graphics/Canvas2DLayerBridge.cpp
index 492dc2b..91f024b 100644
--- a/Source/platform/graphics/Canvas2DLayerBridge.cpp
+++ b/Source/platform/graphics/Canvas2DLayerBridge.cpp
@@ -264,10 +264,11 @@
{
if (bitmap) {
// Using accelerated 2d canvas with software renderer, which
- // should only happen in tests that use fake graphics contexts.
- // In this case, we do not care about producing any results for
- // compositing.
+ // should only happen in tests that use fake graphics contexts
+ // or in Android WebView in software mode. In this case, we do
+ // not care about producing any results for this canvas.
m_canvas->silentFlush();
+ m_lastImageId = 0;
return false;
}
if (!isValid())
diff --git a/Source/web/tests/Canvas2DLayerBridgeTest.cpp b/Source/web/tests/Canvas2DLayerBridgeTest.cpp
index 83db780..dd3e507 100644
--- a/Source/web/tests/Canvas2DLayerBridgeTest.cpp
+++ b/Source/web/tests/Canvas2DLayerBridgeTest.cpp
@@ -30,6 +30,7 @@
#include "SkSurface.h"
#include "platform/graphics/ImageBuffer.h"
#include "public/platform/Platform.h"
+#include "public/platform/WebExternalBitmap.h"
#include "public/platform/WebThread.h"
#include "third_party/skia/include/core/SkDevice.h"
#include "web/tests/MockWebGraphicsContext3D.h"
@@ -70,6 +71,23 @@
RefPtr<Canvas2DLayerBridge> m_layerBridge;
};
+class NullWebExternalBitmap : public WebExternalBitmap {
+public:
+ virtual WebSize size()
+ {
+ return WebSize();
+ }
+
+ virtual void setSize(WebSize)
+ {
+ }
+
+ virtual uint8* pixels()
+ {
+ return 0;
+ }
+};
+
} // namespace
class Canvas2DLayerBridgeTest : public Test {
@@ -98,6 +116,19 @@
::testing::Mock::VerifyAndClearExpectations(&mainMock);
}
+
+ void prepareMailboxWithBitmapTest()
+ {
+ MockCanvasContext mainMock;
+ OwnPtr<SkDeferredCanvas> canvas = adoptPtr(SkDeferredCanvas::Create(SkSurface::NewRasterPMColor(300, 150)));
+ OwnPtr<MockWebGraphicsContext3DProvider> mainMockProvider = adoptPtr(new MockWebGraphicsContext3DProvider(&mainMock));
+ Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(mainMockProvider.release(), canvas.release(), 0, NonOpaque)));
+ bridge->m_lastImageId = 1;
+
+ NullWebExternalBitmap bitmap;
+ bridge->prepareMailbox(0, &bitmap);
+ EXPECT_EQ(0u, bridge->m_lastImageId);
+ }
};
namespace {
@@ -107,4 +138,9 @@
fullLifecycleTest();
}
+TEST_F(Canvas2DLayerBridgeTest, prepareMailboxWithBitmapTest)
+{
+ prepareMailboxWithBitmapTest();
+}
+
} // namespace