Index: cc/CCDecorationLayerImplTest.cpp |
diff --git a/cc/CCDecorationLayerImplTest.cpp b/cc/CCDecorationLayerImplTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7f1247a0062706fcfefff182d063eeb93f2b553c |
--- /dev/null |
+++ b/cc/CCDecorationLayerImplTest.cpp |
@@ -0,0 +1,87 @@ |
+// Copyright 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+ |
+#include "CCDecorationLayerImpl.h" |
+ |
+#include "CCAppendQuadsData.h" |
+#include "CCLayerTestCommon.h" |
+#include "CCSingleThreadProxy.h" |
+#include "CCTextureDrawQuad.h" |
+#include "MockCCQuadCuller.h" |
+#include "public/WebTransformationMatrix.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+using namespace cc; |
+using namespace CCLayerTestCommon; |
+ |
+namespace { |
+ |
+TEST(CCDecorationLayerImplTest, verifyDrawQuads) |
+{ |
+ DebugScopedSetImplThread scopedImplThread; |
+ |
+ // Input is a 100x100 bitmap with a 20x20 aperture at x=20, y=20. |
+ // The bounds of the layer are set to 400x400, so the draw quads |
+ // generated should leave the border width (20) intact. |
+ MockCCQuadCuller quadCuller; |
+ IntSize bitmapSize = IntSize(100, 100); |
+ IntSize layerSize = IntSize(400, 400); |
+ IntRect visibleContentRect = IntRect(IntPoint(), layerSize); |
+ IntRect apertureRect = IntRect(20, 20, 20, 20); |
+ IntRect scaledApertureNonUniform = IntRect(20, 20, 320, 320); |
+ |
+ OwnPtr<CCDecorationLayerImpl> layer = CCDecorationLayerImpl::create(1); |
+ layer->setVisibleContentRect(visibleContentRect); |
+ layer->setBounds(layerSize); |
+ layer->setContentBounds(layerSize); |
+ layer->createRenderSurface(); |
+ layer->setRenderTarget(layer.get()); |
+ layer->setDecorationLayout(bitmapSize, apertureRect); |
+ layer->setResourceId(1); |
+ |
+ // This scale should not affect the generated quad geometry, but only |
+ // the shared draw transform. |
+ WebKit::WebTransformationMatrix transform; |
+ transform.scale(10); |
+ layer->setDrawTransform(transform); |
+ |
+ CCAppendQuadsData data; |
+ layer->appendQuads(quadCuller, data); |
+ |
+ // Verify quad rects |
+ const CCQuadList& quads = quadCuller.quadList(); |
+ EXPECT_EQ(quads.size(), 8); |
+ Region remaining(visibleContentRect); |
+ for (size_t i = 0; i < quads.size(); ++i) { |
+ CCDrawQuad* quad = quads[i]; |
+ IntRect quadRect = quad->quadRect(); |
+ |
+ EXPECT_TRUE(visibleContentRect.contains(quadRect)) << quadString << i; |
+ EXPECT_TRUE(remaining.contains(quadRect)) << quadString << i; |
+ EXPECT_EQ(quad->sharedQuadState()->quadTransform, transform) << quadString << i; |
+ remaining.subtract(cc::Region(quadRect)); |
+ } |
+ EXPECT_EQ(remaining.rects().size(), 1); |
+ EXPECT_EQ(remaining.rects()[0], scaledApertureNonUniform); |
+ |
+ // Verify UV rects |
+ IntRect bitmapRect(IntPoint(), bitmapSize); |
+ Region texRemaining(bitmapRect); |
+ for (size_t i = 0; i < quads.size(); ++i) { |
+ CCDrawQuad* quad = quads[i]; |
+ ASSERT_EQ(quad->material(), CCDrawQuad::TextureContent); |
+ CCTextureDrawQuad* texQuad = static_cast<CCTextureDrawQuad*>(quad); |
+ WebCore::FloatRect texRect = texQuad->uvRect(); |
+ texRect.scale(bitmapSize.width(), bitmapSize.height()); |
+ WebCore::IntRect rect(texRect); |
+ texRemaining.subtract(cc::Region(rect)); |
+ } |
+ EXPECT_EQ(texRemaining.rects().size(), 1); |
+ EXPECT_EQ(texRemaining.rects()[0], apertureRect); |
+} |
+ |
+} // namespace |