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

Side by Side Diff: ui/accelerated_widget_mac/ca_layer_tree_unittest_mac.mm

Issue 2186693002: Implement filter effects in Core Animation using CAFilters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp50_base
Patch Set: Comments from piman. Created 4 years, 4 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 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
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;
42 }; 43 };
43 44
44 scoped_refptr<gl::GLImageIOSurface> CreateGLImage(const gfx::Size& size, 45 scoped_refptr<gl::GLImageIOSurface> CreateGLImage(const gfx::Size& size,
45 gfx::BufferFormat format, 46 gfx::BufferFormat format,
46 bool video) { 47 bool video) {
47 scoped_refptr<gl::GLImageIOSurface> gl_image( 48 scoped_refptr<gl::GLImageIOSurface> gl_image(
48 new gl::GLImageIOSurface(size, GL_RGBA)); 49 new gl::GLImageIOSurface(size, GL_RGBA));
49 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( 50 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(
50 gfx::CreateIOSurface(size, format)); 51 gfx::CreateIOSurface(size, format));
51 if (video) { 52 if (video) {
52 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer; 53 base::ScopedCFTypeRef<CVPixelBufferRef> cv_pixel_buffer;
53 CVPixelBufferCreateWithIOSurface(nullptr, io_surface, nullptr, 54 CVPixelBufferCreateWithIOSurface(nullptr, io_surface, nullptr,
54 cv_pixel_buffer.InitializeInto()); 55 cv_pixel_buffer.InitializeInto());
55 gl_image->InitializeWithCVPixelBuffer(cv_pixel_buffer, 56 gl_image->InitializeWithCVPixelBuffer(cv_pixel_buffer,
56 gfx::GenericSharedMemoryId(), format); 57 gfx::GenericSharedMemoryId(), format);
57 } else { 58 } else {
58 gl_image->Initialize(io_surface, gfx::GenericSharedMemoryId(), format); 59 gl_image->Initialize(io_surface, gfx::GenericSharedMemoryId(), format);
59 } 60 }
60 return gl_image; 61 return gl_image;
61 } 62 }
62 63
63 bool ScheduleCALayer(ui::CARendererLayerTree* tree, 64 bool ScheduleCALayer(ui::CARendererLayerTree* tree,
64 CALayerProperties* properties) { 65 CALayerProperties* properties) {
65 return tree->ScheduleCALayer(ui::CARendererLayerParams( 66 ui::CARendererLayerParams params = ui::CARendererLayerParams(
66 properties->is_clipped, properties->clip_rect, 67 properties->is_clipped, properties->clip_rect,
67 properties->sorting_context_id, properties->transform, 68 properties->sorting_context_id, properties->transform,
68 properties->gl_image.get(), properties->contents_rect, properties->rect, 69 properties->gl_image.get(), properties->contents_rect, properties->rect,
69 properties->background_color, properties->edge_aa_mask, 70 properties->background_color, properties->edge_aa_mask,
70 properties->opacity, properties->filter)); 71 properties->opacity, properties->filter);
72 params.filter_effects = properties->filter_effects;
73 return tree->ScheduleCALayer(params);
71 } 74 }
72 75
73 void UpdateCALayerTree(std::unique_ptr<ui::CARendererLayerTree>& ca_layer_tree, 76 void UpdateCALayerTree(std::unique_ptr<ui::CARendererLayerTree>& ca_layer_tree,
74 CALayerProperties* properties, 77 CALayerProperties* properties,
75 CALayer* superlayer) { 78 CALayer* superlayer) {
76 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree( 79 std::unique_ptr<ui::CARendererLayerTree> new_ca_layer_tree(
77 new ui::CARendererLayerTree); 80 new ui::CARendererLayerTree);
78 bool result = ScheduleCALayer(new_ca_layer_tree.get(), properties); 81 bool result = ScheduleCALayer(new_ca_layer_tree.get(), properties);
79 EXPECT_TRUE(result); 82 EXPECT_TRUE(result);
80 new_ca_layer_tree->CommitScheduledCALayers( 83 new_ca_layer_tree->CommitScheduledCALayers(
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 EXPECT_EQ(transform_layer, 358 EXPECT_EQ(transform_layer,
356 [[clip_and_sorting_layer sublayers] objectAtIndex:0]); 359 [[clip_and_sorting_layer sublayers] objectAtIndex:0]);
357 EXPECT_EQ(1u, [[transform_layer sublayers] count]); 360 EXPECT_EQ(1u, [[transform_layer sublayers] count]);
358 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]); 361 EXPECT_EQ(content_layer, [[transform_layer sublayers] objectAtIndex:0]);
359 362
360 // Validate the content layer. 363 // Validate the content layer.
361 EXPECT_NSEQ(kCAFilterNearest, [content_layer minificationFilter]); 364 EXPECT_NSEQ(kCAFilterNearest, [content_layer minificationFilter]);
362 EXPECT_NSEQ(kCAFilterNearest, [content_layer magnificationFilter]); 365 EXPECT_NSEQ(kCAFilterNearest, [content_layer magnificationFilter]);
363 } 366 }
364 367
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
365 // Add the clipping and IOSurface contents back. 396 // Add the clipping and IOSurface contents back.
366 { 397 {
367 properties.is_clipped = true; 398 properties.is_clipped = true;
368 properties.gl_image = 399 properties.gl_image =
369 CreateGLImage(gfx::Size(256, 256), gfx::BufferFormat::BGRA_8888, false); 400 CreateGLImage(gfx::Size(256, 256), gfx::BufferFormat::BGRA_8888, false);
370 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_); 401 UpdateCALayerTree(ca_layer_tree, &properties, superlayer_);
371 402
372 // Validate the tree structure. 403 // Validate the tree structure.
373 EXPECT_EQ(1u, [[superlayer_ sublayers] count]); 404 EXPECT_EQ(1u, [[superlayer_ sublayers] count]);
374 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]); 405 EXPECT_EQ(root_layer, [[superlayer_ sublayers] objectAtIndex:0]);
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:0]; 930 CALayer* content_layer = [[transform_layer sublayers] objectAtIndex:0];
900 931
901 // Validate the content layer and fullscreen low power mode. 932 // Validate the content layer and fullscreen low power mode.
902 EXPECT_TRUE([content_layer 933 EXPECT_TRUE([content_layer
903 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]); 934 isKindOfClass:NSClassFromString(@"AVSampleBufferDisplayLayer")]);
904 EXPECT_FALSE(fullscreen_low_power_valid); 935 EXPECT_FALSE(fullscreen_low_power_valid);
905 } 936 }
906 } 937 }
907 938
908 } // namespace gpu 939 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder.cc ('k') | ui/accelerated_widget_mac/ca_renderer_layer_tree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698