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/single_thread_proxy.h" |
| 11 #include "cc/test/geometry_test_utils.h" |
| 12 #include "cc/test/layer_test_common.h" |
| 13 #include "cc/test/mock_quad_culler.h" |
| 14 #include "cc/texture_draw_quad.h" |
| 15 #include "ui/gfx/rect_conversions.h" |
| 16 #include "ui/gfx/safe_integer_conversions.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include <public/WebTransformationMatrix.h> |
| 20 |
| 21 using namespace cc; |
| 22 |
| 23 namespace { |
| 24 |
| 25 gfx::Rect ToRoundedIntRect(gfx::RectF rect_f) { |
| 26 return gfx::Rect(gfx::ToRoundedInt(rect_f.x()), gfx::ToRoundedInt(rect_f.y()
), gfx::ToRoundedInt(rect_f.width()), gfx::ToRoundedInt(rect_f.height())); |
| 27 } |
| 28 |
| 29 TEST(NinePatchLayerImplTest, verifyDrawQuads) |
| 30 { |
| 31 DebugScopedSetImplThread implThread; |
| 32 |
| 33 // Input is a 100x100 bitmap with a 40x50 aperture at x=20, y=30. |
| 34 // The bounds of the layer are set to 400x400, so the draw quads |
| 35 // generated should leave the border width (40) intact. |
| 36 MockQuadCuller quadCuller; |
| 37 gfx::Size bitmapSize(100, 100); |
| 38 gfx::Size layerSize(400, 400); |
| 39 gfx::Rect visibleContentRect(gfx::Point(), layerSize); |
| 40 gfx::Rect apertureRect(20, 30, 40, 50); |
| 41 gfx::Rect scaledApertureNonUniform(20, 30, 340, 350); |
| 42 |
| 43 scoped_ptr<NinePatchLayerImpl> layer = NinePatchLayerImpl::create(1); |
| 44 layer->setVisibleContentRect(visibleContentRect); |
| 45 layer->setBounds(layerSize); |
| 46 layer->setContentBounds(layerSize); |
| 47 layer->createRenderSurface(); |
| 48 layer->setRenderTarget(layer.get()); |
| 49 layer->setLayout(bitmapSize, apertureRect); |
| 50 layer->setResourceId(1); |
| 51 |
| 52 // This scale should not affect the generated quad geometry, but only |
| 53 // the shared draw transform. |
| 54 WebKit::WebTransformationMatrix transform; |
| 55 transform.scale(10); |
| 56 layer->setDrawTransform(transform); |
| 57 |
| 58 AppendQuadsData data; |
| 59 layer->appendQuads(quadCuller, data); |
| 60 |
| 61 // Verify quad rects |
| 62 const QuadList& quads = quadCuller.quadList(); |
| 63 EXPECT_EQ(quads.size(), 8); |
| 64 Region remaining(visibleContentRect); |
| 65 for (size_t i = 0; i < quads.size(); ++i) { |
| 66 DrawQuad* quad = quads[i]; |
| 67 gfx::Rect quadRect = quad->quadRect(); |
| 68 |
| 69 EXPECT_TRUE(visibleContentRect.Contains(quadRect)) << i; |
| 70 EXPECT_TRUE(remaining.Contains(quadRect)) << i; |
| 71 EXPECT_EQ(quad->sharedQuadState()->quadTransform, transform) << i; |
| 72 remaining.Subtract(Region(quadRect)); |
| 73 } |
| 74 EXPECT_RECT_EQ(remaining.bounds(), scaledApertureNonUniform); |
| 75 Region scaledApertureRegion(scaledApertureNonUniform); |
| 76 EXPECT_EQ(remaining, scaledApertureRegion); |
| 77 |
| 78 // Verify UV rects |
| 79 gfx::Rect bitmapRect(gfx::Point(), bitmapSize); |
| 80 Region texRemaining(bitmapRect); |
| 81 for (size_t i = 0; i < quads.size(); ++i) { |
| 82 DrawQuad* quad = quads[i]; |
| 83 ASSERT_EQ(quad->material(), DrawQuad::TextureContent); |
| 84 TextureDrawQuad* texQuad = static_cast<TextureDrawQuad*>(quad); |
| 85 gfx::RectF texRect = texQuad->uvRect(); |
| 86 texRect.Scale(bitmapSize.width(), bitmapSize.height()); |
| 87 texRemaining.Subtract(Region(ToRoundedIntRect(texRect))); |
| 88 } |
| 89 EXPECT_RECT_EQ(texRemaining.bounds(), apertureRect); |
| 90 Region apertureRegion(apertureRect); |
| 91 EXPECT_EQ(texRemaining, apertureRegion); |
| 92 } |
| 93 |
| 94 } |
OLD | NEW |