| 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 <AVFoundation/AVFoundation.h> | 5 #include <AVFoundation/AVFoundation.h> |
| 6 #include <memory> | 6 #include <memory> |
| 7 | 7 |
| 8 #include "base/mac/sdk_forward_declarations.h" | 8 #include "base/mac/sdk_forward_declarations.h" |
| 9 #include "gpu/GLES2/gl2extchromium.h" | 9 #include "gpu/GLES2/gl2extchromium.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 int sorting_context_id = 0; | 32 int sorting_context_id = 0; |
| 33 gfx::Transform transform; | 33 gfx::Transform transform; |
| 34 gfx::RectF contents_rect = gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f); | 34 gfx::RectF contents_rect = gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f); |
| 35 gfx::Rect rect = gfx::Rect(0, 0, 256, 256); | 35 gfx::Rect rect = gfx::Rect(0, 0, 256, 256); |
| 36 unsigned background_color = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF); | 36 unsigned background_color = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF); |
| 37 unsigned edge_aa_mask = 0; | 37 unsigned edge_aa_mask = 0; |
| 38 float opacity = 1.0f; | 38 float opacity = 1.0f; |
| 39 float scale_factor = 1.0f; | 39 float scale_factor = 1.0f; |
| 40 unsigned filter = GL_LINEAR; | 40 unsigned filter = GL_LINEAR; |
| 41 scoped_refptr<gl::GLImageIOSurface> gl_image; | 41 scoped_refptr<gl::GLImageIOSurface> gl_image; |
| 42 ui::CARendererLayerParams::FilterEffects filter_effects; | |
| 43 }; | 42 }; |
| 44 | 43 |
| 45 scoped_refptr<gl::GLImageIOSurface> CreateGLImage(const gfx::Size& size, | 44 scoped_refptr<gl::GLImageIOSurface> CreateGLImage(const gfx::Size& size, |
| 46 gfx::BufferFormat format, | 45 gfx::BufferFormat format, |
| 47 bool video) { | 46 bool video) { |
| 48 scoped_refptr<gl::GLImageIOSurface> gl_image( | 47 scoped_refptr<gl::GLImageIOSurface> gl_image( |
| 49 new gl::GLImageIOSurface(size, GL_RGBA)); | 48 new gl::GLImageIOSurface(size, GL_RGBA)); |
| 50 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( | 49 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( |
| 51 gfx::CreateIOSurface(size, format)); | 50 gfx::CreateIOSurface(size, format)); |
| 52 if (video) { | 51 if (video) { |
| 53 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; | 52 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; |
| 54 CVPixelBufferCreateWithIOSurface(nullptr, io_surface, nullptr, | 53 CVPixelBufferCreateWithIOSurface(nullptr, io_surface, nullptr, |
| 55 cv_pixel_buffer.InitializeInto()); | 54 cv_pixel_buffer.InitializeInto()); |
| 56 gl_image->InitializeWithCVPixelBuffer(cv_pixel_buffer, | 55 gl_image->InitializeWithCVPixelBuffer(cv_pixel_buffer, |
| 57 gfx::GenericSharedMemoryId(), format); | 56 gfx::GenericSharedMemoryId(), format); |
| 58 } else { | 57 } else { |
| 59 gl_image->Initialize(io_surface, gfx::GenericSharedMemoryId(), format); | 58 gl_image->Initialize(io_surface, gfx::GenericSharedMemoryId(), format); |
| 60 } | 59 } |
| 61 return gl_image; | 60 return gl_image; |
| 62 } | 61 } |
| 63 | 62 |
| 64 bool ScheduleCALayer(ui::CARendererLayerTree* tree, | 63 bool ScheduleCALayer(ui::CARendererLayerTree* tree, |
| 65 CALayerProperties* properties) { | 64 CALayerProperties* properties) { |
| 66 ui::CARendererLayerParams params = ui::CARendererLayerParams( | 65 return tree->ScheduleCALayer(ui::CARendererLayerParams( |
| 67 properties->is_clipped, properties->clip_rect, | 66 properties->is_clipped, properties->clip_rect, |
| 68 properties->sorting_context_id, properties->transform, | 67 properties->sorting_context_id, properties->transform, |
| 69 properties->gl_image.get(), properties->contents_rect, properties->rect, | 68 properties->gl_image.get(), properties->contents_rect, properties->rect, |
| 70 properties->background_color, properties->edge_aa_mask, | 69 properties->background_color, properties->edge_aa_mask, |
| 71 properties->opacity, properties->filter); | 70 properties->opacity, properties->filter)); |
| 72 params.filter_effects = properties->filter_effects; | |
| 73 return tree->ScheduleCALayer(params); | |
| 74 } | 71 } |
| 75 | 72 |
| 76 void UpdateCALayerTree(std::unique_ptr<ui::CARendererLayerTree>& ca_layer_tree, | 73 void UpdateCALayerTree(std::unique_ptr<ui::CARendererLayerTree>& ca_layer_tree, |
| 77 CALayerProperties* properties, | 74 CALayerProperties* properties, |
| 78 CALayer* superlayer) { | 75 CALayer* superlayer) { |
| 79 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( | 76 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( |
| 80 new ui::CARendererLayerTree); | 77 new ui::CARendererLayerTree); |
| 81 bool result = ScheduleCALayer(new_ca_layer_tree.get(), properties); | 78 bool result = ScheduleCALayer(new_ca_layer_tree.get(), properties); |
| 82 EXPECT_TRUE(result); | 79 EXPECT_TRUE(result); |
| 83 new_ca_layer_tree->CommitScheduledCALayers( | 80 new_ca_layer_tree->CommitScheduledCALayers( |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 EXPECT_EQ(transform_layer, | 355 EXPECT_EQ(transform_layer, |
| 359 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); | 356 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); |
| 360 EXPECT_EQ(1u, [[transform_layer sublayers] count]); | 357 EXPECT_EQ(1u, [[transform_layer sublayers] count]); |
| 361 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); | 358 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); |
| 362 | 359 |
| 363 // Validate the content layer. | 360 // Validate the content layer. |
| 364 EXPECT_NSEQ(kCAFilterNearest, [content_layer minificationFilter]); | 361 EXPECT_NSEQ(kCAFilterNearest, [content_layer minificationFilter]); |
| 365 EXPECT_NSEQ(kCAFilterNearest, [content_layer magnificationFilter]); | 362 EXPECT_NSEQ(kCAFilterNearest, [content_layer magnificationFilter]); |
| 366 } | 363 } |
| 367 | 364 |
| 368 // Add every filter effect. | |
| 369 { | |
| 370 using FilterEffectType = ui::CARendererLayerParams::FilterEffectType; | |
| 371 for (int i = static_cast<int>(FilterEffectType::MIN); | |
| 372 i <= static_cast<int>(FilterEffectType::MAX); i++) { | |
| 373 ui::CARendererLayerParams::FilterEffect filter_effect; | |
| 374 filter_effect.type = static_cast<FilterEffectType>(i); | |
| 375 filter_effect.amount = i * 0.05 + 0.1; | |
| 376 properties.filter_effects.push_back(filter_effect); | |
| 377 } | |
| 378 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); | |
| 379 | |
| 380 // Validate the content layer. | |
| 381 EXPECT_EQ(9u, [[content_layer filters] count]); | |
| 382 EXPECT_GT([content_layer shadowRadius], 0.0); | |
| 383 EXPECT_LT([content_layer shadowRadius], 1.0); | |
| 384 } | |
| 385 | |
| 386 // Remove every filter effect. | |
| 387 { | |
| 388 properties.filter_effects.clear(); | |
| 389 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); | |
| 390 | |
| 391 // Validate the content layer. | |
| 392 EXPECT_EQ(0u, [[content_layer filters] count]); | |
| 393 EXPECT_EQ(0.0, [content_layer shadowRadius]); | |
| 394 } | |
| 395 | |
| 396 // Add the clipping and IOSurface contents back. | 365 // Add the clipping and IOSurface contents back. |
| 397 { | 366 { |
| 398 properties.is_clipped = true; | 367 properties.is_clipped = true; |
| 399 properties.gl_image = | 368 properties.gl_image = |
| 400 CreateGLImage(gfx::Size(256, 256), gfx::BufferFormat::BGRA_8888, false); | 369 CreateGLImage(gfx::Size(256, 256), gfx::BufferFormat::BGRA_8888, false); |
| 401 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); | 370 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); |
| 402 | 371 |
| 403 // Validate the tree structure. | 372 // Validate the tree structure. |
| 404 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); | 373 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); |
| 405 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); | 374 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:0]; | 899 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:0]; |
| 931 | 900 |
| 932 // Validate the content layer and fullscreen low power mode. | 901 // Validate the content layer and fullscreen low power mode. |
| 933 EXPECT_TRUE([content_layer | 902 EXPECT_TRUE([content_layer |
| 934 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); | 903 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); |
| 935 EXPECT_FALSE(fullscreen_low_power_valid); | 904 EXPECT_FALSE(fullscreen_low_power_valid); |
| 936 } | 905 } |
| 937 } | 906 } |
| 938 | 907 |
| 939 } // namespace gpu | 908 } // namespace gpu |
| OLD | NEW |