Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 | |
| 7 #include "cc/nine_patch_layer_impl.h" | |
| 8 | |
| 9 #include "cc/append_quads_data.h" | |
| 10 #include "cc/test/geometry_test_utils.h" | |
| 11 #include "cc/test/layer_test_common.h" | |
| 12 #include "cc/test/mock_quad_culler.h" | |
| 13 #include "cc/texture_draw_quad.h" | |
| 14 #include "ui/gfx/rect_conversions.h" | |
| 15 #include "testing/gmock/include/gmock/gmock.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | |
| 17 #include <public/WebTransformationMatrix.h> | |
| 18 | |
| 19 using namespace cc; | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 TEST(NinePatchLayerImplTest, verifyDrawQuads) | |
| 24 { | |
| 25 // Input is a 100x100 bitmap with a 20x20 aperture at x=20, y=20. | |
| 26 // The bounds of the layer are set to 400x400, so the draw quads | |
| 27 // generated should leave the border width (20) intact. | |
| 28 MockQuadCuller quadCuller; | |
| 29 gfx::Size bitmapSize(100, 100); | |
| 30 gfx::Size layerSize(400, 400); | |
| 31 gfx::Rect visibleContentRect(gfx::Point(), layerSize); | |
| 32 gfx::Rect apertureRect(20, 20, 20, 20); | |
|
jamesr
2012/11/05 23:10:53
would you mind making these values not equal to ea
aelias_OOO_until_Jul13
2012/11/06 01:15:00
Done.
| |
| 33 gfx::Rect scaledApertureNonUniform(20, 20, 320, 320); | |
| 34 | |
| 35 scoped_ptr<NinePatchLayerImpl> layer = NinePatchLayerImpl::create(1); | |
| 36 layer->setVisibleContentRect(visibleContentRect); | |
| 37 layer->setBounds(layerSize); | |
| 38 layer->setContentBounds(layerSize); | |
| 39 layer->createRenderSurface(); | |
| 40 layer->setRenderTarget(layer.get()); | |
| 41 layer->setLayout(bitmapSize, apertureRect); | |
| 42 layer->setResourceId(1); | |
| 43 | |
| 44 // This scale should not affect the generated quad geometry, but only | |
| 45 // the shared draw transform. | |
| 46 WebKit::WebTransformationMatrix transform; | |
| 47 transform.scale(10); | |
| 48 layer->setDrawTransform(transform); | |
| 49 | |
| 50 AppendQuadsData data; | |
| 51 layer->appendQuads(quadCuller, data); | |
| 52 | |
| 53 // Verify quad rects | |
| 54 const QuadList& quads = quadCuller.quadList(); | |
| 55 EXPECT_EQ(quads.size(), 8); | |
| 56 Region remaining(visibleContentRect); | |
| 57 for (size_t i = 0; i < quads.size(); ++i) { | |
| 58 DrawQuad* quad = quads[i]; | |
| 59 gfx::Rect quadRect = quad->quadRect(); | |
| 60 | |
| 61 EXPECT_TRUE(visibleContentRect.Contains(quadRect)) << i; | |
| 62 EXPECT_TRUE(remaining.Contains(quadRect)) << i; | |
| 63 EXPECT_EQ(quad->sharedQuadState()->quadTransform, transform) << i; | |
| 64 remaining.Subtract(Region(quadRect)); | |
| 65 } | |
| 66 EXPECT_EQ(remaining.rects().size(), 1); | |
| 67 EXPECT_RECT_EQ(remaining.bounds(), scaledApertureNonUniform); | |
| 68 | |
| 69 // Verify UV rects | |
| 70 gfx::Rect bitmapRect(gfx::Point(), bitmapSize); | |
| 71 Region texRemaining(bitmapRect); | |
| 72 for (size_t i = 0; i < quads.size(); ++i) { | |
| 73 DrawQuad* quad = quads[i]; | |
| 74 ASSERT_EQ(quad->material(), DrawQuad::TextureContent); | |
| 75 TextureDrawQuad* texQuad = static_cast<TextureDrawQuad*>(quad); | |
| 76 gfx::RectF texRect = texQuad->uvRect(); | |
| 77 texRect.Scale(bitmapSize.width(), bitmapSize.height()); | |
| 78 texRemaining.Subtract(Region(gfx::ToEnclosingRect(texRect))); | |
| 79 } | |
| 80 EXPECT_EQ(texRemaining.rects().size(), 1); | |
| 81 EXPECT_RECT_EQ(texRemaining.bounds(), apertureRect); | |
| 82 } | |
| 83 | |
| 84 } | |
| OLD | NEW |