| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> |
| 6 |
| 5 #include "base/mac/sdk_forward_declarations.h" | 7 #include "base/mac/sdk_forward_declarations.h" |
| 6 #include "gpu/GLES2/gl2extchromium.h" | 8 #include "gpu/GLES2/gl2extchromium.h" |
| 7 #include "gpu/ipc/service/ca_layer_tree_mac.h" | 9 #include "gpu/ipc/service/ca_layer_tree_mac.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "third_party/skia/include/core/SkColor.h" | 11 #include "third_party/skia/include/core/SkColor.h" |
| 10 #include "ui/gfx/geometry/dip_util.h" | 12 #include "ui/gfx/geometry/dip_util.h" |
| 11 #include "ui/gfx/mac/io_surface.h" | 13 #include "ui/gfx/mac/io_surface.h" |
| 12 | 14 |
| 13 namespace gpu { | 15 namespace gpu { |
| 14 | 16 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 31 gfx::Transform transform; | 33 gfx::Transform transform; |
| 32 transform.Translate(10, 20); | 34 transform.Translate(10, 20); |
| 33 gfx::RectF contents_rect(0.0f, 0.25f, 0.5f, 0.75f); | 35 gfx::RectF contents_rect(0.0f, 0.25f, 0.5f, 0.75f); |
| 34 gfx::Rect rect(16, 32, 64, 128); | 36 gfx::Rect rect(16, 32, 64, 128); |
| 35 unsigned background_color = SkColorSetARGB(0xFF, 0xFF, 0, 0); | 37 unsigned background_color = SkColorSetARGB(0xFF, 0xFF, 0, 0); |
| 36 unsigned edge_aa_mask = GL_CA_LAYER_EDGE_LEFT_CHROMIUM; | 38 unsigned edge_aa_mask = GL_CA_LAYER_EDGE_LEFT_CHROMIUM; |
| 37 float opacity = 0.5f; | 39 float opacity = 0.5f; |
| 38 float scale_factor = 1.0f; | 40 float scale_factor = 1.0f; |
| 39 bool result = false; | 41 bool result = false; |
| 40 | 42 |
| 41 scoped_ptr<CALayerTree> ca_layer_tree; | 43 std::unique_ptr<CALayerTree> ca_layer_tree; |
| 42 CALayer* root_layer = nil; | 44 CALayer* root_layer = nil; |
| 43 CALayer* clip_and_sorting_layer = nil; | 45 CALayer* clip_and_sorting_layer = nil; |
| 44 CALayer* transform_layer = nil; | 46 CALayer* transform_layer = nil; |
| 45 CALayer* content_layer = nil; | 47 CALayer* content_layer = nil; |
| 46 | 48 |
| 47 // Validate the initial values. | 49 // Validate the initial values. |
| 48 { | 50 { |
| 49 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); | 51 std::unique_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 50 result = new_ca_layer_tree->ScheduleCALayer( | 52 result = new_ca_layer_tree->ScheduleCALayer( |
| 51 is_clipped, | 53 is_clipped, |
| 52 clip_rect, | 54 clip_rect, |
| 53 sorting_context_id, | 55 sorting_context_id, |
| 54 transform, | 56 transform, |
| 55 io_surface, | 57 io_surface, |
| 56 contents_rect, | 58 contents_rect, |
| 57 rect, | 59 rect, |
| 58 background_color, | 60 background_color, |
| 59 edge_aa_mask, | 61 edge_aa_mask, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 EXPECT_EQ(gfx::Rect(rect.size()), gfx::Rect([content_layer bounds])); | 99 EXPECT_EQ(gfx::Rect(rect.size()), gfx::Rect([content_layer bounds])); |
| 98 EXPECT_EQ(kCALayerLeftEdge, [content_layer edgeAntialiasingMask]); | 100 EXPECT_EQ(kCALayerLeftEdge, [content_layer edgeAntialiasingMask]); |
| 99 EXPECT_EQ(opacity, [content_layer opacity]); | 101 EXPECT_EQ(opacity, [content_layer opacity]); |
| 100 if ([content_layer respondsToSelector:(@selector(contentsScale))]) | 102 if ([content_layer respondsToSelector:(@selector(contentsScale))]) |
| 101 EXPECT_EQ(scale_factor, [content_layer contentsScale]); | 103 EXPECT_EQ(scale_factor, [content_layer contentsScale]); |
| 102 } | 104 } |
| 103 | 105 |
| 104 // Update just the clip rect and re-commit. | 106 // Update just the clip rect and re-commit. |
| 105 { | 107 { |
| 106 clip_rect = gfx::Rect(4, 8, 16, 32); | 108 clip_rect = gfx::Rect(4, 8, 16, 32); |
| 107 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); | 109 std::unique_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 108 result = new_ca_layer_tree->ScheduleCALayer( | 110 result = new_ca_layer_tree->ScheduleCALayer( |
| 109 is_clipped, | 111 is_clipped, |
| 110 clip_rect, | 112 clip_rect, |
| 111 sorting_context_id, | 113 sorting_context_id, |
| 112 transform, | 114 transform, |
| 113 io_surface, | 115 io_surface, |
| 114 contents_rect, | 116 contents_rect, |
| 115 rect, | 117 rect, |
| 116 background_color, | 118 background_color, |
| 117 edge_aa_mask, | 119 edge_aa_mask, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 138 gfx::Point([clip_and_sorting_layer position])); | 140 gfx::Point([clip_and_sorting_layer position])); |
| 139 EXPECT_EQ(-clip_rect.origin().x(), | 141 EXPECT_EQ(-clip_rect.origin().x(), |
| 140 [clip_and_sorting_layer sublayerTransform].m41); | 142 [clip_and_sorting_layer sublayerTransform].m41); |
| 141 EXPECT_EQ(-clip_rect.origin().y(), | 143 EXPECT_EQ(-clip_rect.origin().y(), |
| 142 [clip_and_sorting_layer sublayerTransform].m42); | 144 [clip_and_sorting_layer sublayerTransform].m42); |
| 143 } | 145 } |
| 144 | 146 |
| 145 // Disable clipping and re-commit. | 147 // Disable clipping and re-commit. |
| 146 { | 148 { |
| 147 is_clipped = false; | 149 is_clipped = false; |
| 148 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); | 150 std::unique_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 149 result = new_ca_layer_tree->ScheduleCALayer( | 151 result = new_ca_layer_tree->ScheduleCALayer( |
| 150 is_clipped, | 152 is_clipped, |
| 151 clip_rect, | 153 clip_rect, |
| 152 sorting_context_id, | 154 sorting_context_id, |
| 153 transform, | 155 transform, |
| 154 io_surface, | 156 io_surface, |
| 155 contents_rect, | 157 contents_rect, |
| 156 rect, | 158 rect, |
| 157 background_color, | 159 background_color, |
| 158 edge_aa_mask, | 160 edge_aa_mask, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 176 EXPECT_EQ(gfx::Rect(), gfx::Rect([clip_and_sorting_layer bounds])); | 178 EXPECT_EQ(gfx::Rect(), gfx::Rect([clip_and_sorting_layer bounds])); |
| 177 EXPECT_EQ(gfx::Point(), gfx::Point([clip_and_sorting_layer position])); | 179 EXPECT_EQ(gfx::Point(), gfx::Point([clip_and_sorting_layer position])); |
| 178 EXPECT_EQ(0.0, [clip_and_sorting_layer sublayerTransform].m41); | 180 EXPECT_EQ(0.0, [clip_and_sorting_layer sublayerTransform].m41); |
| 179 EXPECT_EQ(0.0, [clip_and_sorting_layer sublayerTransform].m42); | 181 EXPECT_EQ(0.0, [clip_and_sorting_layer sublayerTransform].m42); |
| 180 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 182 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
| 181 } | 183 } |
| 182 | 184 |
| 183 // Change the transform and re-commit. | 185 // Change the transform and re-commit. |
| 184 { | 186 { |
| 185 transform.Translate(5, 5); | 187 transform.Translate(5, 5); |
| 186 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); | 188 std::unique_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 187 result = new_ca_layer_tree->ScheduleCALayer( | 189 result = new_ca_layer_tree->ScheduleCALayer( |
| 188 is_clipped, | 190 is_clipped, |
| 189 clip_rect, | 191 clip_rect, |
| 190 sorting_context_id, | 192 sorting_context_id, |
| 191 transform, | 193 transform, |
| 192 io_surface, | 194 io_surface, |
| 193 contents_rect, | 195 contents_rect, |
| 194 rect, | 196 rect, |
| 195 background_color, | 197 background_color, |
| 196 edge_aa_mask, | 198 edge_aa_mask, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 212 // Validate the transform layer. | 214 // Validate the transform layer. |
| 213 EXPECT_EQ(transform.matrix().get(3, 0), | 215 EXPECT_EQ(transform.matrix().get(3, 0), |
| 214 [transform_layer sublayerTransform].m41); | 216 [transform_layer sublayerTransform].m41); |
| 215 EXPECT_EQ(transform.matrix().get(3, 1), | 217 EXPECT_EQ(transform.matrix().get(3, 1), |
| 216 [transform_layer sublayerTransform].m42); | 218 [transform_layer sublayerTransform].m42); |
| 217 } | 219 } |
| 218 | 220 |
| 219 // Change the edge antialiasing mask and commit. | 221 // Change the edge antialiasing mask and commit. |
| 220 { | 222 { |
| 221 edge_aa_mask = GL_CA_LAYER_EDGE_TOP_CHROMIUM; | 223 edge_aa_mask = GL_CA_LAYER_EDGE_TOP_CHROMIUM; |
| 222 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); | 224 std::unique_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 223 result = new_ca_layer_tree->ScheduleCALayer( | 225 result = new_ca_layer_tree->ScheduleCALayer( |
| 224 is_clipped, | 226 is_clipped, |
| 225 clip_rect, | 227 clip_rect, |
| 226 sorting_context_id, | 228 sorting_context_id, |
| 227 transform, | 229 transform, |
| 228 io_surface, | 230 io_surface, |
| 229 contents_rect, | 231 contents_rect, |
| 230 rect, | 232 rect, |
| 231 background_color, | 233 background_color, |
| 232 edge_aa_mask, | 234 edge_aa_mask, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 246 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); | 248 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); |
| 247 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 249 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
| 248 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 250 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
| 249 | 251 |
| 250 // Validate the content layer. Note that top and bottom edges flip. | 252 // Validate the content layer. Note that top and bottom edges flip. |
| 251 EXPECT_EQ(kCALayerBottomEdge, [content_layer edgeAntialiasingMask]); | 253 EXPECT_EQ(kCALayerBottomEdge, [content_layer edgeAntialiasingMask]); |
| 252 } | 254 } |
| 253 | 255 |
| 254 // Change the contents and commit. | 256 // Change the contents and commit. |
| 255 { | 257 { |
| 256 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); | 258 std::unique_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 257 result = new_ca_layer_tree->ScheduleCALayer( | 259 result = new_ca_layer_tree->ScheduleCALayer( |
| 258 is_clipped, | 260 is_clipped, |
| 259 clip_rect, | 261 clip_rect, |
| 260 sorting_context_id, | 262 sorting_context_id, |
| 261 transform, | 263 transform, |
| 262 nullptr, | 264 nullptr, |
| 263 contents_rect, | 265 contents_rect, |
| 264 rect, | 266 rect, |
| 265 background_color, | 267 background_color, |
| 266 edge_aa_mask, | 268 edge_aa_mask, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 282 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 284 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
| 283 | 285 |
| 284 // Validate the content layer. Note that edge anti-aliasing no longer flips. | 286 // Validate the content layer. Note that edge anti-aliasing no longer flips. |
| 285 EXPECT_EQ(nil, [content_layer contents]); | 287 EXPECT_EQ(nil, [content_layer contents]); |
| 286 EXPECT_EQ(kCALayerTopEdge, [content_layer edgeAntialiasingMask]); | 288 EXPECT_EQ(kCALayerTopEdge, [content_layer edgeAntialiasingMask]); |
| 287 } | 289 } |
| 288 | 290 |
| 289 // Change the rect size. | 291 // Change the rect size. |
| 290 { | 292 { |
| 291 rect = gfx::Rect(rect.origin(), gfx::Size(32, 16)); | 293 rect = gfx::Rect(rect.origin(), gfx::Size(32, 16)); |
| 292 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); | 294 std::unique_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 293 result = new_ca_layer_tree->ScheduleCALayer( | 295 result = new_ca_layer_tree->ScheduleCALayer( |
| 294 is_clipped, | 296 is_clipped, |
| 295 clip_rect, | 297 clip_rect, |
| 296 sorting_context_id, | 298 sorting_context_id, |
| 297 transform, | 299 transform, |
| 298 nullptr, | 300 nullptr, |
| 299 contents_rect, | 301 contents_rect, |
| 300 rect, | 302 rect, |
| 301 background_color, | 303 background_color, |
| 302 edge_aa_mask, | 304 edge_aa_mask, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 318 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 320 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
| 319 | 321 |
| 320 // Validate the content layer. | 322 // Validate the content layer. |
| 321 EXPECT_EQ(rect.origin(), gfx::Point([content_layer position])); | 323 EXPECT_EQ(rect.origin(), gfx::Point([content_layer position])); |
| 322 EXPECT_EQ(gfx::Rect(rect.size()), gfx::Rect([content_layer bounds])); | 324 EXPECT_EQ(gfx::Rect(rect.size()), gfx::Rect([content_layer bounds])); |
| 323 } | 325 } |
| 324 | 326 |
| 325 // Change the rect position. | 327 // Change the rect position. |
| 326 { | 328 { |
| 327 rect = gfx::Rect(gfx::Point(16, 4), rect.size()); | 329 rect = gfx::Rect(gfx::Point(16, 4), rect.size()); |
| 328 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); | 330 std::unique_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 329 result = new_ca_layer_tree->ScheduleCALayer( | 331 result = new_ca_layer_tree->ScheduleCALayer( |
| 330 is_clipped, | 332 is_clipped, |
| 331 clip_rect, | 333 clip_rect, |
| 332 sorting_context_id, | 334 sorting_context_id, |
| 333 transform, | 335 transform, |
| 334 nullptr, | 336 nullptr, |
| 335 contents_rect, | 337 contents_rect, |
| 336 rect, | 338 rect, |
| 337 background_color, | 339 background_color, |
| 338 edge_aa_mask, | 340 edge_aa_mask, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 354 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 356 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
| 355 | 357 |
| 356 // Validate the content layer. | 358 // Validate the content layer. |
| 357 EXPECT_EQ(rect.origin(), gfx::Point([content_layer position])); | 359 EXPECT_EQ(rect.origin(), gfx::Point([content_layer position])); |
| 358 EXPECT_EQ(gfx::Rect(rect.size()), gfx::Rect([content_layer bounds])); | 360 EXPECT_EQ(gfx::Rect(rect.size()), gfx::Rect([content_layer bounds])); |
| 359 } | 361 } |
| 360 | 362 |
| 361 // Change the opacity. | 363 // Change the opacity. |
| 362 { | 364 { |
| 363 opacity = 1.0f; | 365 opacity = 1.0f; |
| 364 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); | 366 std::unique_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 365 result = new_ca_layer_tree->ScheduleCALayer( | 367 result = new_ca_layer_tree->ScheduleCALayer( |
| 366 is_clipped, | 368 is_clipped, |
| 367 clip_rect, | 369 clip_rect, |
| 368 sorting_context_id, | 370 sorting_context_id, |
| 369 transform, | 371 transform, |
| 370 nullptr, | 372 nullptr, |
| 371 contents_rect, | 373 contents_rect, |
| 372 rect, | 374 rect, |
| 373 background_color, | 375 background_color, |
| 374 edge_aa_mask, | 376 edge_aa_mask, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 389 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 391 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
| 390 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 392 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
| 391 | 393 |
| 392 // Validate the content layer. | 394 // Validate the content layer. |
| 393 EXPECT_EQ(opacity, [content_layer opacity]); | 395 EXPECT_EQ(opacity, [content_layer opacity]); |
| 394 } | 396 } |
| 395 | 397 |
| 396 // Add the clipping and IOSurface contents back. | 398 // Add the clipping and IOSurface contents back. |
| 397 { | 399 { |
| 398 is_clipped = true; | 400 is_clipped = true; |
| 399 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); | 401 std::unique_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 400 result = new_ca_layer_tree->ScheduleCALayer( | 402 result = new_ca_layer_tree->ScheduleCALayer( |
| 401 is_clipped, | 403 is_clipped, |
| 402 clip_rect, | 404 clip_rect, |
| 403 sorting_context_id, | 405 sorting_context_id, |
| 404 transform, | 406 transform, |
| 405 io_surface, | 407 io_surface, |
| 406 contents_rect, | 408 contents_rect, |
| 407 rect, | 409 rect, |
| 408 background_color, | 410 background_color, |
| 409 edge_aa_mask, | 411 edge_aa_mask, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 425 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 427 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
| 426 | 428 |
| 427 // Validate the content layer. | 429 // Validate the content layer. |
| 428 EXPECT_EQ(static_cast<id>(io_surface.get()), [content_layer contents]); | 430 EXPECT_EQ(static_cast<id>(io_surface.get()), [content_layer contents]); |
| 429 EXPECT_EQ(kCALayerBottomEdge, [content_layer edgeAntialiasingMask]); | 431 EXPECT_EQ(kCALayerBottomEdge, [content_layer edgeAntialiasingMask]); |
| 430 } | 432 } |
| 431 | 433 |
| 432 // Change the scale factor. This should result in a new tree being created. | 434 // Change the scale factor. This should result in a new tree being created. |
| 433 { | 435 { |
| 434 scale_factor = 2.0f; | 436 scale_factor = 2.0f; |
| 435 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); | 437 std::unique_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 436 result = new_ca_layer_tree->ScheduleCALayer( | 438 result = new_ca_layer_tree->ScheduleCALayer( |
| 437 is_clipped, | 439 is_clipped, |
| 438 clip_rect, | 440 clip_rect, |
| 439 sorting_context_id, | 441 sorting_context_id, |
| 440 transform, | 442 transform, |
| 441 io_surface, | 443 io_surface, |
| 442 contents_rect, | 444 contents_rect, |
| 443 rect, | 445 rect, |
| 444 background_color, | 446 background_color, |
| 445 edge_aa_mask, | 447 edge_aa_mask, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 // * 1 non-flat (new sorting context layer) | 521 // * 1 non-flat (new sorting context layer) |
| 520 // * 2 flat and the same (new sorting context layer, 1 transform layer) | 522 // * 2 flat and the same (new sorting context layer, 1 transform layer) |
| 521 gfx::Transform transforms[5]; | 523 gfx::Transform transforms[5]; |
| 522 transforms[0].Translate(10, 10); | 524 transforms[0].Translate(10, 10); |
| 523 transforms[1].RotateAboutZAxis(45.0f); | 525 transforms[1].RotateAboutZAxis(45.0f); |
| 524 transforms[2].RotateAboutYAxis(45.0f); | 526 transforms[2].RotateAboutYAxis(45.0f); |
| 525 transforms[3].Translate(10, 10); | 527 transforms[3].Translate(10, 10); |
| 526 transforms[4].Translate(10, 10); | 528 transforms[4].Translate(10, 10); |
| 527 | 529 |
| 528 // Schedule and commit the layers. | 530 // Schedule and commit the layers. |
| 529 scoped_ptr<CALayerTree> ca_layer_tree(new CALayerTree); | 531 std::unique_ptr<CALayerTree> ca_layer_tree(new CALayerTree); |
| 530 for (size_t i = 0; i < 5; ++i) { | 532 for (size_t i = 0; i < 5; ++i) { |
| 531 bool result = ca_layer_tree->ScheduleCALayer( | 533 bool result = ca_layer_tree->ScheduleCALayer( |
| 532 is_clipped, | 534 is_clipped, |
| 533 clip_rect, | 535 clip_rect, |
| 534 sorting_context_id, | 536 sorting_context_id, |
| 535 transforms[i], | 537 transforms[i], |
| 536 io_surfaces[i], | 538 io_surfaces[i], |
| 537 contents_rect, | 539 contents_rect, |
| 538 rect, | 540 rect, |
| 539 background_color, | 541 background_color, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 float scale_factor = 1.0f; | 606 float scale_factor = 1.0f; |
| 605 | 607 |
| 606 // We'll use the IOSurface contents to identify the content layers. | 608 // We'll use the IOSurface contents to identify the content layers. |
| 607 base::ScopedCFTypeRef<IOSurfaceRef> io_surfaces[3]; | 609 base::ScopedCFTypeRef<IOSurfaceRef> io_surfaces[3]; |
| 608 for (size_t i = 0; i < 3; ++i) { | 610 for (size_t i = 0; i < 3; ++i) { |
| 609 io_surfaces[i].reset(gfx::CreateIOSurface( | 611 io_surfaces[i].reset(gfx::CreateIOSurface( |
| 610 gfx::Size(256, 256), gfx::BufferFormat::BGRA_8888)); | 612 gfx::Size(256, 256), gfx::BufferFormat::BGRA_8888)); |
| 611 } | 613 } |
| 612 | 614 |
| 613 // Schedule and commit the layers. | 615 // Schedule and commit the layers. |
| 614 scoped_ptr<CALayerTree> ca_layer_tree(new CALayerTree); | 616 std::unique_ptr<CALayerTree> ca_layer_tree(new CALayerTree); |
| 615 for (size_t i = 0; i < 3; ++i) { | 617 for (size_t i = 0; i < 3; ++i) { |
| 616 bool result = ca_layer_tree->ScheduleCALayer( | 618 bool result = ca_layer_tree->ScheduleCALayer( |
| 617 is_clipped, | 619 is_clipped, |
| 618 clip_rect, | 620 clip_rect, |
| 619 sorting_context_ids[i], | 621 sorting_context_ids[i], |
| 620 transform, | 622 transform, |
| 621 io_surfaces[i], | 623 io_surfaces[i], |
| 622 contents_rect, | 624 contents_rect, |
| 623 rect, | 625 rect, |
| 624 background_color, | 626 background_color, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 float opacity = 1.0f; | 676 float opacity = 1.0f; |
| 675 | 677 |
| 676 // Vary the clipping parameters within sorting contexts. | 678 // Vary the clipping parameters within sorting contexts. |
| 677 bool is_clippeds[3] = { true, true, false}; | 679 bool is_clippeds[3] = { true, true, false}; |
| 678 gfx::Rect clip_rects[3] = { | 680 gfx::Rect clip_rects[3] = { |
| 679 gfx::Rect(0, 0, 16, 16), | 681 gfx::Rect(0, 0, 16, 16), |
| 680 gfx::Rect(4, 8, 16, 32), | 682 gfx::Rect(4, 8, 16, 32), |
| 681 gfx::Rect(0, 0, 16, 16) | 683 gfx::Rect(0, 0, 16, 16) |
| 682 }; | 684 }; |
| 683 | 685 |
| 684 scoped_ptr<CALayerTree> ca_layer_tree(new CALayerTree); | 686 std::unique_ptr<CALayerTree> ca_layer_tree(new CALayerTree); |
| 685 // First send the various clip parameters to sorting context zero. This is | 687 // First send the various clip parameters to sorting context zero. This is |
| 686 // legitimate. | 688 // legitimate. |
| 687 for (size_t i = 0; i < 3; ++i) { | 689 for (size_t i = 0; i < 3; ++i) { |
| 688 int sorting_context_id = 0; | 690 int sorting_context_id = 0; |
| 689 bool result = ca_layer_tree->ScheduleCALayer( | 691 bool result = ca_layer_tree->ScheduleCALayer( |
| 690 is_clippeds[i], | 692 is_clippeds[i], |
| 691 clip_rects[i], | 693 clip_rects[i], |
| 692 sorting_context_id, | 694 sorting_context_id, |
| 693 transform, | 695 transform, |
| 694 io_surface, | 696 io_surface, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 int sorting_context_id = 0; | 748 int sorting_context_id = 0; |
| 747 gfx::Transform transform; | 749 gfx::Transform transform; |
| 748 gfx::RectF contents_rect(0.0f, 0.0f, 1.0f, 1.0f); | 750 gfx::RectF contents_rect(0.0f, 0.0f, 1.0f, 1.0f); |
| 749 gfx::Rect rect(16, 32, 64, 128); | 751 gfx::Rect rect(16, 32, 64, 128); |
| 750 unsigned background_color = SkColorSetARGB(0xFF, 0xFF, 0, 0); | 752 unsigned background_color = SkColorSetARGB(0xFF, 0xFF, 0, 0); |
| 751 unsigned edge_aa_mask = GL_CA_LAYER_EDGE_LEFT_CHROMIUM; | 753 unsigned edge_aa_mask = GL_CA_LAYER_EDGE_LEFT_CHROMIUM; |
| 752 float opacity = 0.5f; | 754 float opacity = 0.5f; |
| 753 float scale_factor = 1.0f; | 755 float scale_factor = 1.0f; |
| 754 bool result = false; | 756 bool result = false; |
| 755 | 757 |
| 756 scoped_ptr<CALayerTree> ca_layer_tree; | 758 std::unique_ptr<CALayerTree> ca_layer_tree; |
| 757 CALayer* root_layer = nil; | 759 CALayer* root_layer = nil; |
| 758 CALayer* clip_and_sorting_layer = nil; | 760 CALayer* clip_and_sorting_layer = nil; |
| 759 CALayer* transform_layer = nil; | 761 CALayer* transform_layer = nil; |
| 760 CALayer* content_layer1 = nil; | 762 CALayer* content_layer1 = nil; |
| 761 CALayer* content_layer2 = nil; | 763 CALayer* content_layer2 = nil; |
| 762 CALayer* content_layer3 = nil; | 764 CALayer* content_layer3 = nil; |
| 763 | 765 |
| 764 // Validate the initial values. | 766 // Validate the initial values. |
| 765 { | 767 { |
| 766 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); | 768 std::unique_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 767 result = new_ca_layer_tree->ScheduleCALayer( | 769 result = new_ca_layer_tree->ScheduleCALayer( |
| 768 is_clipped, clip_rect, sorting_context_id, transform, io_surface, | 770 is_clipped, clip_rect, sorting_context_id, transform, io_surface, |
| 769 contents_rect, rect, background_color, edge_aa_mask, opacity); | 771 contents_rect, rect, background_color, edge_aa_mask, opacity); |
| 770 EXPECT_TRUE(result); | 772 EXPECT_TRUE(result); |
| 771 new_ca_layer_tree->CommitScheduledCALayers( | 773 new_ca_layer_tree->CommitScheduledCALayers( |
| 772 superlayer_, std::move(ca_layer_tree), scale_factor); | 774 superlayer_, std::move(ca_layer_tree), scale_factor); |
| 773 std::swap(new_ca_layer_tree, ca_layer_tree); | 775 std::swap(new_ca_layer_tree, ca_layer_tree); |
| 774 | 776 |
| 775 // Validate the tree structure. | 777 // Validate the tree structure. |
| 776 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 778 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
| 777 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 779 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
| 778 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 780 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
| 779 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; | 781 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
| 780 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 782 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
| 781 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; | 783 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
| 782 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 784 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
| 783 content_layer1 = [[transform_layer sublayers] objectAtIndex:0]; | 785 content_layer1 = [[transform_layer sublayers] objectAtIndex:0]; |
| 784 | 786 |
| 785 // Validate the content layer. | 787 // Validate the content layer. |
| 786 EXPECT_FALSE([content_layer1 | 788 EXPECT_FALSE([content_layer1 |
| 787 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 789 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 788 } | 790 } |
| 789 | 791 |
| 790 io_surface.reset(gfx::CreateIOSurface(gfx::Size(256, 256), | 792 io_surface.reset(gfx::CreateIOSurface(gfx::Size(256, 256), |
| 791 gfx::BufferFormat::YUV_420_BIPLANAR)); | 793 gfx::BufferFormat::YUV_420_BIPLANAR)); |
| 792 | 794 |
| 793 // Pass another frame. | 795 // Pass another frame. |
| 794 { | 796 { |
| 795 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); | 797 std::unique_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 796 result = new_ca_layer_tree->ScheduleCALayer( | 798 result = new_ca_layer_tree->ScheduleCALayer( |
| 797 is_clipped, clip_rect, sorting_context_id, transform, io_surface, | 799 is_clipped, clip_rect, sorting_context_id, transform, io_surface, |
| 798 contents_rect, rect, background_color, edge_aa_mask, opacity); | 800 contents_rect, rect, background_color, edge_aa_mask, opacity); |
| 799 EXPECT_TRUE(result); | 801 EXPECT_TRUE(result); |
| 800 new_ca_layer_tree->CommitScheduledCALayers( | 802 new_ca_layer_tree->CommitScheduledCALayers( |
| 801 superlayer_, std::move(ca_layer_tree), scale_factor); | 803 superlayer_, std::move(ca_layer_tree), scale_factor); |
| 802 std::swap(new_ca_layer_tree, ca_layer_tree); | 804 std::swap(new_ca_layer_tree, ca_layer_tree); |
| 803 | 805 |
| 804 // Validate the tree structure. | 806 // Validate the tree structure. |
| 805 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 807 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 816 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 818 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 817 EXPECT_EQ(content_layer2, content_layer1); | 819 EXPECT_EQ(content_layer2, content_layer1); |
| 818 } | 820 } |
| 819 | 821 |
| 820 io_surface.reset(gfx::CreateIOSurface(gfx::Size(256, 256), | 822 io_surface.reset(gfx::CreateIOSurface(gfx::Size(256, 256), |
| 821 gfx::BufferFormat::YUV_420_BIPLANAR)); | 823 gfx::BufferFormat::YUV_420_BIPLANAR)); |
| 822 | 824 |
| 823 // Pass a frame that is clipped. | 825 // Pass a frame that is clipped. |
| 824 contents_rect = gfx::RectF(0, 0, 1, 0.9); | 826 contents_rect = gfx::RectF(0, 0, 1, 0.9); |
| 825 { | 827 { |
| 826 scoped_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); | 828 std::unique_ptr<CALayerTree> new_ca_layer_tree(new CALayerTree); |
| 827 result = new_ca_layer_tree->ScheduleCALayer( | 829 result = new_ca_layer_tree->ScheduleCALayer( |
| 828 is_clipped, clip_rect, sorting_context_id, transform, io_surface, | 830 is_clipped, clip_rect, sorting_context_id, transform, io_surface, |
| 829 contents_rect, rect, background_color, edge_aa_mask, opacity); | 831 contents_rect, rect, background_color, edge_aa_mask, opacity); |
| 830 EXPECT_TRUE(result); | 832 EXPECT_TRUE(result); |
| 831 new_ca_layer_tree->CommitScheduledCALayers( | 833 new_ca_layer_tree->CommitScheduledCALayers( |
| 832 superlayer_, std::move(ca_layer_tree), scale_factor); | 834 superlayer_, std::move(ca_layer_tree), scale_factor); |
| 833 std::swap(new_ca_layer_tree, ca_layer_tree); | 835 std::swap(new_ca_layer_tree, ca_layer_tree); |
| 834 | 836 |
| 835 // Validate the tree structure. | 837 // Validate the tree structure. |
| 836 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 838 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
| 837 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; | 839 root_layer = [[superlayer_ sublayers] objectAtIndex:0]; |
| 838 EXPECT_EQ(1u, [[root_layer sublayers] count]); | 840 EXPECT_EQ(1u, [[root_layer sublayers] count]); |
| 839 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; | 841 clip_and_sorting_layer = [[root_layer sublayers] objectAtIndex:0]; |
| 840 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); | 842 EXPECT_EQ(1u, [[clip_and_sorting_layer sublayers] count]); |
| 841 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; | 843 transform_layer = [[clip_and_sorting_layer sublayers] objectAtIndex:0]; |
| 842 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 844 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
| 843 content_layer3 = [[transform_layer sublayers] objectAtIndex:0]; | 845 content_layer3 = [[transform_layer sublayers] objectAtIndex:0]; |
| 844 | 846 |
| 845 // Validate the content layer. | 847 // Validate the content layer. |
| 846 EXPECT_FALSE([content_layer3 | 848 EXPECT_FALSE([content_layer3 |
| 847 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 849 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 848 EXPECT_EQ(content_layer3, content_layer2); | 850 EXPECT_EQ(content_layer3, content_layer2); |
| 849 } | 851 } |
| 850 } | 852 } |
| 851 | 853 |
| 852 } // namespace gpu | 854 } // namespace gpu |
| OLD | NEW |