Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2391)

Unified Diff: cc/nine_patch_layer_impl_unittest.cc

Issue 11304020: cc: Nine patch layer. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix DCHECK failures and rebase to 166129 Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/nine_patch_layer_impl.cc ('k') | cc/nine_patch_layer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/nine_patch_layer_impl_unittest.cc
diff --git a/cc/nine_patch_layer_impl_unittest.cc b/cc/nine_patch_layer_impl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..55f0c105c5e4d8b62e0155e0f6d05bc6cc5d86ff
--- /dev/null
+++ b/cc/nine_patch_layer_impl_unittest.cc
@@ -0,0 +1,94 @@
+// 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 "cc/nine_patch_layer_impl.h"
+
+#include "cc/append_quads_data.h"
+#include "cc/single_thread_proxy.h"
+#include "cc/test/geometry_test_utils.h"
+#include "cc/test/layer_test_common.h"
+#include "cc/test/mock_quad_culler.h"
+#include "cc/texture_draw_quad.h"
+#include "ui/gfx/rect_conversions.h"
+#include "ui/gfx/safe_integer_conversions.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include <public/WebTransformationMatrix.h>
+
+using namespace cc;
+
+namespace {
+
+gfx::Rect ToRoundedIntRect(gfx::RectF rect_f) {
+ return gfx::Rect(gfx::ToRoundedInt(rect_f.x()), gfx::ToRoundedInt(rect_f.y()), gfx::ToRoundedInt(rect_f.width()), gfx::ToRoundedInt(rect_f.height()));
+}
+
+TEST(NinePatchLayerImplTest, verifyDrawQuads)
+{
+ DebugScopedSetImplThread implThread;
+
+ // Input is a 100x100 bitmap with a 40x50 aperture at x=20, y=30.
+ // The bounds of the layer are set to 400x400, so the draw quads
+ // generated should leave the border width (40) intact.
+ MockQuadCuller quadCuller;
+ gfx::Size bitmapSize(100, 100);
+ gfx::Size layerSize(400, 400);
+ gfx::Rect visibleContentRect(gfx::Point(), layerSize);
+ gfx::Rect apertureRect(20, 30, 40, 50);
+ gfx::Rect scaledApertureNonUniform(20, 30, 340, 350);
+
+ scoped_ptr<NinePatchLayerImpl> layer = NinePatchLayerImpl::create(1);
+ layer->setVisibleContentRect(visibleContentRect);
+ layer->setBounds(layerSize);
+ layer->setContentBounds(layerSize);
+ layer->createRenderSurface();
+ layer->setRenderTarget(layer.get());
+ layer->setLayout(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);
+
+ AppendQuadsData data;
+ layer->appendQuads(quadCuller, data);
+
+ // Verify quad rects
+ const QuadList& quads = quadCuller.quadList();
+ EXPECT_EQ(quads.size(), 8);
+ Region remaining(visibleContentRect);
+ for (size_t i = 0; i < quads.size(); ++i) {
+ DrawQuad* quad = quads[i];
+ gfx::Rect quadRect = quad->quadRect();
+
+ EXPECT_TRUE(visibleContentRect.Contains(quadRect)) << i;
+ EXPECT_TRUE(remaining.Contains(quadRect)) << i;
+ EXPECT_EQ(quad->sharedQuadState()->quadTransform, transform) << i;
+ remaining.Subtract(Region(quadRect));
+ }
+ EXPECT_RECT_EQ(remaining.bounds(), scaledApertureNonUniform);
+ Region scaledApertureRegion(scaledApertureNonUniform);
+ EXPECT_EQ(remaining, scaledApertureRegion);
+
+ // Verify UV rects
+ gfx::Rect bitmapRect(gfx::Point(), bitmapSize);
+ Region texRemaining(bitmapRect);
+ for (size_t i = 0; i < quads.size(); ++i) {
+ DrawQuad* quad = quads[i];
+ ASSERT_EQ(quad->material(), DrawQuad::TextureContent);
+ TextureDrawQuad* texQuad = static_cast<TextureDrawQuad*>(quad);
+ gfx::RectF texRect = texQuad->uvRect();
+ texRect.Scale(bitmapSize.width(), bitmapSize.height());
+ texRemaining.Subtract(Region(ToRoundedIntRect(texRect)));
+ }
+ EXPECT_RECT_EQ(texRemaining.bounds(), apertureRect);
+ Region apertureRegion(apertureRect);
+ EXPECT_EQ(texRemaining, apertureRegion);
+}
+
+}
« no previous file with comments | « cc/nine_patch_layer_impl.cc ('k') | cc/nine_patch_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698