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

Side by Side Diff: components/mus/public/cpp/surfaces/tests/surface_unittest.cc

Issue 2008193002: Change mojo geometry structs from using type converters to StructTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <utility> 8 #include <utility>
9 9
10 #include "cc/quads/debug_border_draw_quad.h" 10 #include "cc/quads/debug_border_draw_quad.h"
11 #include "cc/quads/render_pass.h" 11 #include "cc/quads/render_pass.h"
12 #include "cc/quads/solid_color_draw_quad.h" 12 #include "cc/quads/solid_color_draw_quad.h"
13 #include "cc/quads/surface_draw_quad.h" 13 #include "cc/quads/surface_draw_quad.h"
14 #include "cc/quads/texture_draw_quad.h" 14 #include "cc/quads/texture_draw_quad.h"
15 #include "cc/resources/resource_provider.h" 15 #include "cc/resources/resource_provider.h"
16 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h" 16 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h"
17 #include "gpu/command_buffer/common/mailbox.h" 17 #include "gpu/command_buffer/common/mailbox.h"
18 #include "gpu/command_buffer/common/mailbox_holder.h" 18 #include "gpu/command_buffer/common/mailbox_holder.h"
19 #include "gpu/command_buffer/common/sync_token.h" 19 #include "gpu/command_buffer/common/sync_token.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/skia/include/core/SkColor.h" 21 #include "third_party/skia/include/core/SkColor.h"
22 #include "third_party/skia/include/core/SkXfermode.h" 22 #include "third_party/skia/include/core/SkXfermode.h"
23 #include "ui/gfx/geometry/mojo/geometry_type_converters.h"
24 #include "ui/gfx/mojo/transform_type_converters.h" 23 #include "ui/gfx/mojo/transform_type_converters.h"
25 24
26 using mus::mojom::Color; 25 using mus::mojom::Color;
27 using mus::mojom::ColorPtr; 26 using mus::mojom::ColorPtr;
28 using mus::mojom::CompositorFrame; 27 using mus::mojom::CompositorFrame;
29 using mus::mojom::CompositorFramePtr; 28 using mus::mojom::CompositorFramePtr;
30 using mus::mojom::CompositorFrameMetadata; 29 using mus::mojom::CompositorFrameMetadata;
31 using mus::mojom::CompositorFrameMetadataPtr; 30 using mus::mojom::CompositorFrameMetadataPtr;
32 using mus::mojom::DebugBorderQuadState; 31 using mus::mojom::DebugBorderQuadState;
33 using mus::mojom::DebugBorderQuadStatePtr; 32 using mus::mojom::DebugBorderQuadStatePtr;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 rect, 94 rect,
96 opaque_rect, 95 opaque_rect,
97 visible_rect, 96 visible_rect,
98 needs_blending, 97 needs_blending,
99 arbitrary_color, 98 arbitrary_color,
100 force_anti_aliasing_off); 99 force_anti_aliasing_off);
101 100
102 QuadPtr mus_quad = Quad::From<cc::DrawQuad>(*color_quad); 101 QuadPtr mus_quad = Quad::From<cc::DrawQuad>(*color_quad);
103 ASSERT_FALSE(mus_quad.is_null()); 102 ASSERT_FALSE(mus_quad.is_null());
104 EXPECT_EQ(mus::mojom::Material::SOLID_COLOR, mus_quad->material); 103 EXPECT_EQ(mus::mojom::Material::SOLID_COLOR, mus_quad->material);
105 EXPECT_TRUE(Rect::From(rect).Equals(mus_quad->rect)); 104 EXPECT_EQ(rect, mus_quad->rect);
106 EXPECT_TRUE(Rect::From(opaque_rect).Equals(mus_quad->opaque_rect)); 105 EXPECT_EQ(opaque_rect, mus_quad->opaque_rect);
107 EXPECT_TRUE(Rect::From(visible_rect).Equals(mus_quad->visible_rect)); 106 EXPECT_EQ(visible_rect, mus_quad->visible_rect);
108 EXPECT_EQ(needs_blending, mus_quad->needs_blending); 107 EXPECT_EQ(needs_blending, mus_quad->needs_blending);
109 ASSERT_TRUE(mus_quad->solid_color_quad_state); 108 ASSERT_TRUE(mus_quad->solid_color_quad_state);
110 SolidColorQuadStatePtr& mus_color_state = mus_quad->solid_color_quad_state; 109 SolidColorQuadStatePtr& mus_color_state = mus_quad->solid_color_quad_state;
111 EXPECT_TRUE(Color::From(arbitrary_color).Equals(mus_color_state->color)); 110 EXPECT_TRUE(Color::From(arbitrary_color).Equals(mus_color_state->color));
112 EXPECT_EQ(force_anti_aliasing_off, mus_color_state->force_anti_aliasing_off); 111 EXPECT_EQ(force_anti_aliasing_off, mus_color_state->force_anti_aliasing_off);
113 } 112 }
114 113
115 TEST_F(SurfaceLibQuadTest, SurfaceQuad) { 114 TEST_F(SurfaceLibQuadTest, SurfaceQuad) {
116 cc::SurfaceDrawQuad* surface_quad = 115 cc::SurfaceDrawQuad* surface_quad =
117 pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); 116 pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>();
(...skipping 27 matching lines...) Expand all
145 vertex_opacity, y_flipped, nearest_neighbor, 144 vertex_opacity, y_flipped, nearest_neighbor,
146 secure_output_only); 145 secure_output_only);
147 146
148 QuadPtr mus_quad = Quad::From<cc::DrawQuad>(*texture_quad); 147 QuadPtr mus_quad = Quad::From<cc::DrawQuad>(*texture_quad);
149 ASSERT_FALSE(mus_quad.is_null()); 148 ASSERT_FALSE(mus_quad.is_null());
150 EXPECT_EQ(mus::mojom::Material::TEXTURE_CONTENT, mus_quad->material); 149 EXPECT_EQ(mus::mojom::Material::TEXTURE_CONTENT, mus_quad->material);
151 ASSERT_TRUE(mus_quad->texture_quad_state); 150 ASSERT_TRUE(mus_quad->texture_quad_state);
152 TextureQuadStatePtr& mus_texture_state = mus_quad->texture_quad_state; 151 TextureQuadStatePtr& mus_texture_state = mus_quad->texture_quad_state;
153 EXPECT_EQ(resource_id, mus_texture_state->resource_id); 152 EXPECT_EQ(resource_id, mus_texture_state->resource_id);
154 EXPECT_EQ(premultiplied_alpha, mus_texture_state->premultiplied_alpha); 153 EXPECT_EQ(premultiplied_alpha, mus_texture_state->premultiplied_alpha);
155 EXPECT_TRUE(PointF::From(uv_top_left).Equals(mus_texture_state->uv_top_left)); 154 EXPECT_EQ(uv_top_left, mus_texture_state->uv_top_left);
156 EXPECT_TRUE( 155 EXPECT_EQ(uv_bottom_right, mus_texture_state->uv_bottom_right);
157 PointF::From(uv_bottom_right).Equals(mus_texture_state->uv_bottom_right));
158 EXPECT_TRUE(Color::From(background_color) 156 EXPECT_TRUE(Color::From(background_color)
159 .Equals(mus_texture_state->background_color)); 157 .Equals(mus_texture_state->background_color));
160 for (size_t i = 0; i < 4; ++i) { 158 for (size_t i = 0; i < 4; ++i) {
161 EXPECT_EQ(vertex_opacity[i], mus_texture_state->vertex_opacity[i]) << i; 159 EXPECT_EQ(vertex_opacity[i], mus_texture_state->vertex_opacity[i]) << i;
162 } 160 }
163 EXPECT_EQ(y_flipped, mus_texture_state->y_flipped); 161 EXPECT_EQ(y_flipped, mus_texture_state->y_flipped);
164 EXPECT_EQ(secure_output_only, mus_texture_state->secure_output_only); 162 EXPECT_EQ(secure_output_only, mus_texture_state->secure_output_only);
165 } 163 }
166 164
167 TEST_F(SurfaceLibQuadTest, TextureQuadEmptyVertexOpacity) { 165 TEST_F(SurfaceLibQuadTest, TextureQuadEmptyVertexOpacity) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); 212 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create();
215 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); 213 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
216 sqs->SetAll(quad_to_target_transform, quad_layer_bounds, 214 sqs->SetAll(quad_to_target_transform, quad_layer_bounds,
217 visible_quad_layer_rect, clip_rect, is_clipped, opacity, 215 visible_quad_layer_rect, clip_rect, is_clipped, opacity,
218 blend_mode, sorting_context_id); 216 blend_mode, sorting_context_id);
219 217
220 SharedQuadStatePtr mus_sqs = SharedQuadState::From(*sqs); 218 SharedQuadStatePtr mus_sqs = SharedQuadState::From(*sqs);
221 ASSERT_FALSE(mus_sqs.is_null()); 219 ASSERT_FALSE(mus_sqs.is_null());
222 EXPECT_TRUE(Transform::From(quad_to_target_transform) 220 EXPECT_TRUE(Transform::From(quad_to_target_transform)
223 .Equals(mus_sqs->quad_to_target_transform)); 221 .Equals(mus_sqs->quad_to_target_transform));
224 EXPECT_TRUE(Size::From(quad_layer_bounds).Equals(mus_sqs->quad_layer_bounds)); 222 EXPECT_EQ(quad_layer_bounds, mus_sqs->quad_layer_bounds);
225 EXPECT_TRUE(Rect::From(visible_quad_layer_rect) 223 EXPECT_EQ(visible_quad_layer_rect, mus_sqs->visible_quad_layer_rect);
226 .Equals(mus_sqs->visible_quad_layer_rect)); 224 EXPECT_EQ(clip_rect, mus_sqs->clip_rect);
227 EXPECT_TRUE(Rect::From(clip_rect).Equals(mus_sqs->clip_rect));
228 EXPECT_EQ(is_clipped, mus_sqs->is_clipped); 225 EXPECT_EQ(is_clipped, mus_sqs->is_clipped);
229 EXPECT_EQ(opacity, mus_sqs->opacity); 226 EXPECT_EQ(opacity, mus_sqs->opacity);
230 EXPECT_EQ(sorting_context_id, mus_sqs->sorting_context_id); 227 EXPECT_EQ(sorting_context_id, mus_sqs->sorting_context_id);
231 } 228 }
232 229
233 TEST(SurfaceLibTest, RenderPass) { 230 TEST(SurfaceLibTest, RenderPass) {
234 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); 231 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create();
235 cc::RenderPassId pass_id(1, 6); 232 cc::RenderPassId pass_id(1, 6);
236 gfx::Rect output_rect(4, 9, 13, 71); 233 gfx::Rect output_rect(4, 9, 13, 71);
237 gfx::Rect damage_rect(9, 17, 41, 45); 234 gfx::Rect damage_rect(9, 17, 41, 45);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 bool secure_output_only = false; 291 bool secure_output_only = false;
295 texture_quad->SetAll(sqs, rect, opaque_rect, visible_rect, needs_blending, 292 texture_quad->SetAll(sqs, rect, opaque_rect, visible_rect, needs_blending,
296 resource_id, gfx::Size(), premultiplied_alpha, 293 resource_id, gfx::Size(), premultiplied_alpha,
297 uv_top_left, uv_bottom_right, background_color, 294 uv_top_left, uv_bottom_right, background_color,
298 vertex_opacity, y_flipped, nearest_neighbor, 295 vertex_opacity, y_flipped, nearest_neighbor,
299 secure_output_only); 296 secure_output_only);
300 297
301 PassPtr mus_pass = Pass::From(*pass); 298 PassPtr mus_pass = Pass::From(*pass);
302 ASSERT_FALSE(mus_pass.is_null()); 299 ASSERT_FALSE(mus_pass.is_null());
303 EXPECT_EQ(6u, mus_pass->id.index); 300 EXPECT_EQ(6u, mus_pass->id.index);
304 EXPECT_TRUE(Rect::From(output_rect).Equals(mus_pass->output_rect)); 301 EXPECT_EQ(output_rect, mus_pass->output_rect);
305 EXPECT_TRUE(Rect::From(damage_rect).Equals(mus_pass->damage_rect)); 302 EXPECT_EQ(damage_rect, mus_pass->damage_rect);
306 EXPECT_TRUE(Transform::From(transform_to_root_target) 303 EXPECT_TRUE(Transform::From(transform_to_root_target)
307 .Equals(mus_pass->transform_to_root_target)); 304 .Equals(mus_pass->transform_to_root_target));
308 EXPECT_EQ(has_transparent_background, mus_pass->has_transparent_background); 305 EXPECT_EQ(has_transparent_background, mus_pass->has_transparent_background);
309 ASSERT_EQ(1u, mus_pass->shared_quad_states.size()); 306 ASSERT_EQ(1u, mus_pass->shared_quad_states.size());
310 ASSERT_EQ(3u, mus_pass->quads.size()); 307 ASSERT_EQ(3u, mus_pass->quads.size());
311 EXPECT_EQ(0u, mus_pass->quads[0]->shared_quad_state_index); 308 EXPECT_EQ(0u, mus_pass->quads[0]->shared_quad_state_index);
312 309
313 std::unique_ptr<cc::RenderPass> round_trip_pass = 310 std::unique_ptr<cc::RenderPass> round_trip_pass =
314 mus_pass.To<std::unique_ptr<cc::RenderPass>>(); 311 mus_pass.To<std::unique_ptr<cc::RenderPass>>();
315 EXPECT_EQ(pass_id, round_trip_pass->id); 312 EXPECT_EQ(pass_id, round_trip_pass->id);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 resource.format = format; 381 resource.format = format;
385 resource.filter = filter; 382 resource.filter = filter;
386 resource.size = size; 383 resource.size = size;
387 resource.mailbox_holder = mailbox_holder; 384 resource.mailbox_holder = mailbox_holder;
388 resource.is_software = is_software; 385 resource.is_software = is_software;
389 386
390 TransferableResourcePtr mus_resource = TransferableResource::From(resource); 387 TransferableResourcePtr mus_resource = TransferableResource::From(resource);
391 EXPECT_EQ(id, mus_resource->id); 388 EXPECT_EQ(id, mus_resource->id);
392 EXPECT_EQ(static_cast<ResourceFormat>(format), mus_resource->format); 389 EXPECT_EQ(static_cast<ResourceFormat>(format), mus_resource->format);
393 EXPECT_EQ(filter, mus_resource->filter); 390 EXPECT_EQ(filter, mus_resource->filter);
394 EXPECT_TRUE(Size::From(size).Equals(mus_resource->size)); 391 EXPECT_EQ(size, mus_resource->size);
395 EXPECT_EQ(is_software, mus_resource->is_software); 392 EXPECT_EQ(is_software, mus_resource->is_software);
396 393
397 cc::TransferableResource round_trip_resource = 394 cc::TransferableResource round_trip_resource =
398 mus_resource.To<cc::TransferableResource>(); 395 mus_resource.To<cc::TransferableResource>();
399 EXPECT_EQ(id, round_trip_resource.id); 396 EXPECT_EQ(id, round_trip_resource.id);
400 EXPECT_EQ(format, round_trip_resource.format); 397 EXPECT_EQ(format, round_trip_resource.format);
401 EXPECT_EQ(filter, round_trip_resource.filter); 398 EXPECT_EQ(filter, round_trip_resource.filter);
402 EXPECT_EQ(size, round_trip_resource.size); 399 EXPECT_EQ(size, round_trip_resource.size);
403 EXPECT_EQ(mailbox_holder.mailbox, round_trip_resource.mailbox_holder.mailbox); 400 EXPECT_EQ(mailbox_holder.mailbox, round_trip_resource.mailbox_holder.mailbox);
404 EXPECT_EQ(mailbox_holder.texture_target, 401 EXPECT_EQ(mailbox_holder.texture_target,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 rect, 441 rect,
445 opaque_rect, 442 opaque_rect,
446 visible_rect, 443 visible_rect,
447 needs_blending, 444 needs_blending,
448 arbitrary_color, 445 arbitrary_color,
449 width); 446 width);
450 447
451 QuadPtr mus_quad = Quad::From<cc::DrawQuad>(*debug_border_quad); 448 QuadPtr mus_quad = Quad::From<cc::DrawQuad>(*debug_border_quad);
452 ASSERT_FALSE(mus_quad.is_null()); 449 ASSERT_FALSE(mus_quad.is_null());
453 EXPECT_EQ(mus::mojom::Material::DEBUG_BORDER, mus_quad->material); 450 EXPECT_EQ(mus::mojom::Material::DEBUG_BORDER, mus_quad->material);
454 EXPECT_TRUE(Rect::From(rect).Equals(mus_quad->rect)); 451 EXPECT_EQ(rect, mus_quad->rect);
455 EXPECT_TRUE(Rect::From(opaque_rect).Equals(mus_quad->opaque_rect)); 452 EXPECT_EQ(opaque_rect, mus_quad->opaque_rect);
456 EXPECT_TRUE(Rect::From(visible_rect).Equals(mus_quad->visible_rect)); 453 EXPECT_EQ(visible_rect, mus_quad->visible_rect);
457 EXPECT_EQ(needs_blending, mus_quad->needs_blending); 454 EXPECT_EQ(needs_blending, mus_quad->needs_blending);
458 ASSERT_TRUE(mus_quad->debug_border_quad_state); 455 ASSERT_TRUE(mus_quad->debug_border_quad_state);
459 DebugBorderQuadStatePtr& mus_debug_border_state = 456 DebugBorderQuadStatePtr& mus_debug_border_state =
460 mus_quad->debug_border_quad_state; 457 mus_quad->debug_border_quad_state;
461 EXPECT_TRUE( 458 EXPECT_TRUE(
462 Color::From(arbitrary_color).Equals(mus_debug_border_state->color)); 459 Color::From(arbitrary_color).Equals(mus_debug_border_state->color));
463 EXPECT_EQ(width, mus_debug_border_state->width); 460 EXPECT_EQ(width, mus_debug_border_state->width);
464 } 461 }
465 462
466 } // namespace 463 } // namespace
467 } // namespace mojo 464 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698