| OLD | NEW |
| 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 | 23 |
| 24 using cc::mojom::Color; | |
| 25 using cc::mojom::ColorPtr; | |
| 26 using cc::mojom::DebugBorderQuadState; | 24 using cc::mojom::DebugBorderQuadState; |
| 27 using cc::mojom::DebugBorderQuadStatePtr; | 25 using cc::mojom::DebugBorderQuadStatePtr; |
| 28 using cc::mojom::DrawQuad; | 26 using cc::mojom::DrawQuad; |
| 29 using cc::mojom::DrawQuadPtr; | 27 using cc::mojom::DrawQuadPtr; |
| 30 using cc::mojom::RenderPass; | 28 using cc::mojom::RenderPass; |
| 31 using cc::mojom::RenderPassPtr; | 29 using cc::mojom::RenderPassPtr; |
| 32 using cc::mojom::RenderPassQuadState; | 30 using cc::mojom::RenderPassQuadState; |
| 33 using cc::mojom::RenderPassQuadStatePtr; | 31 using cc::mojom::RenderPassQuadStatePtr; |
| 34 using cc::mojom::SolidColorQuadState; | 32 using cc::mojom::SolidColorQuadState; |
| 35 using cc::mojom::SolidColorQuadStatePtr; | 33 using cc::mojom::SolidColorQuadStatePtr; |
| 36 using cc::mojom::SurfaceQuadState; | 34 using cc::mojom::SurfaceQuadState; |
| 37 using cc::mojom::SurfaceQuadStatePtr; | 35 using cc::mojom::SurfaceQuadStatePtr; |
| 38 using cc::mojom::TextureQuadState; | 36 using cc::mojom::TextureQuadState; |
| 39 using cc::mojom::TextureQuadStatePtr; | 37 using cc::mojom::TextureQuadStatePtr; |
| 40 using cc::mojom::TileQuadState; | 38 using cc::mojom::TileQuadState; |
| 41 using cc::mojom::TileQuadStatePtr; | 39 using cc::mojom::TileQuadStatePtr; |
| 42 using cc::mojom::YUVColorSpace; | 40 using cc::mojom::YUVColorSpace; |
| 43 using cc::mojom::YUVVideoQuadState; | 41 using cc::mojom::YUVVideoQuadState; |
| 44 using cc::mojom::YUVVideoQuadStatePtr; | 42 using cc::mojom::YUVVideoQuadStatePtr; |
| 45 using mus::mojom::CompositorFrame; | 43 using mus::mojom::CompositorFrame; |
| 46 using mus::mojom::CompositorFramePtr; | 44 using mus::mojom::CompositorFramePtr; |
| 47 | 45 |
| 48 namespace mojo { | 46 namespace mojo { |
| 49 namespace { | 47 namespace { |
| 50 | 48 |
| 51 | 49 |
| 52 TEST(SurfaceLibTest, Color) { | |
| 53 SkColor arbitrary_color = SK_ColorMAGENTA; | |
| 54 SkColor round_trip = Color::From(arbitrary_color).To<SkColor>(); | |
| 55 EXPECT_EQ(arbitrary_color, round_trip); | |
| 56 } | |
| 57 | |
| 58 class SurfaceLibQuadTest : public testing::Test { | 50 class SurfaceLibQuadTest : public testing::Test { |
| 59 public: | 51 public: |
| 60 SurfaceLibQuadTest() | 52 SurfaceLibQuadTest() |
| 61 : rect(5, 7, 13, 19), | 53 : rect(5, 7, 13, 19), |
| 62 opaque_rect(rect), | 54 opaque_rect(rect), |
| 63 visible_rect(9, 11, 5, 7), | 55 visible_rect(9, 11, 5, 7), |
| 64 needs_blending(false) { | 56 needs_blending(false) { |
| 65 pass = cc::RenderPass::Create(); | 57 pass = cc::RenderPass::Create(); |
| 66 sqs = pass->CreateAndAppendSharedQuadState(); | 58 sqs = pass->CreateAndAppendSharedQuadState(); |
| 67 } | 59 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 90 | 82 |
| 91 DrawQuadPtr mus_quad = DrawQuad::From<cc::DrawQuad>(*color_quad); | 83 DrawQuadPtr mus_quad = DrawQuad::From<cc::DrawQuad>(*color_quad); |
| 92 ASSERT_FALSE(mus_quad.is_null()); | 84 ASSERT_FALSE(mus_quad.is_null()); |
| 93 EXPECT_EQ(cc::mojom::Material::SOLID_COLOR, mus_quad->material); | 85 EXPECT_EQ(cc::mojom::Material::SOLID_COLOR, mus_quad->material); |
| 94 EXPECT_EQ(rect, mus_quad->rect); | 86 EXPECT_EQ(rect, mus_quad->rect); |
| 95 EXPECT_EQ(opaque_rect, mus_quad->opaque_rect); | 87 EXPECT_EQ(opaque_rect, mus_quad->opaque_rect); |
| 96 EXPECT_EQ(visible_rect, mus_quad->visible_rect); | 88 EXPECT_EQ(visible_rect, mus_quad->visible_rect); |
| 97 EXPECT_EQ(needs_blending, mus_quad->needs_blending); | 89 EXPECT_EQ(needs_blending, mus_quad->needs_blending); |
| 98 ASSERT_TRUE(mus_quad->solid_color_quad_state); | 90 ASSERT_TRUE(mus_quad->solid_color_quad_state); |
| 99 SolidColorQuadStatePtr& mus_color_state = mus_quad->solid_color_quad_state; | 91 SolidColorQuadStatePtr& mus_color_state = mus_quad->solid_color_quad_state; |
| 100 EXPECT_TRUE(Color::From(arbitrary_color).Equals(mus_color_state->color)); | 92 EXPECT_EQ(arbitrary_color, mus_color_state->color); |
| 101 EXPECT_EQ(force_anti_aliasing_off, mus_color_state->force_anti_aliasing_off); | 93 EXPECT_EQ(force_anti_aliasing_off, mus_color_state->force_anti_aliasing_off); |
| 102 } | 94 } |
| 103 | 95 |
| 104 TEST_F(SurfaceLibQuadTest, SurfaceQuad) { | 96 TEST_F(SurfaceLibQuadTest, SurfaceQuad) { |
| 105 cc::SurfaceDrawQuad* surface_quad = | 97 cc::SurfaceDrawQuad* surface_quad = |
| 106 pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 98 pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
| 107 cc::SurfaceId arbitrary_id(0, 5, 0); | 99 cc::SurfaceId arbitrary_id(0, 5, 0); |
| 108 surface_quad->SetAll( | 100 surface_quad->SetAll( |
| 109 sqs, rect, opaque_rect, visible_rect, needs_blending, arbitrary_id); | 101 sqs, rect, opaque_rect, visible_rect, needs_blending, arbitrary_id); |
| 110 | 102 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 136 | 128 |
| 137 DrawQuadPtr mus_quad = DrawQuad::From<cc::DrawQuad>(*texture_quad); | 129 DrawQuadPtr mus_quad = DrawQuad::From<cc::DrawQuad>(*texture_quad); |
| 138 ASSERT_FALSE(mus_quad.is_null()); | 130 ASSERT_FALSE(mus_quad.is_null()); |
| 139 EXPECT_EQ(cc::mojom::Material::TEXTURE_CONTENT, mus_quad->material); | 131 EXPECT_EQ(cc::mojom::Material::TEXTURE_CONTENT, mus_quad->material); |
| 140 ASSERT_TRUE(mus_quad->texture_quad_state); | 132 ASSERT_TRUE(mus_quad->texture_quad_state); |
| 141 TextureQuadStatePtr& mus_texture_state = mus_quad->texture_quad_state; | 133 TextureQuadStatePtr& mus_texture_state = mus_quad->texture_quad_state; |
| 142 EXPECT_EQ(resource_id, mus_texture_state->resource_id); | 134 EXPECT_EQ(resource_id, mus_texture_state->resource_id); |
| 143 EXPECT_EQ(premultiplied_alpha, mus_texture_state->premultiplied_alpha); | 135 EXPECT_EQ(premultiplied_alpha, mus_texture_state->premultiplied_alpha); |
| 144 EXPECT_EQ(uv_top_left, mus_texture_state->uv_top_left); | 136 EXPECT_EQ(uv_top_left, mus_texture_state->uv_top_left); |
| 145 EXPECT_EQ(uv_bottom_right, mus_texture_state->uv_bottom_right); | 137 EXPECT_EQ(uv_bottom_right, mus_texture_state->uv_bottom_right); |
| 146 EXPECT_TRUE(Color::From(background_color) | 138 EXPECT_EQ(background_color, mus_texture_state->background_color); |
| 147 .Equals(mus_texture_state->background_color)); | |
| 148 for (size_t i = 0; i < 4; ++i) { | 139 for (size_t i = 0; i < 4; ++i) { |
| 149 EXPECT_EQ(vertex_opacity[i], mus_texture_state->vertex_opacity[i]) << i; | 140 EXPECT_EQ(vertex_opacity[i], mus_texture_state->vertex_opacity[i]) << i; |
| 150 } | 141 } |
| 151 EXPECT_EQ(y_flipped, mus_texture_state->y_flipped); | 142 EXPECT_EQ(y_flipped, mus_texture_state->y_flipped); |
| 152 EXPECT_EQ(secure_output_only, mus_texture_state->secure_output_only); | 143 EXPECT_EQ(secure_output_only, mus_texture_state->secure_output_only); |
| 153 } | 144 } |
| 154 | 145 |
| 155 TEST_F(SurfaceLibQuadTest, TextureQuadEmptyVertexOpacity) { | 146 TEST_F(SurfaceLibQuadTest, TextureQuadEmptyVertexOpacity) { |
| 156 DrawQuadPtr mus_texture_quad = DrawQuad::New(); | 147 DrawQuadPtr mus_texture_quad = DrawQuad::New(); |
| 157 mus_texture_quad->material = cc::mojom::Material::TEXTURE_CONTENT; | 148 mus_texture_quad->material = cc::mojom::Material::TEXTURE_CONTENT; |
| 158 TextureQuadStatePtr mus_texture_state = TextureQuadState::New(); | 149 TextureQuadStatePtr mus_texture_state = TextureQuadState::New(); |
| 159 mus_texture_state->background_color = Color::New(); | |
| 160 mus_texture_quad->texture_quad_state = std::move(mus_texture_state); | 150 mus_texture_quad->texture_quad_state = std::move(mus_texture_state); |
| 161 RenderPassPtr mus_pass = RenderPass::New(); | 151 RenderPassPtr mus_pass = RenderPass::New(); |
| 162 mus_pass->id.layer_id = 1; | 152 mus_pass->id.layer_id = 1; |
| 163 mus_pass->id.index = 1u; | 153 mus_pass->id.index = 1u; |
| 164 mus_pass->quads.push_back(std::move(mus_texture_quad)); | 154 mus_pass->quads.push_back(std::move(mus_texture_quad)); |
| 165 mus_pass->shared_quad_states.push_back(cc::SharedQuadState()); | 155 mus_pass->shared_quad_states.push_back(cc::SharedQuadState()); |
| 166 | 156 |
| 167 std::unique_ptr<cc::RenderPass> pass = | 157 std::unique_ptr<cc::RenderPass> pass = |
| 168 mus_pass.To<std::unique_ptr<cc::RenderPass>>(); | 158 mus_pass.To<std::unique_ptr<cc::RenderPass>>(); |
| 169 | 159 |
| 170 EXPECT_FALSE(pass); | 160 EXPECT_FALSE(pass); |
| 171 } | 161 } |
| 172 | 162 |
| 173 TEST_F(SurfaceLibQuadTest, TextureQuadEmptyBackgroundColor) { | |
| 174 DrawQuadPtr mus_texture_quad = DrawQuad::New(); | |
| 175 mus_texture_quad->material = cc::mojom::Material::TEXTURE_CONTENT; | |
| 176 TextureQuadStatePtr mus_texture_state = TextureQuadState::New(); | |
| 177 mus_texture_state->vertex_opacity = mojo::Array<float>::New(4); | |
| 178 mus_texture_quad->texture_quad_state = std::move(mus_texture_state); | |
| 179 RenderPassPtr mus_pass = RenderPass::New(); | |
| 180 mus_pass->id.layer_id = 1; | |
| 181 mus_pass->id.index = 1u; | |
| 182 mus_pass->quads.push_back(std::move(mus_texture_quad)); | |
| 183 mus_pass->shared_quad_states.push_back(cc::SharedQuadState()); | |
| 184 | |
| 185 std::unique_ptr<cc::RenderPass> pass = | |
| 186 mus_pass.To<std::unique_ptr<cc::RenderPass>>(); | |
| 187 EXPECT_FALSE(pass); | |
| 188 } | |
| 189 | |
| 190 TEST(SurfaceLibTest, RenderPass) { | 163 TEST(SurfaceLibTest, RenderPass) { |
| 191 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); | 164 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); |
| 192 cc::RenderPassId pass_id(1, 6); | 165 cc::RenderPassId pass_id(1, 6); |
| 193 gfx::Rect output_rect(4, 9, 13, 71); | 166 gfx::Rect output_rect(4, 9, 13, 71); |
| 194 gfx::Rect damage_rect(9, 17, 41, 45); | 167 gfx::Rect damage_rect(9, 17, 41, 45); |
| 195 gfx::Transform transform_to_root_target; | 168 gfx::Transform transform_to_root_target; |
| 196 transform_to_root_target.Skew(0.0, 43.0); | 169 transform_to_root_target.Skew(0.0, 43.0); |
| 197 bool has_transparent_background = false; | 170 bool has_transparent_background = false; |
| 198 pass->SetAll(pass_id, | 171 pass->SetAll(pass_id, |
| 199 output_rect, | 172 output_rect, |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 DrawQuadPtr mus_quad = DrawQuad::From<cc::DrawQuad>(*debug_border_quad); | 317 DrawQuadPtr mus_quad = DrawQuad::From<cc::DrawQuad>(*debug_border_quad); |
| 345 ASSERT_FALSE(mus_quad.is_null()); | 318 ASSERT_FALSE(mus_quad.is_null()); |
| 346 EXPECT_EQ(cc::mojom::Material::DEBUG_BORDER, mus_quad->material); | 319 EXPECT_EQ(cc::mojom::Material::DEBUG_BORDER, mus_quad->material); |
| 347 EXPECT_EQ(rect, mus_quad->rect); | 320 EXPECT_EQ(rect, mus_quad->rect); |
| 348 EXPECT_EQ(opaque_rect, mus_quad->opaque_rect); | 321 EXPECT_EQ(opaque_rect, mus_quad->opaque_rect); |
| 349 EXPECT_EQ(visible_rect, mus_quad->visible_rect); | 322 EXPECT_EQ(visible_rect, mus_quad->visible_rect); |
| 350 EXPECT_EQ(needs_blending, mus_quad->needs_blending); | 323 EXPECT_EQ(needs_blending, mus_quad->needs_blending); |
| 351 ASSERT_TRUE(mus_quad->debug_border_quad_state); | 324 ASSERT_TRUE(mus_quad->debug_border_quad_state); |
| 352 DebugBorderQuadStatePtr& mus_debug_border_state = | 325 DebugBorderQuadStatePtr& mus_debug_border_state = |
| 353 mus_quad->debug_border_quad_state; | 326 mus_quad->debug_border_quad_state; |
| 354 EXPECT_TRUE( | 327 EXPECT_EQ(arbitrary_color, mus_debug_border_state->color); |
| 355 Color::From(arbitrary_color).Equals(mus_debug_border_state->color)); | |
| 356 EXPECT_EQ(width, mus_debug_border_state->width); | 328 EXPECT_EQ(width, mus_debug_border_state->width); |
| 357 } | 329 } |
| 358 | 330 |
| 359 } // namespace | 331 } // namespace |
| 360 } // namespace mojo | 332 } // namespace mojo |
| OLD | NEW |