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

Side by Side Diff: cc/layers/nine_patch_layer_impl_unittest.cc

Issue 12967018: cc: Avoid pointless gfx::Point/Size contructors when making Rects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: RectFs as well Created 7 years, 9 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layers/nine_patch_layer.cc ('k') | cc/layers/render_surface_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdio.h> 5 #include <stdio.h>
6 6
7 #include "cc/layers/append_quads_data.h" 7 #include "cc/layers/append_quads_data.h"
8 #include "cc/layers/nine_patch_layer_impl.h" 8 #include "cc/layers/nine_patch_layer_impl.h"
9 #include "cc/quads/texture_draw_quad.h" 9 #include "cc/quads/texture_draw_quad.h"
10 #include "cc/test/fake_impl_proxy.h" 10 #include "cc/test/fake_impl_proxy.h"
(...skipping 18 matching lines...) Expand all
29 gfx::ToRoundedInt(rect_f.height())); 29 gfx::ToRoundedInt(rect_f.height()));
30 } 30 }
31 31
32 TEST(NinePatchLayerImplTest, VerifyDrawQuads) { 32 TEST(NinePatchLayerImplTest, VerifyDrawQuads) {
33 // Input is a 100x100 bitmap with a 40x50 aperture at x=20, y=30. 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 34 // The bounds of the layer are set to 400x400, so the draw quads
35 // generated should leave the border width (40) intact. 35 // generated should leave the border width (40) intact.
36 MockQuadCuller quad_culler; 36 MockQuadCuller quad_culler;
37 gfx::Size bitmap_size(100, 100); 37 gfx::Size bitmap_size(100, 100);
38 gfx::Size layer_size(400, 400); 38 gfx::Size layer_size(400, 400);
39 gfx::Rect visible_content_rect(gfx::Point(), layer_size); 39 gfx::Rect visible_content_rect(layer_size);
40 gfx::Rect aperture_rect(20, 30, 40, 50); 40 gfx::Rect aperture_rect(20, 30, 40, 50);
41 gfx::Rect scaled_aperture_non_uniform(20, 30, 340, 350); 41 gfx::Rect scaled_aperture_non_uniform(20, 30, 340, 350);
42 42
43 FakeImplProxy proxy; 43 FakeImplProxy proxy;
44 FakeLayerTreeHostImpl host_impl(&proxy); 44 FakeLayerTreeHostImpl host_impl(&proxy);
45 scoped_ptr<NinePatchLayerImpl> layer = 45 scoped_ptr<NinePatchLayerImpl> layer =
46 NinePatchLayerImpl::Create(host_impl.active_tree(), 1); 46 NinePatchLayerImpl::Create(host_impl.active_tree(), 1);
47 layer->draw_properties().visible_content_rect = visible_content_rect; 47 layer->draw_properties().visible_content_rect = visible_content_rect;
48 layer->SetBounds(layer_size); 48 layer->SetBounds(layer_size);
49 layer->SetContentBounds(layer_size); 49 layer->SetContentBounds(layer_size);
(...skipping 22 matching lines...) Expand all
72 EXPECT_TRUE(visible_content_rect.Contains(quad_rect)) << i; 72 EXPECT_TRUE(visible_content_rect.Contains(quad_rect)) << i;
73 EXPECT_TRUE(remaining.Contains(quad_rect)) << i; 73 EXPECT_TRUE(remaining.Contains(quad_rect)) << i;
74 EXPECT_EQ(transform, quad->quadTransform()); 74 EXPECT_EQ(transform, quad->quadTransform());
75 remaining.Subtract(Region(quad_rect)); 75 remaining.Subtract(Region(quad_rect));
76 } 76 }
77 EXPECT_RECT_EQ(scaled_aperture_non_uniform, remaining.bounds()); 77 EXPECT_RECT_EQ(scaled_aperture_non_uniform, remaining.bounds());
78 Region scaled_aperture_region(scaled_aperture_non_uniform); 78 Region scaled_aperture_region(scaled_aperture_non_uniform);
79 EXPECT_EQ(scaled_aperture_region, remaining); 79 EXPECT_EQ(scaled_aperture_region, remaining);
80 80
81 // Verify UV rects 81 // Verify UV rects
82 gfx::Rect bitmap_rect(gfx::Point(), bitmap_size); 82 gfx::Rect bitmap_rect(bitmap_size);
83 Region tex_remaining(bitmap_rect); 83 Region tex_remaining(bitmap_rect);
84 for (size_t i = 0; i < quads.size(); ++i) { 84 for (size_t i = 0; i < quads.size(); ++i) {
85 DrawQuad* quad = quads[i]; 85 DrawQuad* quad = quads[i];
86 const TextureDrawQuad* tex_quad = TextureDrawQuad::MaterialCast(quad); 86 const TextureDrawQuad* tex_quad = TextureDrawQuad::MaterialCast(quad);
87 gfx::RectF tex_rect = 87 gfx::RectF tex_rect =
88 gfx::BoundingRect(tex_quad->uv_top_left, tex_quad->uv_bottom_right); 88 gfx::BoundingRect(tex_quad->uv_top_left, tex_quad->uv_bottom_right);
89 tex_rect.Scale(bitmap_size.width(), bitmap_size.height()); 89 tex_rect.Scale(bitmap_size.width(), bitmap_size.height());
90 tex_remaining.Subtract(Region(ToRoundedIntRect(tex_rect))); 90 tex_remaining.Subtract(Region(ToRoundedIntRect(tex_rect)));
91 } 91 }
92 EXPECT_RECT_EQ(aperture_rect, tex_remaining.bounds()); 92 EXPECT_RECT_EQ(aperture_rect, tex_remaining.bounds());
93 Region aperture_region(aperture_rect); 93 Region aperture_region(aperture_rect);
94 EXPECT_EQ(aperture_region, tex_remaining); 94 EXPECT_EQ(aperture_region, tex_remaining);
95 } 95 }
96 96
97 TEST(NinePatchLayerImplTest, VerifyDrawQuadsForSqueezedLayer) { 97 TEST(NinePatchLayerImplTest, VerifyDrawQuadsForSqueezedLayer) {
98 // Test with a layer much smaller than the bitmap. 98 // Test with a layer much smaller than the bitmap.
99 MockQuadCuller quad_culler; 99 MockQuadCuller quad_culler;
100 gfx::Size bitmap_size(101, 101); 100 gfx::Size bitmap_size(101, 101);
101 gfx::Size layer_size(51, 51); 101 gfx::Size layer_size(51, 51);
102 gfx::Rect visible_content_rect(gfx::Point(), layer_size); 102 gfx::Rect visible_content_rect(layer_size);
103 gfx::Rect aperture_rect(20, 30, 40, 45); // rightWidth: 40, botHeight: 25 103 gfx::Rect aperture_rect(20, 30, 40, 45); // rightWidth: 40, botHeight: 25
104 104
105 FakeImplProxy proxy; 105 FakeImplProxy proxy;
106 FakeLayerTreeHostImpl host_impl(&proxy); 106 FakeLayerTreeHostImpl host_impl(&proxy);
107 scoped_ptr<NinePatchLayerImpl> layer = 107 scoped_ptr<NinePatchLayerImpl> layer =
108 NinePatchLayerImpl::Create(host_impl.active_tree(), 1); 108 NinePatchLayerImpl::Create(host_impl.active_tree(), 1);
109 layer->draw_properties().visible_content_rect = visible_content_rect; 109 layer->draw_properties().visible_content_rect = visible_content_rect;
110 layer->SetBounds(layer_size); 110 layer->SetBounds(layer_size);
111 layer->SetContentBounds(layer_size); 111 layer->SetContentBounds(layer_size);
112 layer->CreateRenderSurface(); 112 layer->CreateRenderSurface();
(...skipping 13 matching lines...) Expand all
126 gfx::Rect quad_rect = quad->rect; 126 gfx::Rect quad_rect = quad->rect;
127 127
128 EXPECT_FALSE(filled.Intersects(quad_rect)); 128 EXPECT_FALSE(filled.Intersects(quad_rect));
129 filled.Union(quad_rect); 129 filled.Union(quad_rect);
130 } 130 }
131 Region expected_full(visible_content_rect); 131 Region expected_full(visible_content_rect);
132 EXPECT_EQ(expected_full, filled); 132 EXPECT_EQ(expected_full, filled);
133 133
134 // Verify UV rects cover the corners of the bitmap and the crop is weighted 134 // Verify UV rects cover the corners of the bitmap and the crop is weighted
135 // proportionately to the relative corner sizes (for uneven apertures). 135 // proportionately to the relative corner sizes (for uneven apertures).
136 gfx::Rect bitmap_rect(gfx::Point(), bitmap_size); 136 gfx::Rect bitmap_rect(bitmap_size);
137 Region tex_remaining(bitmap_rect); 137 Region tex_remaining(bitmap_rect);
138 for (size_t i = 0; i < quads.size(); ++i) { 138 for (size_t i = 0; i < quads.size(); ++i) {
139 DrawQuad* quad = quads[i]; 139 DrawQuad* quad = quads[i];
140 const TextureDrawQuad* tex_quad = TextureDrawQuad::MaterialCast(quad); 140 const TextureDrawQuad* tex_quad = TextureDrawQuad::MaterialCast(quad);
141 gfx::RectF tex_rect = 141 gfx::RectF tex_rect =
142 gfx::BoundingRect(tex_quad->uv_top_left, tex_quad->uv_bottom_right); 142 gfx::BoundingRect(tex_quad->uv_top_left, tex_quad->uv_bottom_right);
143 tex_rect.Scale(bitmap_size.width(), bitmap_size.height()); 143 tex_rect.Scale(bitmap_size.width(), bitmap_size.height());
144 tex_remaining.Subtract(Region(ToRoundedIntRect(tex_rect))); 144 tex_remaining.Subtract(Region(ToRoundedIntRect(tex_rect)));
145 } 145 }
146 Region expected_remaining_region = Region(gfx::Rect(bitmap_size)); 146 Region expected_remaining_region = Region(gfx::Rect(bitmap_size));
147 expected_remaining_region.Subtract(gfx::Rect(0, 0, 17, 28)); 147 expected_remaining_region.Subtract(gfx::Rect(0, 0, 17, 28));
148 expected_remaining_region.Subtract(gfx::Rect(67, 0, 34, 28)); 148 expected_remaining_region.Subtract(gfx::Rect(67, 0, 34, 28));
149 expected_remaining_region.Subtract(gfx::Rect(0, 78, 17, 23)); 149 expected_remaining_region.Subtract(gfx::Rect(0, 78, 17, 23));
150 expected_remaining_region.Subtract(gfx::Rect(67, 78, 34, 23)); 150 expected_remaining_region.Subtract(gfx::Rect(67, 78, 34, 23));
151 EXPECT_EQ(expected_remaining_region, tex_remaining); 151 EXPECT_EQ(expected_remaining_region, tex_remaining);
152 } 152 }
153 153
154 } // namespace 154 } // namespace
155 } // namespace cc 155 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/nine_patch_layer.cc ('k') | cc/layers/render_surface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698