| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stddef.h> | |
| 6 #include <stdint.h> | |
| 7 | |
| 8 #include <utility> | |
| 9 | |
| 10 #include "cc/quads/debug_border_draw_quad.h" | |
| 11 #include "cc/quads/render_pass.h" | |
| 12 #include "cc/quads/solid_color_draw_quad.h" | |
| 13 #include "cc/quads/surface_draw_quad.h" | |
| 14 #include "cc/quads/texture_draw_quad.h" | |
| 15 #include "cc/resources/resource_provider.h" | |
| 16 #include "gpu/command_buffer/common/mailbox.h" | |
| 17 #include "gpu/command_buffer/common/mailbox_holder.h" | |
| 18 #include "gpu/command_buffer/common/sync_token.h" | |
| 19 #include "mojo/converters/surfaces/surfaces_type_converters.h" | |
| 20 #include "mojo/converters/transform/transform_type_converters.h" | |
| 21 #include "testing/gtest/include/gtest/gtest.h" | |
| 22 #include "third_party/skia/include/core/SkColor.h" | |
| 23 #include "third_party/skia/include/core/SkXfermode.h" | |
| 24 #include "ui/gfx/geometry/mojo/geometry_type_converters.h" | |
| 25 | |
| 26 using mus::mojom::Color; | |
| 27 using mus::mojom::ColorPtr; | |
| 28 using mus::mojom::CompositorFrame; | |
| 29 using mus::mojom::CompositorFramePtr; | |
| 30 using mus::mojom::CompositorFrameMetadata; | |
| 31 using mus::mojom::CompositorFrameMetadataPtr; | |
| 32 using mus::mojom::DebugBorderQuadState; | |
| 33 using mus::mojom::DebugBorderQuadStatePtr; | |
| 34 using mus::mojom::Pass; | |
| 35 using mus::mojom::PassPtr; | |
| 36 using mus::mojom::Quad; | |
| 37 using mus::mojom::QuadPtr; | |
| 38 using mus::mojom::RenderPassId; | |
| 39 using mus::mojom::RenderPassIdPtr; | |
| 40 using mus::mojom::RenderPassQuadState; | |
| 41 using mus::mojom::RenderPassQuadStatePtr; | |
| 42 using mus::mojom::ResourceFormat; | |
| 43 using mus::mojom::ReturnedResource; | |
| 44 using mus::mojom::ReturnedResourcePtr; | |
| 45 using mus::mojom::SharedQuadState; | |
| 46 using mus::mojom::SharedQuadStatePtr; | |
| 47 using mus::mojom::SolidColorQuadState; | |
| 48 using mus::mojom::SolidColorQuadStatePtr; | |
| 49 using mus::mojom::SurfaceId; | |
| 50 using mus::mojom::SurfaceIdPtr; | |
| 51 using mus::mojom::SurfaceQuadState; | |
| 52 using mus::mojom::SurfaceQuadStatePtr; | |
| 53 using mus::mojom::TextureQuadState; | |
| 54 using mus::mojom::TextureQuadStatePtr; | |
| 55 using mus::mojom::TileQuadState; | |
| 56 using mus::mojom::TileQuadStatePtr; | |
| 57 using mus::mojom::TransferableResource; | |
| 58 using mus::mojom::TransferableResourcePtr; | |
| 59 using mus::mojom::YUVColorSpace; | |
| 60 using mus::mojom::YUVVideoQuadState; | |
| 61 using mus::mojom::YUVVideoQuadStatePtr; | |
| 62 | |
| 63 namespace mojo { | |
| 64 namespace { | |
| 65 | |
| 66 TEST(SurfaceLibTest, SurfaceIdConverterNullId) { | |
| 67 cc::SurfaceId null_id; | |
| 68 cc::SurfaceId round_trip = SurfaceId::From(null_id).To<cc::SurfaceId>(); | |
| 69 EXPECT_TRUE(round_trip.is_null()); | |
| 70 } | |
| 71 | |
| 72 TEST(SurfaceLibTest, SurfaceIdConverterValidId) { | |
| 73 cc::SurfaceId valid_id(0, 7, 0); | |
| 74 cc::SurfaceId round_trip = SurfaceId::From(valid_id).To<cc::SurfaceId>(); | |
| 75 EXPECT_FALSE(round_trip.is_null()); | |
| 76 EXPECT_EQ(valid_id, round_trip); | |
| 77 } | |
| 78 | |
| 79 TEST(SurfaceLibTest, Color) { | |
| 80 SkColor arbitrary_color = SK_ColorMAGENTA; | |
| 81 SkColor round_trip = Color::From(arbitrary_color).To<SkColor>(); | |
| 82 EXPECT_EQ(arbitrary_color, round_trip); | |
| 83 } | |
| 84 | |
| 85 class SurfaceLibQuadTest : public testing::Test { | |
| 86 public: | |
| 87 SurfaceLibQuadTest() | |
| 88 : rect(5, 7, 13, 19), | |
| 89 opaque_rect(rect), | |
| 90 visible_rect(9, 11, 5, 7), | |
| 91 needs_blending(false) { | |
| 92 pass = cc::RenderPass::Create(); | |
| 93 sqs = pass->CreateAndAppendSharedQuadState(); | |
| 94 } | |
| 95 | |
| 96 protected: | |
| 97 gfx::Rect rect; | |
| 98 gfx::Rect opaque_rect; | |
| 99 gfx::Rect visible_rect; | |
| 100 bool needs_blending; | |
| 101 std::unique_ptr<cc::RenderPass> pass; | |
| 102 cc::SharedQuadState* sqs; | |
| 103 }; | |
| 104 | |
| 105 TEST_F(SurfaceLibQuadTest, ColorQuad) { | |
| 106 cc::SolidColorDrawQuad* color_quad = | |
| 107 pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); | |
| 108 SkColor arbitrary_color = SK_ColorGREEN; | |
| 109 bool force_anti_aliasing_off = true; | |
| 110 color_quad->SetAll(sqs, | |
| 111 rect, | |
| 112 opaque_rect, | |
| 113 visible_rect, | |
| 114 needs_blending, | |
| 115 arbitrary_color, | |
| 116 force_anti_aliasing_off); | |
| 117 | |
| 118 QuadPtr mus_quad = Quad::From<cc::DrawQuad>(*color_quad); | |
| 119 ASSERT_FALSE(mus_quad.is_null()); | |
| 120 EXPECT_EQ(mus::mojom::Material::SOLID_COLOR, mus_quad->material); | |
| 121 EXPECT_TRUE(Rect::From(rect).Equals(mus_quad->rect)); | |
| 122 EXPECT_TRUE(Rect::From(opaque_rect).Equals(mus_quad->opaque_rect)); | |
| 123 EXPECT_TRUE(Rect::From(visible_rect).Equals(mus_quad->visible_rect)); | |
| 124 EXPECT_EQ(needs_blending, mus_quad->needs_blending); | |
| 125 ASSERT_TRUE(mus_quad->solid_color_quad_state); | |
| 126 SolidColorQuadStatePtr& mus_color_state = mus_quad->solid_color_quad_state; | |
| 127 EXPECT_TRUE(Color::From(arbitrary_color).Equals(mus_color_state->color)); | |
| 128 EXPECT_EQ(force_anti_aliasing_off, mus_color_state->force_anti_aliasing_off); | |
| 129 } | |
| 130 | |
| 131 TEST_F(SurfaceLibQuadTest, SurfaceQuad) { | |
| 132 cc::SurfaceDrawQuad* surface_quad = | |
| 133 pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | |
| 134 cc::SurfaceId arbitrary_id(0, 5, 0); | |
| 135 surface_quad->SetAll( | |
| 136 sqs, rect, opaque_rect, visible_rect, needs_blending, arbitrary_id); | |
| 137 | |
| 138 QuadPtr mus_quad = Quad::From<cc::DrawQuad>(*surface_quad); | |
| 139 ASSERT_FALSE(mus_quad.is_null()); | |
| 140 EXPECT_EQ(mus::mojom::Material::SURFACE_CONTENT, mus_quad->material); | |
| 141 ASSERT_TRUE(mus_quad->surface_quad_state); | |
| 142 SurfaceQuadStatePtr& mus_surface_state = mus_quad->surface_quad_state; | |
| 143 EXPECT_TRUE(SurfaceId::From(arbitrary_id).Equals(mus_surface_state->surface)); | |
| 144 } | |
| 145 | |
| 146 TEST_F(SurfaceLibQuadTest, TextureQuad) { | |
| 147 cc::TextureDrawQuad* texture_quad = | |
| 148 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); | |
| 149 unsigned resource_id = 9; | |
| 150 bool premultiplied_alpha = true; | |
| 151 gfx::PointF uv_top_left(1.7f, 2.1f); | |
| 152 gfx::PointF uv_bottom_right(-7.f, 16.3f); | |
| 153 SkColor background_color = SK_ColorYELLOW; | |
| 154 float vertex_opacity[4] = {0.1f, 0.5f, 0.4f, 0.8f}; | |
| 155 bool y_flipped = false; | |
| 156 bool nearest_neighbor = false; | |
| 157 bool secure_output_only = true; | |
| 158 texture_quad->SetAll(sqs, rect, opaque_rect, visible_rect, needs_blending, | |
| 159 resource_id, gfx::Size(), premultiplied_alpha, | |
| 160 uv_top_left, uv_bottom_right, background_color, | |
| 161 vertex_opacity, y_flipped, nearest_neighbor, | |
| 162 secure_output_only); | |
| 163 | |
| 164 QuadPtr mus_quad = Quad::From<cc::DrawQuad>(*texture_quad); | |
| 165 ASSERT_FALSE(mus_quad.is_null()); | |
| 166 EXPECT_EQ(mus::mojom::Material::TEXTURE_CONTENT, mus_quad->material); | |
| 167 ASSERT_TRUE(mus_quad->texture_quad_state); | |
| 168 TextureQuadStatePtr& mus_texture_state = mus_quad->texture_quad_state; | |
| 169 EXPECT_EQ(resource_id, mus_texture_state->resource_id); | |
| 170 EXPECT_EQ(premultiplied_alpha, mus_texture_state->premultiplied_alpha); | |
| 171 EXPECT_TRUE(PointF::From(uv_top_left).Equals(mus_texture_state->uv_top_left)); | |
| 172 EXPECT_TRUE( | |
| 173 PointF::From(uv_bottom_right).Equals(mus_texture_state->uv_bottom_right)); | |
| 174 EXPECT_TRUE(Color::From(background_color) | |
| 175 .Equals(mus_texture_state->background_color)); | |
| 176 for (size_t i = 0; i < 4; ++i) { | |
| 177 EXPECT_EQ(vertex_opacity[i], mus_texture_state->vertex_opacity[i]) << i; | |
| 178 } | |
| 179 EXPECT_EQ(y_flipped, mus_texture_state->y_flipped); | |
| 180 EXPECT_EQ(secure_output_only, mus_texture_state->secure_output_only); | |
| 181 } | |
| 182 | |
| 183 TEST_F(SurfaceLibQuadTest, TextureQuadEmptyVertexOpacity) { | |
| 184 QuadPtr mus_texture_quad = Quad::New(); | |
| 185 mus_texture_quad->material = mus::mojom::Material::TEXTURE_CONTENT; | |
| 186 TextureQuadStatePtr mus_texture_state = TextureQuadState::New(); | |
| 187 mus_texture_state->background_color = Color::New(); | |
| 188 mus_texture_quad->texture_quad_state = std::move(mus_texture_state); | |
| 189 PassPtr mus_pass = Pass::New(); | |
| 190 mus_pass->id = RenderPassId::New(); | |
| 191 mus_pass->id->layer_id = 1; | |
| 192 mus_pass->id->index = 1u; | |
| 193 mus_pass->quads.push_back(std::move(mus_texture_quad)); | |
| 194 SharedQuadStatePtr mus_sqs = SharedQuadState::New(); | |
| 195 mus_pass->shared_quad_states.push_back(std::move(mus_sqs)); | |
| 196 | |
| 197 std::unique_ptr<cc::RenderPass> pass = | |
| 198 mus_pass.To<std::unique_ptr<cc::RenderPass>>(); | |
| 199 | |
| 200 EXPECT_FALSE(pass); | |
| 201 } | |
| 202 | |
| 203 TEST_F(SurfaceLibQuadTest, TextureQuadEmptyBackgroundColor) { | |
| 204 QuadPtr mus_texture_quad = Quad::New(); | |
| 205 mus_texture_quad->material = mus::mojom::Material::TEXTURE_CONTENT; | |
| 206 TextureQuadStatePtr mus_texture_state = TextureQuadState::New(); | |
| 207 mus_texture_state->vertex_opacity = mojo::Array<float>::New(4); | |
| 208 mus_texture_quad->texture_quad_state = std::move(mus_texture_state); | |
| 209 PassPtr mus_pass = Pass::New(); | |
| 210 mus_pass->id = RenderPassId::New(); | |
| 211 mus_pass->id->layer_id = 1; | |
| 212 mus_pass->id->index = 1u; | |
| 213 mus_pass->quads.push_back(std::move(mus_texture_quad)); | |
| 214 SharedQuadStatePtr mus_sqs = SharedQuadState::New(); | |
| 215 mus_pass->shared_quad_states.push_back(std::move(mus_sqs)); | |
| 216 | |
| 217 std::unique_ptr<cc::RenderPass> pass = | |
| 218 mus_pass.To<std::unique_ptr<cc::RenderPass>>(); | |
| 219 EXPECT_FALSE(pass); | |
| 220 } | |
| 221 | |
| 222 TEST(SurfaceLibTest, SharedQuadState) { | |
| 223 gfx::Transform quad_to_target_transform; | |
| 224 quad_to_target_transform.Scale3d(0.3f, 0.7f, 0.9f); | |
| 225 gfx::Size quad_layer_bounds(57, 39); | |
| 226 gfx::Rect visible_quad_layer_rect(3, 7, 28, 42); | |
| 227 gfx::Rect clip_rect(9, 12, 21, 31); | |
| 228 bool is_clipped = true; | |
| 229 float opacity = 0.65f; | |
| 230 int sorting_context_id = 13; | |
| 231 ::SkXfermode::Mode blend_mode = ::SkXfermode::kSrcOver_Mode; | |
| 232 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); | |
| 233 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | |
| 234 sqs->SetAll(quad_to_target_transform, quad_layer_bounds, | |
| 235 visible_quad_layer_rect, clip_rect, is_clipped, opacity, | |
| 236 blend_mode, sorting_context_id); | |
| 237 | |
| 238 SharedQuadStatePtr mus_sqs = SharedQuadState::From(*sqs); | |
| 239 ASSERT_FALSE(mus_sqs.is_null()); | |
| 240 EXPECT_TRUE(Transform::From(quad_to_target_transform) | |
| 241 .Equals(mus_sqs->quad_to_target_transform)); | |
| 242 EXPECT_TRUE(Size::From(quad_layer_bounds).Equals(mus_sqs->quad_layer_bounds)); | |
| 243 EXPECT_TRUE(Rect::From(visible_quad_layer_rect) | |
| 244 .Equals(mus_sqs->visible_quad_layer_rect)); | |
| 245 EXPECT_TRUE(Rect::From(clip_rect).Equals(mus_sqs->clip_rect)); | |
| 246 EXPECT_EQ(is_clipped, mus_sqs->is_clipped); | |
| 247 EXPECT_EQ(opacity, mus_sqs->opacity); | |
| 248 EXPECT_EQ(sorting_context_id, mus_sqs->sorting_context_id); | |
| 249 } | |
| 250 | |
| 251 TEST(SurfaceLibTest, RenderPass) { | |
| 252 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); | |
| 253 cc::RenderPassId pass_id(1, 6); | |
| 254 gfx::Rect output_rect(4, 9, 13, 71); | |
| 255 gfx::Rect damage_rect(9, 17, 41, 45); | |
| 256 gfx::Transform transform_to_root_target; | |
| 257 transform_to_root_target.Skew(0.0, 43.0); | |
| 258 bool has_transparent_background = false; | |
| 259 pass->SetAll(pass_id, | |
| 260 output_rect, | |
| 261 damage_rect, | |
| 262 transform_to_root_target, | |
| 263 has_transparent_background); | |
| 264 | |
| 265 gfx::Transform quad_to_target_transform; | |
| 266 quad_to_target_transform.Scale3d(0.3f, 0.7f, 0.9f); | |
| 267 gfx::Size quad_layer_bounds(57, 39); | |
| 268 gfx::Rect visible_quad_layer_rect(3, 7, 28, 42); | |
| 269 gfx::Rect clip_rect(9, 12, 21, 31); | |
| 270 bool is_clipped = true; | |
| 271 float opacity = 0.65f; | |
| 272 int sorting_context_id = 13; | |
| 273 ::SkXfermode::Mode blend_mode = ::SkXfermode::kSrcOver_Mode; | |
| 274 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | |
| 275 sqs->SetAll(quad_to_target_transform, quad_layer_bounds, | |
| 276 visible_quad_layer_rect, clip_rect, is_clipped, opacity, | |
| 277 blend_mode, sorting_context_id); | |
| 278 | |
| 279 gfx::Rect rect(5, 7, 13, 19); | |
| 280 gfx::Rect opaque_rect(rect); | |
| 281 gfx::Rect visible_rect(9, 11, 5, 7); | |
| 282 bool needs_blending = false; | |
| 283 | |
| 284 cc::SolidColorDrawQuad* color_quad = | |
| 285 pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); | |
| 286 SkColor arbitrary_color = SK_ColorGREEN; | |
| 287 bool force_anti_aliasing_off = true; | |
| 288 color_quad->SetAll(pass->shared_quad_state_list.back(), | |
| 289 rect, | |
| 290 opaque_rect, | |
| 291 visible_rect, | |
| 292 needs_blending, | |
| 293 arbitrary_color, | |
| 294 force_anti_aliasing_off); | |
| 295 | |
| 296 cc::SurfaceDrawQuad* surface_quad = | |
| 297 pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | |
| 298 cc::SurfaceId arbitrary_id(0, 5, 0); | |
| 299 surface_quad->SetAll( | |
| 300 sqs, rect, opaque_rect, visible_rect, needs_blending, arbitrary_id); | |
| 301 | |
| 302 cc::TextureDrawQuad* texture_quad = | |
| 303 pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); | |
| 304 unsigned resource_id = 9; | |
| 305 bool premultiplied_alpha = true; | |
| 306 gfx::PointF uv_top_left(1.7f, 2.1f); | |
| 307 gfx::PointF uv_bottom_right(-7.f, 16.3f); | |
| 308 SkColor background_color = SK_ColorYELLOW; | |
| 309 float vertex_opacity[4] = {0.1f, 0.5f, 0.4f, 0.8f}; | |
| 310 bool y_flipped = false; | |
| 311 bool nearest_neighbor = false; | |
| 312 bool secure_output_only = false; | |
| 313 texture_quad->SetAll(sqs, rect, opaque_rect, visible_rect, needs_blending, | |
| 314 resource_id, gfx::Size(), premultiplied_alpha, | |
| 315 uv_top_left, uv_bottom_right, background_color, | |
| 316 vertex_opacity, y_flipped, nearest_neighbor, | |
| 317 secure_output_only); | |
| 318 | |
| 319 PassPtr mus_pass = Pass::From(*pass); | |
| 320 ASSERT_FALSE(mus_pass.is_null()); | |
| 321 EXPECT_EQ(6u, mus_pass->id->index); | |
| 322 EXPECT_TRUE(Rect::From(output_rect).Equals(mus_pass->output_rect)); | |
| 323 EXPECT_TRUE(Rect::From(damage_rect).Equals(mus_pass->damage_rect)); | |
| 324 EXPECT_TRUE(Transform::From(transform_to_root_target) | |
| 325 .Equals(mus_pass->transform_to_root_target)); | |
| 326 EXPECT_EQ(has_transparent_background, mus_pass->has_transparent_background); | |
| 327 ASSERT_EQ(1u, mus_pass->shared_quad_states.size()); | |
| 328 ASSERT_EQ(3u, mus_pass->quads.size()); | |
| 329 EXPECT_EQ(0u, mus_pass->quads[0]->shared_quad_state_index); | |
| 330 | |
| 331 std::unique_ptr<cc::RenderPass> round_trip_pass = | |
| 332 mus_pass.To<std::unique_ptr<cc::RenderPass>>(); | |
| 333 EXPECT_EQ(pass_id, round_trip_pass->id); | |
| 334 EXPECT_EQ(output_rect, round_trip_pass->output_rect); | |
| 335 EXPECT_EQ(damage_rect, round_trip_pass->damage_rect); | |
| 336 EXPECT_EQ(transform_to_root_target, | |
| 337 round_trip_pass->transform_to_root_target); | |
| 338 EXPECT_EQ(has_transparent_background, | |
| 339 round_trip_pass->has_transparent_background); | |
| 340 ASSERT_EQ(1u, round_trip_pass->shared_quad_state_list.size()); | |
| 341 ASSERT_EQ(3u, round_trip_pass->quad_list.size()); | |
| 342 EXPECT_EQ(round_trip_pass->shared_quad_state_list.front(), | |
| 343 round_trip_pass->quad_list.front()->shared_quad_state); | |
| 344 | |
| 345 cc::SharedQuadState* round_trip_sqs = | |
| 346 round_trip_pass->shared_quad_state_list.front(); | |
| 347 EXPECT_EQ(quad_to_target_transform, round_trip_sqs->quad_to_target_transform); | |
| 348 EXPECT_EQ(quad_layer_bounds, round_trip_sqs->quad_layer_bounds); | |
| 349 EXPECT_EQ(visible_quad_layer_rect, round_trip_sqs->visible_quad_layer_rect); | |
| 350 EXPECT_EQ(clip_rect, round_trip_sqs->clip_rect); | |
| 351 EXPECT_EQ(is_clipped, round_trip_sqs->is_clipped); | |
| 352 EXPECT_EQ(opacity, round_trip_sqs->opacity); | |
| 353 EXPECT_EQ(sorting_context_id, round_trip_sqs->sorting_context_id); | |
| 354 | |
| 355 cc::DrawQuad* round_trip_quad = round_trip_pass->quad_list.front(); | |
| 356 // First is solid color quad. | |
| 357 ASSERT_EQ(cc::DrawQuad::SOLID_COLOR, round_trip_quad->material); | |
| 358 EXPECT_EQ(rect, round_trip_quad->rect); | |
| 359 EXPECT_EQ(opaque_rect, round_trip_quad->opaque_rect); | |
| 360 EXPECT_EQ(visible_rect, round_trip_quad->visible_rect); | |
| 361 EXPECT_EQ(needs_blending, round_trip_quad->needs_blending); | |
| 362 const cc::SolidColorDrawQuad* round_trip_color_quad = | |
| 363 cc::SolidColorDrawQuad::MaterialCast(round_trip_quad); | |
| 364 EXPECT_EQ(arbitrary_color, round_trip_color_quad->color); | |
| 365 EXPECT_EQ(force_anti_aliasing_off, | |
| 366 round_trip_color_quad->force_anti_aliasing_off); | |
| 367 | |
| 368 round_trip_quad = round_trip_pass->quad_list.ElementAt(1); | |
| 369 // Second is surface quad. | |
| 370 ASSERT_EQ(cc::DrawQuad::SURFACE_CONTENT, round_trip_quad->material); | |
| 371 const cc::SurfaceDrawQuad* round_trip_surface_quad = | |
| 372 cc::SurfaceDrawQuad::MaterialCast(round_trip_quad); | |
| 373 EXPECT_EQ(arbitrary_id, round_trip_surface_quad->surface_id); | |
| 374 | |
| 375 round_trip_quad = round_trip_pass->quad_list.ElementAt(2); | |
| 376 // Third is texture quad. | |
| 377 ASSERT_EQ(cc::DrawQuad::TEXTURE_CONTENT, round_trip_quad->material); | |
| 378 const cc::TextureDrawQuad* round_trip_texture_quad = | |
| 379 cc::TextureDrawQuad::MaterialCast(round_trip_quad); | |
| 380 EXPECT_EQ(resource_id, round_trip_texture_quad->resource_id()); | |
| 381 EXPECT_EQ(premultiplied_alpha, round_trip_texture_quad->premultiplied_alpha); | |
| 382 EXPECT_EQ(uv_top_left, round_trip_texture_quad->uv_top_left); | |
| 383 EXPECT_EQ(uv_bottom_right, round_trip_texture_quad->uv_bottom_right); | |
| 384 EXPECT_EQ(background_color, round_trip_texture_quad->background_color); | |
| 385 for (size_t i = 0; i < 4; ++i) { | |
| 386 EXPECT_EQ(vertex_opacity[i], round_trip_texture_quad->vertex_opacity[i]) | |
| 387 << i; | |
| 388 } | |
| 389 EXPECT_EQ(y_flipped, round_trip_texture_quad->y_flipped); | |
| 390 EXPECT_EQ(secure_output_only, round_trip_texture_quad->secure_output_only); | |
| 391 } | |
| 392 | |
| 393 TEST(SurfaceLibTest, TransferableResource) { | |
| 394 uint32_t id = 7u; | |
| 395 cc::ResourceFormat format = cc::BGRA_8888; | |
| 396 uint32_t filter = 123u; | |
| 397 gfx::Size size(17, 18); | |
| 398 gpu::MailboxHolder mailbox_holder; | |
| 399 bool is_software = false; | |
| 400 cc::TransferableResource resource; | |
| 401 resource.id = id; | |
| 402 resource.format = format; | |
| 403 resource.filter = filter; | |
| 404 resource.size = size; | |
| 405 resource.mailbox_holder = mailbox_holder; | |
| 406 resource.is_software = is_software; | |
| 407 | |
| 408 TransferableResourcePtr mus_resource = TransferableResource::From(resource); | |
| 409 EXPECT_EQ(id, mus_resource->id); | |
| 410 EXPECT_EQ(static_cast<ResourceFormat>(format), mus_resource->format); | |
| 411 EXPECT_EQ(filter, mus_resource->filter); | |
| 412 EXPECT_TRUE(Size::From(size).Equals(mus_resource->size)); | |
| 413 EXPECT_EQ(is_software, mus_resource->is_software); | |
| 414 | |
| 415 cc::TransferableResource round_trip_resource = | |
| 416 mus_resource.To<cc::TransferableResource>(); | |
| 417 EXPECT_EQ(id, round_trip_resource.id); | |
| 418 EXPECT_EQ(format, round_trip_resource.format); | |
| 419 EXPECT_EQ(filter, round_trip_resource.filter); | |
| 420 EXPECT_EQ(size, round_trip_resource.size); | |
| 421 EXPECT_EQ(mailbox_holder.mailbox, round_trip_resource.mailbox_holder.mailbox); | |
| 422 EXPECT_EQ(mailbox_holder.texture_target, | |
| 423 round_trip_resource.mailbox_holder.texture_target); | |
| 424 EXPECT_EQ(mailbox_holder.sync_token, | |
| 425 round_trip_resource.mailbox_holder.sync_token); | |
| 426 EXPECT_EQ(is_software, round_trip_resource.is_software); | |
| 427 } | |
| 428 | |
| 429 TEST(SurfaceLibTest, ReturnedResource) { | |
| 430 uint32_t id = 5u; | |
| 431 gpu::SyncToken sync_token(gpu::CommandBufferNamespace::GPU_IO, 0, | |
| 432 gpu::CommandBufferId::FromUnsafeValue(1), 24u); | |
| 433 sync_token.SetVerifyFlush(); | |
| 434 int count = 2; | |
| 435 bool lost = false; | |
| 436 cc::ReturnedResource resource; | |
| 437 resource.id = id; | |
| 438 resource.sync_token = sync_token; | |
| 439 resource.count = count; | |
| 440 resource.lost = lost; | |
| 441 | |
| 442 ReturnedResourcePtr mus_resource = ReturnedResource::From(resource); | |
| 443 EXPECT_EQ(id, mus_resource->id); | |
| 444 EXPECT_EQ(sync_token, mus_resource->sync_token); | |
| 445 EXPECT_EQ(count, mus_resource->count); | |
| 446 EXPECT_EQ(lost, mus_resource->lost); | |
| 447 | |
| 448 cc::ReturnedResource round_trip_resource = | |
| 449 mus_resource.To<cc::ReturnedResource>(); | |
| 450 EXPECT_EQ(id, round_trip_resource.id); | |
| 451 EXPECT_EQ(sync_token, round_trip_resource.sync_token); | |
| 452 EXPECT_EQ(count, round_trip_resource.count); | |
| 453 EXPECT_EQ(lost, round_trip_resource.lost); | |
| 454 } | |
| 455 | |
| 456 TEST_F(SurfaceLibQuadTest, DebugBorderQuad) { | |
| 457 cc::DebugBorderDrawQuad* debug_border_quad = | |
| 458 pass->CreateAndAppendDrawQuad<cc::DebugBorderDrawQuad>(); | |
| 459 const SkColor arbitrary_color = SK_ColorGREEN; | |
| 460 const int width = 3; | |
| 461 debug_border_quad->SetAll(sqs, | |
| 462 rect, | |
| 463 opaque_rect, | |
| 464 visible_rect, | |
| 465 needs_blending, | |
| 466 arbitrary_color, | |
| 467 width); | |
| 468 | |
| 469 QuadPtr mus_quad = Quad::From<cc::DrawQuad>(*debug_border_quad); | |
| 470 ASSERT_FALSE(mus_quad.is_null()); | |
| 471 EXPECT_EQ(mus::mojom::Material::DEBUG_BORDER, mus_quad->material); | |
| 472 EXPECT_TRUE(Rect::From(rect).Equals(mus_quad->rect)); | |
| 473 EXPECT_TRUE(Rect::From(opaque_rect).Equals(mus_quad->opaque_rect)); | |
| 474 EXPECT_TRUE(Rect::From(visible_rect).Equals(mus_quad->visible_rect)); | |
| 475 EXPECT_EQ(needs_blending, mus_quad->needs_blending); | |
| 476 ASSERT_TRUE(mus_quad->debug_border_quad_state); | |
| 477 DebugBorderQuadStatePtr& mus_debug_border_state = | |
| 478 mus_quad->debug_border_quad_state; | |
| 479 EXPECT_TRUE( | |
| 480 Color::From(arbitrary_color).Equals(mus_debug_border_state->color)); | |
| 481 EXPECT_EQ(width, mus_debug_border_state->width); | |
| 482 } | |
| 483 | |
| 484 } // namespace | |
| 485 } // namespace mojo | |
| OLD | NEW |