1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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);
}
}
|