summaryrefslogtreecommitdiff
path: root/chromium/cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-11-20 15:06:40 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-11-22 11:48:58 +0000
commitdaa093eea7c773db06799a13bd7e4e2e2a9f8f14 (patch)
tree96cc5e7b9194c1b29eab927730bfa419e7111c25 /chromium/cc
parentbe59a35641616a4cf23c4a13fa0632624b021c1b (diff)
downloadqtwebengine-chromium-daa093eea7c773db06799a13bd7e4e2e2a9f8f14.tar.gz
BASELINE: Update Chromium to 63.0.3239.58
Change-Id: Ia93b322a00ba4dd4004f3bcf1254063ba90e1605 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/cc')
-rw-r--r--chromium/cc/BUILD.gn138
-rw-r--r--chromium/cc/DEPS2
-rw-r--r--chromium/cc/OWNERS1
-rw-r--r--chromium/cc/README.md10
-rw-r--r--chromium/cc/animation/BUILD.gn2
-rw-r--r--chromium/cc/animation/animation.cc6
-rw-r--r--chromium/cc/animation/animation.h1
-rw-r--r--chromium/cc/animation/animation_host.cc49
-rw-r--r--chromium/cc/animation/animation_host.h9
-rw-r--r--chromium/cc/animation/animation_player.cc1110
-rw-r--r--chromium/cc/animation/animation_player.h159
-rw-r--r--chromium/cc/animation/animation_player_unittest.cc88
-rw-r--r--chromium/cc/animation/animation_ticker.cc1030
-rw-r--r--chromium/cc/animation/animation_ticker.h186
-rw-r--r--chromium/cc/animation/animation_timeline.cc9
-rw-r--r--chromium/cc/animation/animation_unittest.cc13
-rw-r--r--chromium/cc/animation/element_animations.cc154
-rw-r--r--chromium/cc/animation/element_animations.h26
-rw-r--r--chromium/cc/animation/element_animations_unittest.cc843
-rw-r--r--chromium/cc/animation/keyframed_animation_curve.cc34
-rw-r--r--chromium/cc/animation/timing_function.cc2
-rw-r--r--chromium/cc/animation/transform_operation.cc82
-rw-r--r--chromium/cc/animation/transform_operations.cc51
-rw-r--r--chromium/cc/base/delayed_unique_notifier_unittest.cc23
-rw-r--r--chromium/cc/base/filter_operation.cc3
-rw-r--r--chromium/cc/base/filter_operations.cc42
-rw-r--r--chromium/cc/base/filter_operations.h1
-rw-r--r--chromium/cc/base/filter_operations_unittest.cc71
-rw-r--r--chromium/cc/base/math_util.cc12
-rw-r--r--chromium/cc/base/math_util.h31
-rw-r--r--chromium/cc/base/render_surface_filters.cc7
-rw-r--r--chromium/cc/base/rolling_time_delta_history.h4
-rw-r--r--chromium/cc/benchmarks/rasterize_and_record_benchmark_impl.cc10
-rw-r--r--chromium/cc/blink/web_compositor_support_impl.cc2
-rw-r--r--chromium/cc/blink/web_content_layer_impl.cc2
-rw-r--r--chromium/cc/blink/web_display_item_list_impl.cc7
-rw-r--r--chromium/cc/blink/web_display_item_list_impl.h4
-rw-r--r--chromium/cc/blink/web_display_item_list_impl_unittest.cc6
-rw-r--r--chromium/cc/blink/web_layer_impl.cc16
-rw-r--r--chromium/cc/blink/web_layer_impl.h12
-rw-r--r--chromium/cc/input/layer_selection_bound.h4
-rw-r--r--chromium/cc/input/scroll_state.h2
-rw-r--r--chromium/cc/input/scroll_state_data.cc1
-rw-r--r--chromium/cc/input/scroll_state_data.h1
-rw-r--r--chromium/cc/input/selection.h34
-rw-r--r--chromium/cc/ipc/BUILD.gn30
-rw-r--r--chromium/cc/ipc/cc_param_traits.cc395
-rw-r--r--chromium/cc/ipc/cc_param_traits.h36
-rw-r--r--chromium/cc/ipc/cc_param_traits_macros.h72
-rw-r--r--chromium/cc/ipc/cc_param_traits_unittest.cc120
-rw-r--r--chromium/cc/ipc/cc_serialization_perftest.cc108
-rw-r--r--chromium/cc/ipc/copy_output_result.mojom18
-rw-r--r--chromium/cc/ipc/copy_output_result.typemap16
-rw-r--r--chromium/cc/ipc/copy_output_result_struct_traits.cc134
-rw-r--r--chromium/cc/ipc/copy_output_result_struct_traits.h42
-rw-r--r--chromium/cc/ipc/frame_sink_id.mojom10
-rw-r--r--chromium/cc/ipc/frame_sink_id.typemap11
-rw-r--r--chromium/cc/ipc/frame_sink_id_struct_traits.h31
-rw-r--r--chromium/cc/ipc/local_surface_id.mojom15
-rw-r--r--chromium/cc/ipc/local_surface_id.typemap11
-rw-r--r--chromium/cc/ipc/local_surface_id_struct_traits.h34
-rw-r--r--chromium/cc/ipc/struct_traits_unittest.cc185
-rw-r--r--chromium/cc/ipc/texture_mailbox.mojom22
-rw-r--r--chromium/cc/ipc/texture_mailbox.typemap11
-rw-r--r--chromium/cc/ipc/texture_mailbox_releaser.mojom14
-rw-r--r--chromium/cc/ipc/texture_mailbox_struct_traits.h77
-rw-r--r--chromium/cc/ipc/traits_test_service.mojom19
-rw-r--r--chromium/cc/ipc/typemaps.gni10
-rw-r--r--chromium/cc/layers/heads_up_display_layer.cc2
-rw-r--r--chromium/cc/layers/heads_up_display_layer_impl.cc28
-rw-r--r--chromium/cc/layers/heads_up_display_layer_impl.h8
-rw-r--r--chromium/cc/layers/heads_up_display_layer_impl_unittest.cc6
-rw-r--r--chromium/cc/layers/heads_up_display_unittest.cc2
-rw-r--r--chromium/cc/layers/layer.cc74
-rw-r--r--chromium/cc/layers/layer.h27
-rw-r--r--chromium/cc/layers/layer_client.h3
-rw-r--r--chromium/cc/layers/layer_impl.cc116
-rw-r--r--chromium/cc/layers/layer_impl.h64
-rw-r--r--chromium/cc/layers/layer_impl_test_properties.cc3
-rw-r--r--chromium/cc/layers/layer_impl_test_properties.h1
-rw-r--r--chromium/cc/layers/layer_impl_unittest.cc19
-rw-r--r--chromium/cc/layers/layer_position_constraint_unittest.cc13
-rw-r--r--chromium/cc/layers/layer_unittest.cc99
-rw-r--r--chromium/cc/layers/layer_utils.cc117
-rw-r--r--chromium/cc/layers/layer_utils.h29
-rw-r--r--chromium/cc/layers/layer_utils_unittest.cc585
-rw-r--r--chromium/cc/layers/nine_patch_generator.cc (renamed from chromium/cc/quads/nine_patch_generator.cc)11
-rw-r--r--chromium/cc/layers/nine_patch_generator.h (renamed from chromium/cc/quads/nine_patch_generator.h)13
-rw-r--r--chromium/cc/layers/nine_patch_generator_unittest.cc (renamed from chromium/cc/quads/nine_patch_generator_unittest.cc)2
-rw-r--r--chromium/cc/layers/nine_patch_layer.cc2
-rw-r--r--chromium/cc/layers/nine_patch_layer_impl.cc28
-rw-r--r--chromium/cc/layers/nine_patch_layer_impl.h6
-rw-r--r--chromium/cc/layers/nine_patch_layer_impl_unittest.cc28
-rw-r--r--chromium/cc/layers/painted_overlay_scrollbar_layer.cc2
-rw-r--r--chromium/cc/layers/painted_overlay_scrollbar_layer_impl.cc29
-rw-r--r--chromium/cc/layers/painted_overlay_scrollbar_layer_impl.h6
-rw-r--r--chromium/cc/layers/painted_scrollbar_layer.cc18
-rw-r--r--chromium/cc/layers/painted_scrollbar_layer_impl.cc21
-rw-r--r--chromium/cc/layers/painted_scrollbar_layer_impl.h4
-rw-r--r--chromium/cc/layers/painted_scrollbar_layer_impl_unittest.cc24
-rw-r--r--chromium/cc/layers/picture_image_layer.cc2
-rw-r--r--chromium/cc/layers/picture_image_layer_unittest.cc2
-rw-r--r--chromium/cc/layers/picture_layer.cc2
-rw-r--r--chromium/cc/layers/picture_layer.h4
-rw-r--r--chromium/cc/layers/picture_layer_impl.cc200
-rw-r--r--chromium/cc/layers/picture_layer_impl.h17
-rw-r--r--chromium/cc/layers/picture_layer_impl_unittest.cc305
-rw-r--r--chromium/cc/layers/picture_layer_unittest.cc2
-rw-r--r--chromium/cc/layers/recording_source.cc3
-rw-r--r--chromium/cc/layers/recording_source_unittest.cc51
-rw-r--r--chromium/cc/layers/render_surface_impl.cc77
-rw-r--r--chromium/cc/layers/render_surface_impl.h11
-rw-r--r--chromium/cc/layers/render_surface_impl_unittest.cc44
-rw-r--r--chromium/cc/layers/render_surface_unittest.cc16
-rw-r--r--chromium/cc/layers/scrollbar_layer_unittest.cc26
-rw-r--r--chromium/cc/layers/solid_color_layer.cc2
-rw-r--r--chromium/cc/layers/solid_color_layer_impl.cc24
-rw-r--r--chromium/cc/layers/solid_color_layer_impl.h5
-rw-r--r--chromium/cc/layers/solid_color_layer_impl_unittest.cc29
-rw-r--r--chromium/cc/layers/solid_color_scrollbar_layer.cc2
-rw-r--r--chromium/cc/layers/solid_color_scrollbar_layer_impl.cc13
-rw-r--r--chromium/cc/layers/solid_color_scrollbar_layer_impl.h2
-rw-r--r--chromium/cc/layers/surface_layer.cc12
-rw-r--r--chromium/cc/layers/surface_layer.h6
-rw-r--r--chromium/cc/layers/surface_layer_impl.cc67
-rw-r--r--chromium/cc/layers/surface_layer_impl.h21
-rw-r--r--chromium/cc/layers/surface_layer_impl_unittest.cc58
-rw-r--r--chromium/cc/layers/surface_layer_unittest.cc16
-rw-r--r--chromium/cc/layers/texture_layer.cc43
-rw-r--r--chromium/cc/layers/texture_layer.h26
-rw-r--r--chromium/cc/layers/texture_layer_client.h2
-rw-r--r--chromium/cc/layers/texture_layer_impl.cc61
-rw-r--r--chromium/cc/layers/texture_layer_impl.h34
-rw-r--r--chromium/cc/layers/texture_layer_impl_unittest.cc61
-rw-r--r--chromium/cc/layers/texture_layer_unittest.cc236
-rw-r--r--chromium/cc/layers/ui_resource_layer.cc2
-rw-r--r--chromium/cc/layers/ui_resource_layer_impl.cc46
-rw-r--r--chromium/cc/layers/ui_resource_layer_impl.h6
-rw-r--r--chromium/cc/layers/ui_resource_layer_impl_unittest.cc12
-rw-r--r--chromium/cc/layers/ui_resource_layer_unittest.cc2
-rw-r--r--chromium/cc/layers/video_frame_provider_client_impl.cc3
-rw-r--r--chromium/cc/layers/video_layer.cc2
-rw-r--r--chromium/cc/layers/video_layer_impl.cc63
-rw-r--r--chromium/cc/layers/video_layer_impl.h10
-rw-r--r--chromium/cc/layers/video_layer_impl_unittest.cc70
-rw-r--r--chromium/cc/output/DEPS9
-rw-r--r--chromium/cc/output/bsp_compare_result.h21
-rw-r--r--chromium/cc/output/bsp_tree.cc92
-rw-r--r--chromium/cc/output/bsp_tree.h111
-rw-r--r--chromium/cc/output/bsp_tree_perftest.cc188
-rw-r--r--chromium/cc/output/bsp_tree_unittest.cc377
-rw-r--r--chromium/cc/output/bsp_walk_action.cc45
-rw-r--r--chromium/cc/output/bsp_walk_action.h48
-rw-r--r--chromium/cc/output/ca_layer_overlay.cc344
-rw-r--r--chromium/cc/output/ca_layer_overlay.h87
-rw-r--r--chromium/cc/output/compositor_frame.cc17
-rw-r--r--chromium/cc/output/compositor_frame.h53
-rw-r--r--chromium/cc/output/compositor_frame_metadata.cc28
-rw-r--r--chromium/cc/output/compositor_frame_metadata.h126
-rw-r--r--chromium/cc/output/context_cache_controller_unittest.cc115
-rw-r--r--chromium/cc/output/dc_layer_overlay.cc416
-rw-r--r--chromium/cc/output/dc_layer_overlay.h159
-rw-r--r--chromium/cc/output/direct_renderer.cc671
-rw-r--r--chromium/cc/output/direct_renderer.h266
-rw-r--r--chromium/cc/output/layer_quad.cc126
-rw-r--r--chromium/cc/output/layer_quad.h113
-rw-r--r--chromium/cc/output/layer_quad_unittest.cc69
-rw-r--r--chromium/cc/output/output_surface.cc42
-rw-r--r--chromium/cc/output/output_surface.h138
-rw-r--r--chromium/cc/output/output_surface_client.h38
-rw-r--r--chromium/cc/output/output_surface_frame.cc18
-rw-r--r--chromium/cc/output/output_surface_frame.h44
-rw-r--r--chromium/cc/output/overlay_candidate.cc43
-rw-r--r--chromium/cc/output/overlay_candidate.h27
-rw-r--r--chromium/cc/output/overlay_candidate_validator.h43
-rw-r--r--chromium/cc/output/overlay_processor.cc206
-rw-r--r--chromium/cc/output/overlay_processor.h95
-rw-r--r--chromium/cc/output/overlay_strategy_fullscreen.cc71
-rw-r--r--chromium/cc/output/overlay_strategy_fullscreen.h36
-rw-r--r--chromium/cc/output/overlay_strategy_single_on_top.cc92
-rw-r--r--chromium/cc/output/overlay_strategy_single_on_top.h39
-rw-r--r--chromium/cc/output/overlay_strategy_underlay.cc66
-rw-r--r--chromium/cc/output/overlay_strategy_underlay.h39
-rw-r--r--chromium/cc/output/overlay_strategy_underlay_cast.cc67
-rw-r--r--chromium/cc/output/overlay_strategy_underlay_cast.h33
-rw-r--r--chromium/cc/output/overlay_unittest.cc2925
-rw-r--r--chromium/cc/output/renderer_pixeltest.cc3612
-rw-r--r--chromium/cc/output/software_output_device.cc39
-rw-r--r--chromium/cc/output/software_output_device.h70
-rw-r--r--chromium/cc/output/software_renderer.cc732
-rw-r--r--chromium/cc/output/software_renderer.h105
-rw-r--r--chromium/cc/output/software_renderer_unittest.cc456
-rw-r--r--chromium/cc/output/texture_mailbox_deleter.cc100
-rw-r--r--chromium/cc/output/texture_mailbox_deleter.h62
-rw-r--r--chromium/cc/output/texture_mailbox_deleter_unittest.cc75
-rw-r--r--chromium/cc/output/vulkan_renderer.cc92
-rw-r--r--chromium/cc/output/vulkan_renderer.h60
-rw-r--r--chromium/cc/paint/BUILD.gn3
-rw-r--r--chromium/cc/paint/discardable_image_map.cc271
-rw-r--r--chromium/cc/paint/discardable_image_map.h22
-rw-r--r--chromium/cc/paint/discardable_image_map_unittest.cc120
-rw-r--r--chromium/cc/paint/display_item_list_unittest.cc42
-rw-r--r--chromium/cc/paint/draw_image.cc4
-rw-r--r--chromium/cc/paint/draw_image.h9
-rw-r--r--chromium/cc/paint/frame_metadata.h4
-rw-r--r--chromium/cc/paint/image_animation_count.h30
-rw-r--r--chromium/cc/paint/image_provider.h11
-rw-r--r--chromium/cc/paint/paint_canvas.h2
-rw-r--r--chromium/cc/paint/paint_image.cc174
-rw-r--r--chromium/cc/paint/paint_image.h64
-rw-r--r--chromium/cc/paint/paint_image_builder.cc50
-rw-r--r--chromium/cc/paint/paint_image_builder.h76
-rw-r--r--chromium/cc/paint/paint_image_unittest.cc63
-rw-r--r--chromium/cc/paint/paint_op_buffer.cc148
-rw-r--r--chromium/cc/paint/paint_op_buffer.h16
-rw-r--r--chromium/cc/paint/paint_op_buffer_unittest.cc43
-rw-r--r--chromium/cc/paint/paint_op_reader.cc23
-rw-r--r--chromium/cc/paint/paint_op_reader.h3
-rw-r--r--chromium/cc/paint/paint_shader.cc133
-rw-r--r--chromium/cc/paint/paint_shader.h19
-rw-r--r--chromium/cc/paint/paint_shader_unittest.cc120
-rw-r--r--chromium/cc/paint/record_paint_canvas.cc10
-rw-r--r--chromium/cc/paint/record_paint_canvas.h2
-rw-r--r--chromium/cc/paint/scoped_image_flags.cc103
-rw-r--r--chromium/cc/paint/scoped_image_flags.h66
-rw-r--r--chromium/cc/paint/scoped_image_flags_unittest.cc70
-rw-r--r--chromium/cc/paint/skia_paint_canvas.cc8
-rw-r--r--chromium/cc/paint/skia_paint_canvas.h2
-rw-r--r--chromium/cc/paint/skia_paint_image_generator.cc5
-rw-r--r--chromium/cc/paint/skia_paint_image_generator.h8
-rw-r--r--chromium/cc/paint/solid_color_analyzer.cc77
-rw-r--r--chromium/cc/paint/solid_color_analyzer_unittest.cc100
-rw-r--r--chromium/cc/quads/content_draw_quad_base.cc64
-rw-r--r--chromium/cc/quads/content_draw_quad_base.h56
-rw-r--r--chromium/cc/quads/debug_border_draw_quad.cc54
-rw-r--r--chromium/cc/quads/debug_border_draw_quad.h44
-rw-r--r--chromium/cc/quads/draw_polygon.cc351
-rw-r--r--chromium/cc/quads/draw_polygon.h87
-rw-r--r--chromium/cc/quads/draw_polygon_unittest.cc630
-rw-r--r--chromium/cc/quads/draw_quad.cc83
-rw-r--r--chromium/cc/quads/draw_quad.h142
-rw-r--r--chromium/cc/quads/draw_quad_perftest.cc114
-rw-r--r--chromium/cc/quads/draw_quad_unittest.cc732
-rw-r--r--chromium/cc/quads/largest_draw_quad.cc82
-rw-r--r--chromium/cc/quads/largest_draw_quad.h19
-rw-r--r--chromium/cc/quads/picture_draw_quad.cc79
-rw-r--r--chromium/cc/quads/picture_draw_quad.h65
-rw-r--r--chromium/cc/quads/render_pass.cc308
-rw-r--r--chromium/cc/quads/render_pass.h172
-rw-r--r--chromium/cc/quads/render_pass_draw_quad.cc83
-rw-r--r--chromium/cc/quads/render_pass_draw_quad.h81
-rw-r--r--chromium/cc/quads/render_pass_unittest.cc305
-rw-r--r--chromium/cc/quads/solid_color_draw_quad.cc52
-rw-r--r--chromium/cc/quads/solid_color_draw_quad.h44
-rw-r--r--chromium/cc/quads/stream_video_draw_quad.cc62
-rw-r--r--chromium/cc/quads/stream_video_draw_quad.h63
-rw-r--r--chromium/cc/quads/surface_draw_quad.cc54
-rw-r--r--chromium/cc/quads/surface_draw_quad.h49
-rw-r--r--chromium/cc/quads/texture_draw_quad.cc121
-rw-r--r--chromium/cc/quads/texture_draw_quad.h89
-rw-r--r--chromium/cc/quads/tile_draw_quad.cc61
-rw-r--r--chromium/cc/quads/tile_draw_quad.h59
-rw-r--r--chromium/cc/quads/yuv_video_draw_quad.cc116
-rw-r--r--chromium/cc/quads/yuv_video_draw_quad.h117
-rw-r--r--chromium/cc/raster/gpu_raster_buffer_provider.cc10
-rw-r--r--chromium/cc/raster/playback_image_provider.cc75
-rw-r--r--chromium/cc/raster/playback_image_provider.h48
-rw-r--r--chromium/cc/raster/playback_image_provider_unittest.cc108
-rw-r--r--chromium/cc/raster/raster_buffer_provider.cc3
-rw-r--r--chromium/cc/raster/raster_buffer_provider_perftest.cc39
-rw-r--r--chromium/cc/raster/raster_buffer_provider_unittest.cc17
-rw-r--r--chromium/cc/raster/raster_source.cc15
-rw-r--r--chromium/cc/raster/raster_source.h10
-rw-r--r--chromium/cc/raster/raster_source_unittest.cc85
-rw-r--r--chromium/cc/raster/staging_buffer_pool.h5
-rw-r--r--chromium/cc/raster/task_graph_runner_perftest.cc2
-rw-r--r--chromium/cc/resources/DEPS3
-rw-r--r--chromium/cc/resources/display_resource_provider.cc237
-rw-r--r--chromium/cc/resources/display_resource_provider.h31
-rw-r--r--chromium/cc/resources/layer_tree_resource_provider.cc69
-rw-r--r--chromium/cc/resources/layer_tree_resource_provider.h21
-rw-r--r--chromium/cc/resources/release_callback_impl.h24
-rw-r--r--chromium/cc/resources/resource_pool.h4
-rw-r--r--chromium/cc/resources/resource_pool_unittest.cc29
-rw-r--r--chromium/cc/resources/resource_provider.cc364
-rw-r--r--chromium/cc/resources/resource_provider.h100
-rw-r--r--chromium/cc/resources/resource_provider_unittest.cc810
-rw-r--r--chromium/cc/resources/return_callback.h6
-rw-r--r--chromium/cc/resources/scoped_resource.cc4
-rw-r--r--chromium/cc/resources/scoped_resource.h4
-rw-r--r--chromium/cc/resources/scoped_resource_unittest.cc12
-rw-r--r--chromium/cc/resources/single_release_callback_impl.cc34
-rw-r--r--chromium/cc/resources/single_release_callback_impl.h37
-rw-r--r--chromium/cc/resources/video_resource_updater.cc70
-rw-r--r--chromium/cc/resources/video_resource_updater.h21
-rw-r--r--chromium/cc/resources/video_resource_updater_unittest.cc69
-rw-r--r--chromium/cc/scheduler/begin_frame_tracker.cc2
-rw-r--r--chromium/cc/scheduler/begin_frame_tracker.h4
-rw-r--r--chromium/cc/scheduler/compositor_timing_history.cc1
-rw-r--r--chromium/cc/scheduler/compositor_timing_history.h1
-rw-r--r--chromium/cc/scheduler/compositor_timing_history_unittest.cc4
-rw-r--r--chromium/cc/scheduler/scheduler.cc9
-rw-r--r--chromium/cc/scheduler/scheduler.h1
-rw-r--r--chromium/cc/scheduler/scheduler_state_machine.cc75
-rw-r--r--chromium/cc/scheduler/scheduler_state_machine.h4
-rw-r--r--chromium/cc/scheduler/scheduler_state_machine_unittest.cc52
-rw-r--r--chromium/cc/tiles/checker_image_tracker.cc25
-rw-r--r--chromium/cc/tiles/checker_image_tracker.h5
-rw-r--r--chromium/cc/tiles/checker_image_tracker_unittest.cc43
-rw-r--r--chromium/cc/tiles/decoded_image_tracker.cc4
-rw-r--r--chromium/cc/tiles/gpu_image_decode_cache.cc79
-rw-r--r--chromium/cc/tiles/gpu_image_decode_cache.h17
-rw-r--r--chromium/cc/tiles/gpu_image_decode_cache_unittest.cc1175
-rw-r--r--chromium/cc/tiles/image_controller.cc46
-rw-r--r--chromium/cc/tiles/image_controller.h3
-rw-r--r--chromium/cc/tiles/image_controller_unittest.cc39
-rw-r--r--chromium/cc/tiles/image_decode_cache.cc11
-rw-r--r--chromium/cc/tiles/image_decode_cache.h25
-rw-r--r--chromium/cc/tiles/picture_layer_tiling_set_unittest.cc2
-rw-r--r--chromium/cc/tiles/software_image_decode_cache.cc79
-rw-r--r--chromium/cc/tiles/software_image_decode_cache.h23
-rw-r--r--chromium/cc/tiles/software_image_decode_cache_perftest.cc4
-rw-r--r--chromium/cc/tiles/software_image_decode_cache_unittest.cc679
-rw-r--r--chromium/cc/tiles/tile_manager.cc97
-rw-r--r--chromium/cc/tiles/tile_manager.h13
-rw-r--r--chromium/cc/tiles/tile_manager_settings.h1
-rw-r--r--chromium/cc/tiles/tile_manager_unittest.cc14
-rw-r--r--chromium/cc/trees/DEPS5
-rw-r--r--chromium/cc/trees/blocking_task_runner.cc76
-rw-r--r--chromium/cc/trees/blocking_task_runner.h99
-rw-r--r--chromium/cc/trees/blocking_task_runner_unittest.cc45
-rw-r--r--chromium/cc/trees/clip_node.cc41
-rw-r--r--chromium/cc/trees/clip_node.h5
-rw-r--r--chromium/cc/trees/debug_rect_history.cc23
-rw-r--r--chromium/cc/trees/debug_rect_history.h1
-rw-r--r--chromium/cc/trees/draw_property_utils.cc4
-rw-r--r--chromium/cc/trees/effect_node.cc9
-rw-r--r--chromium/cc/trees/effect_node.h3
-rw-r--r--chromium/cc/trees/image_animation_controller.cc430
-rw-r--r--chromium/cc/trees/image_animation_controller.h237
-rw-r--r--chromium/cc/trees/image_animation_controller_unittest.cc736
-rw-r--r--chromium/cc/trees/latency_info_swap_promise.cc (renamed from chromium/cc/output/latency_info_swap_promise.cc)13
-rw-r--r--chromium/cc/trees/latency_info_swap_promise.h (renamed from chromium/cc/output/latency_info_swap_promise.h)10
-rw-r--r--chromium/cc/trees/latency_info_swap_promise_monitor.cc2
-rw-r--r--chromium/cc/trees/layer_tree_frame_sink.cc (renamed from chromium/cc/output/layer_tree_frame_sink.cc)4
-rw-r--r--chromium/cc/trees/layer_tree_frame_sink.h (renamed from chromium/cc/output/layer_tree_frame_sink.h)14
-rw-r--r--chromium/cc/trees/layer_tree_frame_sink_client.h (renamed from chromium/cc/output/layer_tree_frame_sink_client.h)6
-rw-r--r--chromium/cc/trees/layer_tree_frame_sink_unittest.cc (renamed from chromium/cc/output/layer_tree_frame_sink_unittest.cc)6
-rw-r--r--chromium/cc/trees/layer_tree_host.cc10
-rw-r--r--chromium/cc/trees/layer_tree_host.h13
-rw-r--r--chromium/cc/trees/layer_tree_host_client.h35
-rw-r--r--chromium/cc/trees/layer_tree_host_common.cc7
-rw-r--r--chromium/cc/trees/layer_tree_host_common_perftest.cc1
-rw-r--r--chromium/cc/trees/layer_tree_host_common_unittest.cc145
-rw-r--r--chromium/cc/trees/layer_tree_host_impl.cc244
-rw-r--r--chromium/cc/trees/layer_tree_host_impl.h42
-rw-r--r--chromium/cc/trees/layer_tree_host_impl_unittest.cc365
-rw-r--r--chromium/cc/trees/layer_tree_host_perftest.cc2
-rw-r--r--chromium/cc/trees/layer_tree_host_pixeltest_blending.cc22
-rw-r--r--chromium/cc/trees/layer_tree_host_pixeltest_masks.cc347
-rw-r--r--chromium/cc/trees/layer_tree_host_pixeltest_readback.cc113
-rw-r--r--chromium/cc/trees/layer_tree_host_pixeltest_tiles.cc4
-rw-r--r--chromium/cc/trees/layer_tree_host_unittest.cc220
-rw-r--r--chromium/cc/trees/layer_tree_host_unittest_animation.cc60
-rw-r--r--chromium/cc/trees/layer_tree_host_unittest_checkerimaging.cc9
-rw-r--r--chromium/cc/trees/layer_tree_host_unittest_context.cc4
-rw-r--r--chromium/cc/trees/layer_tree_host_unittest_copyrequest.cc143
-rw-r--r--chromium/cc/trees/layer_tree_impl.cc25
-rw-r--r--chromium/cc/trees/layer_tree_impl.h19
-rw-r--r--chromium/cc/trees/layer_tree_impl_unittest.cc130
-rw-r--r--chromium/cc/trees/layer_tree_mutator.h4
-rw-r--r--chromium/cc/trees/layer_tree_settings.cc1
-rw-r--r--chromium/cc/trees/layer_tree_settings.h10
-rw-r--r--chromium/cc/trees/managed_memory_policy.cc (renamed from chromium/cc/output/managed_memory_policy.cc)2
-rw-r--r--chromium/cc/trees/managed_memory_policy.h (renamed from chromium/cc/output/managed_memory_policy.h)9
-rw-r--r--chromium/cc/trees/mutable_properties.h25
-rw-r--r--chromium/cc/trees/mutator_host.h18
-rw-r--r--chromium/cc/trees/occlusion_tracker.cc45
-rw-r--r--chromium/cc/trees/occlusion_tracker_unittest.cc14
-rw-r--r--chromium/cc/trees/property_tree.cc20
-rw-r--r--chromium/cc/trees/property_tree.h1
-rw-r--r--chromium/cc/trees/property_tree_builder.cc39
-rw-r--r--chromium/cc/trees/proxy_common.h1
-rw-r--r--chromium/cc/trees/proxy_impl.cc6
-rw-r--r--chromium/cc/trees/proxy_main.cc40
-rw-r--r--chromium/cc/trees/scoped_abort_remaining_swap_promises.h2
-rw-r--r--chromium/cc/trees/single_thread_proxy.cc26
-rw-r--r--chromium/cc/trees/single_thread_proxy.h8
-rw-r--r--chromium/cc/trees/swap_promise.h (renamed from chromium/cc/output/swap_promise.h)11
-rw-r--r--chromium/cc/trees/swap_promise_manager.cc2
-rw-r--r--chromium/cc/trees/swap_promise_manager.h2
-rw-r--r--chromium/cc/trees/swap_promise_manager_unittest.cc2
-rw-r--r--chromium/cc/trees/task_runner_provider.cc8
-rw-r--r--chromium/cc/trees/task_runner_provider.h6
-rw-r--r--chromium/cc/trees/tree_synchronizer_unittest.cc2
395 files changed, 10657 insertions, 26373 deletions
diff --git a/chromium/cc/BUILD.gn b/chromium/cc/BUILD.gn
index c53c861877c..5c1b29be4fd 100644
--- a/chromium/cc/BUILD.gn
+++ b/chromium/cc/BUILD.gn
@@ -3,7 +3,6 @@
# found in the LICENSE file.
import("//cc/cc.gni")
-import("//gpu/vulkan/features.gni")
cc_component("cc") {
sources = [
@@ -46,7 +45,6 @@ cc_component("cc") {
"input/scroll_state_data.h",
"input/scrollbar_animation_controller.cc",
"input/scrollbar_animation_controller.h",
- "input/selection.h",
"input/single_scrollbar_animation_controller_thinning.cc",
"input/single_scrollbar_animation_controller_thinning.h",
"input/touch_action.h",
@@ -76,8 +74,8 @@ cc_component("cc") {
"layers/layer_position_constraint.h",
"layers/layer_sticky_position_constraint.cc",
"layers/layer_sticky_position_constraint.h",
- "layers/layer_utils.cc",
- "layers/layer_utils.h",
+ "layers/nine_patch_generator.cc",
+ "layers/nine_patch_generator.h",
"layers/nine_patch_layer.cc",
"layers/nine_patch_layer.h",
"layers/nine_patch_layer_impl.cc",
@@ -135,84 +133,8 @@ cc_component("cc") {
"layers/video_layer_impl.h",
"layers/viewport.cc",
"layers/viewport.h",
- "output/bsp_tree.cc",
- "output/bsp_tree.h",
- "output/bsp_walk_action.cc",
- "output/bsp_walk_action.h",
- "output/ca_layer_overlay.cc",
- "output/ca_layer_overlay.h",
- "output/compositor_frame.cc",
- "output/compositor_frame.h",
- "output/compositor_frame_metadata.cc",
- "output/compositor_frame_metadata.h",
- "output/dc_layer_overlay.cc",
- "output/dc_layer_overlay.h",
- "output/direct_renderer.cc",
- "output/direct_renderer.h",
- "output/latency_info_swap_promise.cc",
- "output/latency_info_swap_promise.h",
- "output/layer_quad.cc",
- "output/layer_quad.h",
- "output/layer_tree_frame_sink.cc",
- "output/layer_tree_frame_sink.h",
- "output/layer_tree_frame_sink_client.h",
- "output/managed_memory_policy.cc",
- "output/managed_memory_policy.h",
- "output/output_surface.cc",
- "output/output_surface.h",
- "output/output_surface_client.h",
- "output/output_surface_frame.cc",
- "output/output_surface_frame.h",
"output/overlay_candidate.cc",
"output/overlay_candidate.h",
- "output/overlay_candidate_validator.h",
- "output/overlay_processor.cc",
- "output/overlay_processor.h",
- "output/overlay_strategy_fullscreen.cc",
- "output/overlay_strategy_fullscreen.h",
- "output/overlay_strategy_single_on_top.cc",
- "output/overlay_strategy_single_on_top.h",
- "output/overlay_strategy_underlay.cc",
- "output/overlay_strategy_underlay.h",
- "output/overlay_strategy_underlay_cast.cc",
- "output/overlay_strategy_underlay_cast.h",
- "output/software_output_device.cc",
- "output/software_output_device.h",
- "output/software_renderer.cc",
- "output/software_renderer.h",
- "output/swap_promise.h",
- "output/texture_mailbox_deleter.cc",
- "output/texture_mailbox_deleter.h",
- "quads/content_draw_quad_base.cc",
- "quads/content_draw_quad_base.h",
- "quads/debug_border_draw_quad.cc",
- "quads/debug_border_draw_quad.h",
- "quads/draw_polygon.cc",
- "quads/draw_polygon.h",
- "quads/draw_quad.cc",
- "quads/draw_quad.h",
- "quads/largest_draw_quad.cc",
- "quads/largest_draw_quad.h",
- "quads/nine_patch_generator.cc",
- "quads/nine_patch_generator.h",
- "quads/picture_draw_quad.cc",
- "quads/picture_draw_quad.h",
- "quads/render_pass.cc",
- "quads/render_pass.h",
- "quads/render_pass_draw_quad.cc",
- "quads/render_pass_draw_quad.h",
- "quads/solid_color_draw_quad.cc",
- "quads/solid_color_draw_quad.h",
- "quads/stream_video_draw_quad.cc",
- "quads/stream_video_draw_quad.h",
- "quads/surface_draw_quad.cc",
- "quads/surface_draw_quad.h",
- "quads/texture_draw_quad.cc",
- "quads/texture_draw_quad.h",
- "quads/tile_draw_quad.cc",
- "quads/tile_draw_quad.h",
- "quads/yuv_video_draw_quad.cc",
- "quads/yuv_video_draw_quad.h",
"raster/bitmap_raster_buffer_provider.cc",
"raster/bitmap_raster_buffer_provider.h",
"raster/gpu_raster_buffer_provider.cc",
@@ -265,8 +187,6 @@ cc_component("cc") {
"resources/scoped_resource.h",
"resources/scoped_ui_resource.cc",
"resources/scoped_ui_resource.h",
- "resources/single_release_callback_impl.cc",
- "resources/single_release_callback_impl.h",
"resources/ui_resource_bitmap.cc",
"resources/ui_resource_bitmap.h",
"resources/ui_resource_client.h",
@@ -336,8 +256,6 @@ cc_component("cc") {
"tiles/tiling_set_raster_queue_all.h",
"tiles/tiling_set_raster_queue_required.cc",
"tiles/tiling_set_raster_queue_required.h",
- "trees/blocking_task_runner.cc",
- "trees/blocking_task_runner.h",
"trees/clip_expander.cc",
"trees/clip_expander.h",
"trees/clip_node.cc",
@@ -355,8 +273,15 @@ cc_component("cc") {
"trees/element_id.h",
"trees/frame_rate_counter.cc",
"trees/frame_rate_counter.h",
+ "trees/image_animation_controller.cc",
+ "trees/image_animation_controller.h",
+ "trees/latency_info_swap_promise.cc",
+ "trees/latency_info_swap_promise.h",
"trees/latency_info_swap_promise_monitor.cc",
"trees/latency_info_swap_promise_monitor.h",
+ "trees/layer_tree_frame_sink.cc",
+ "trees/layer_tree_frame_sink.h",
+ "trees/layer_tree_frame_sink_client.h",
"trees/layer_tree_host.cc",
"trees/layer_tree_host.h",
"trees/layer_tree_host_client.h",
@@ -370,7 +295,8 @@ cc_component("cc") {
"trees/layer_tree_mutator.h",
"trees/layer_tree_settings.cc",
"trees/layer_tree_settings.h",
- "trees/mutable_properties.h",
+ "trees/managed_memory_policy.cc",
+ "trees/managed_memory_policy.h",
"trees/mutator_host.h",
"trees/mutator_host_client.h",
"trees/occlusion.cc",
@@ -395,6 +321,7 @@ cc_component("cc") {
"trees/scroll_node.h",
"trees/single_thread_proxy.cc",
"trees/single_thread_proxy.h",
+ "trees/swap_promise.h",
"trees/swap_promise_manager.cc",
"trees/swap_promise_manager.h",
"trees/swap_promise_monitor.cc",
@@ -445,15 +372,6 @@ cc_component("cc") {
]
defines = [ "CC_IMPLEMENTATION=1" ]
-
- if (enable_vulkan) {
- sources += [
- "output/vulkan_renderer.cc",
- "output/vulkan_renderer.h",
- ]
-
- deps += [ "//gpu/vulkan" ]
- }
}
cc_static_library("test_support") {
@@ -463,8 +381,6 @@ cc_static_library("test_support") {
"test/animation_test_common.h",
"test/animation_timelines_test_common.cc",
"test/animation_timelines_test_common.h",
- "test/fake_compositor_frame_sink_support_client.cc",
- "test/fake_compositor_frame_sink_support_client.h",
"test/fake_content_layer_client.cc",
"test/fake_content_layer_client.h",
"test/fake_impl_task_runner_provider.h",
@@ -486,6 +402,8 @@ cc_static_library("test_support") {
"test/fake_output_surface.h",
"test/fake_output_surface_client.cc",
"test/fake_output_surface_client.h",
+ "test/fake_paint_image_generator.cc",
+ "test/fake_paint_image_generator.h",
"test/fake_painted_scrollbar_layer.cc",
"test/fake_painted_scrollbar_layer.h",
"test/fake_picture_layer.cc",
@@ -530,6 +448,8 @@ cc_static_library("test_support") {
"test/layer_tree_pixel_test.h",
"test/layer_tree_test.cc",
"test/layer_tree_test.h",
+ "test/mock_layer_client.cc",
+ "test/mock_layer_client.h",
"test/mock_occlusion_tracker.h",
"test/ordered_texture_map.cc",
"test/ordered_texture_map.h",
@@ -559,8 +479,6 @@ cc_static_library("test_support") {
"test/stub_layer_tree_host_client.h",
"test/stub_layer_tree_host_single_thread_client.cc",
"test/stub_layer_tree_host_single_thread_client.h",
- "test/stub_paint_image_generator.cc",
- "test/stub_paint_image_generator.h",
"test/task_graph_runner_test_template.cc",
"test/task_graph_runner_test_template.h",
"test/test_context_provider.cc",
@@ -653,7 +571,6 @@ cc_test("cc_unittests") {
"input/scrollbar_animation_controller_unittest.cc",
"input/single_scrollbar_animation_controller_thinning_unittest.cc",
"ipc/cc_param_traits_unittest.cc",
- "ipc/struct_traits_unittest.cc",
"layers/effect_tree_layer_list_iterator_unittest.cc",
"layers/heads_up_display_layer_impl_unittest.cc",
"layers/heads_up_display_unittest.cc",
@@ -661,7 +578,7 @@ cc_test("cc_unittests") {
"layers/layer_list_iterator_unittest.cc",
"layers/layer_position_constraint_unittest.cc",
"layers/layer_unittest.cc",
- "layers/layer_utils_unittest.cc",
+ "layers/nine_patch_generator_unittest.cc",
"layers/nine_patch_layer_impl_unittest.cc",
"layers/nine_patch_layer_unittest.cc",
"layers/painted_scrollbar_layer_impl_unittest.cc",
@@ -685,23 +602,13 @@ cc_test("cc_unittests") {
"layers/video_frame_provider_client_impl_unittest.cc",
"layers/video_layer_impl_unittest.cc",
"layers/viewport_unittest.cc",
- "output/bsp_tree_unittest.cc",
- "output/context_cache_controller_unittest.cc",
- "output/layer_quad_unittest.cc",
- "output/layer_tree_frame_sink_unittest.cc",
- "output/overlay_unittest.cc",
- "output/renderer_pixeltest.cc",
- "output/software_renderer_unittest.cc",
- "output/texture_mailbox_deleter_unittest.cc",
"paint/discardable_image_map_unittest.cc",
"paint/display_item_list_unittest.cc",
"paint/paint_image_unittest.cc",
"paint/paint_op_buffer_unittest.cc",
+ "paint/paint_shader_unittest.cc",
+ "paint/scoped_image_flags_unittest.cc",
"paint/solid_color_analyzer_unittest.cc",
- "quads/draw_polygon_unittest.cc",
- "quads/draw_quad_unittest.cc",
- "quads/nine_patch_generator_unittest.cc",
- "quads/render_pass_unittest.cc",
"raster/playback_image_provider_unittest.cc",
"raster/raster_buffer_provider_unittest.cc",
"raster/raster_source_unittest.cc",
@@ -730,8 +637,9 @@ cc_test("cc_unittests") {
"tiles/software_image_decode_cache_unittest.cc",
"tiles/tile_manager_unittest.cc",
"tiles/tile_priority_unittest.cc",
- "trees/blocking_task_runner_unittest.cc",
"trees/damage_tracker_unittest.cc",
+ "trees/image_animation_controller_unittest.cc",
+ "trees/layer_tree_frame_sink_unittest.cc",
"trees/layer_tree_host_common_unittest.cc",
"trees/layer_tree_host_impl_unittest.cc",
"trees/layer_tree_host_pixeltest_blending.cc",
@@ -790,7 +698,6 @@ cc_test("cc_unittests") {
":test_support",
"//base/test:test_support",
"//cc/ipc",
- "//cc/ipc:test_interfaces",
"//cc/paint",
"//components/viz/common",
"//components/viz/service",
@@ -824,8 +731,6 @@ cc_test("cc_perftests") {
"ipc/cc_serialization_perftest.cc",
"layers/layer_perftest.cc",
"layers/picture_layer_impl_perftest.cc",
- "output/bsp_tree_perftest.cc",
- "quads/draw_quad_perftest.cc",
"raster/raster_buffer_provider_perftest.cc",
"raster/task_graph_runner_perftest.cc",
"raster/texture_compressor_perftest.cc",
@@ -844,7 +749,6 @@ cc_test("cc_perftests") {
"//base",
"//base/test:test_support",
"//cc/ipc",
- "//cc/ipc:interfaces",
"//cc/paint",
"//components/viz/common",
"//components/viz/test:test_support",
diff --git a/chromium/cc/DEPS b/chromium/cc/DEPS
index 5ae24df75f4..6899c79c755 100644
--- a/chromium/cc/DEPS
+++ b/chromium/cc/DEPS
@@ -11,6 +11,7 @@ include_rules = [
"+gpu/command_buffer/common/mailbox_holder.h",
"+gpu/command_buffer/common/sync_token.h",
"+gpu/command_buffer/common/texture_in_use_response.h",
+ "+gpu/config/gpu_feature_info.h",
"+gpu/vulkan",
"+media",
"+skia/ext",
@@ -37,6 +38,7 @@ specific_include_rules = {
"+gpu/ipc",
],
".*_(unit|pixel|perf)test.*\.cc": [
+ "+components/viz/service/display",
"+components/viz/test",
],
}
diff --git a/chromium/cc/OWNERS b/chromium/cc/OWNERS
index db3022e1db2..2eca5ad16fc 100644
--- a/chromium/cc/OWNERS
+++ b/chromium/cc/OWNERS
@@ -51,6 +51,7 @@ weiliangc@chromium.org
# animation
vollick@chromium.org
ajuma@chromium.org
+flackr@chromium.org
# we miss you
# jamesr@chromium.org
diff --git a/chromium/cc/README.md b/chromium/cc/README.md
index 9cea72c4090..d1b5218d69b 100644
--- a/chromium/cc/README.md
+++ b/chromium/cc/README.md
@@ -8,18 +8,18 @@ The public API of the compositor is LayerTreeHost and Layer and its
derived types. Embedders create a LayerTreeHost (single, multithreaded,
or synchronous) and then attach a tree of Layers to it.
-When Layers are updated they request a commit, which takes the data
-of and structure of the tree of Layers and the data of its host and
-atomically pushes it to a tree of LayerImpls and a LayerTreeHostImpl
+When Layers are updated they request a commit, which takes the structure
+of the tree of Layers, the data on each Layer, and the data of its host and
+atomically pushes it all to a tree of LayerImpls and a LayerTreeHostImpl
and LayerTreeImpl. The main thread (which owns the tree of Layers
and the embedder) is blocked during this commit operation.
The commit is from the main thread Layer tree to the pending tree in
multithreaded mode. The pending tree is a staging tree for
rasterization. When enough rasterization has completed for
-invalidations and the pending tree is ready to activate. Activate is an
+invalidations, the pending tree is ready to activate. Activate is an
analogous operation to commit, and pushes data from the pending tree to
-the active tree. The pending tree exists so that all the of the updates
+the active tree. The pending tree exists so that all of the updates
from the main thread can be displayed to the user atomically while
the previous frame can be scrolled or animated.
diff --git a/chromium/cc/animation/BUILD.gn b/chromium/cc/animation/BUILD.gn
index 7ae45962bc5..4422a45700d 100644
--- a/chromium/cc/animation/BUILD.gn
+++ b/chromium/cc/animation/BUILD.gn
@@ -22,6 +22,8 @@ cc_component("animation") {
"animation_player.cc",
"animation_player.h",
"animation_target.h",
+ "animation_ticker.cc",
+ "animation_ticker.h",
"animation_timeline.cc",
"animation_timeline.h",
"element_animations.cc",
diff --git a/chromium/cc/animation/animation.cc b/chromium/cc/animation/animation.cc
index b2c7452fa2e..68961e9b212 100644
--- a/chromium/cc/animation/animation.cc
+++ b/chromium/cc/animation/animation.cc
@@ -41,6 +41,10 @@ static_assert(static_cast<int>(cc::AnimationCurve::LAST_CURVE_TYPE) + 1 ==
namespace cc {
+std::string Animation::ToString(RunState state) {
+ return s_runStateNames[state];
+}
+
std::unique_ptr<Animation> Animation::Create(
std::unique_ptr<AnimationCurve> curve,
int animation_id,
@@ -272,7 +276,7 @@ std::string Animation::ToString() const {
"Animation{id=%d, group=%d, target_property_id=%d, "
"run_state=%s}",
id_, group_, target_property_id_,
- s_runStateNames[static_cast<int>(run_state_)]);
+ Animation::ToString(run_state_).c_str());
}
} // namespace cc
diff --git a/chromium/cc/animation/animation.h b/chromium/cc/animation/animation.h
index 321286a526a..b5744ab3fcb 100644
--- a/chromium/cc/animation/animation.h
+++ b/chromium/cc/animation/animation.h
@@ -43,6 +43,7 @@ class CC_ANIMATION_EXPORT Animation {
// This sentinel must be last.
LAST_RUN_STATE = ABORTED_BUT_NEEDS_COMPLETION
};
+ static std::string ToString(RunState);
enum class Direction { NORMAL, REVERSE, ALTERNATE_NORMAL, ALTERNATE_REVERSE };
diff --git a/chromium/cc/animation/animation_host.cc b/chromium/cc/animation/animation_host.cc
index c3ec7760180..b64e1390e73 100644
--- a/chromium/cc/animation/animation_host.cc
+++ b/chromium/cc/animation/animation_host.cc
@@ -141,7 +141,7 @@ void AnimationHost::RegisterPlayerForElement(ElementId element_id,
element_animations->InitAffectedElementTypes();
}
- element_animations->AddPlayer(player);
+ element_animations->AddTicker(player->animation_ticker());
}
void AnimationHost::UnregisterPlayerForElement(ElementId element_id,
@@ -152,7 +152,7 @@ void AnimationHost::UnregisterPlayerForElement(ElementId element_id,
scoped_refptr<ElementAnimations> element_animations =
GetElementAnimationsForElementId(element_id);
DCHECK(element_animations);
- element_animations->RemovePlayer(player);
+ element_animations->RemoveTicker(player->animation_ticker());
if (element_animations->IsEmpty()) {
element_animations->ClearAffectedElementTypes();
@@ -168,9 +168,6 @@ void AnimationHost::SetMutatorHostClient(MutatorHostClient* client) {
return;
mutator_host_client_ = client;
-
- if (needs_push_properties() && mutator_host_client())
- SetNeedsPushProperties();
}
void AnimationHost::SetNeedsCommit() {
@@ -231,23 +228,18 @@ void AnimationHost::PushPropertiesToImplThread(AnimationHost* host_impl) {
// to happen before the element animations are synced below.
for (auto& kv : id_to_timeline_map_) {
AnimationTimeline* timeline = kv.second.get();
- if (timeline->needs_push_properties()) {
- AnimationTimeline* timeline_impl =
- host_impl->GetTimelineById(timeline->id());
- if (timeline_impl)
- timeline->PushPropertiesTo(timeline_impl);
+ if (AnimationTimeline* timeline_impl =
+ host_impl->GetTimelineById(timeline->id())) {
+ timeline->PushPropertiesTo(timeline_impl);
}
}
// Sync properties for created ElementAnimations.
for (auto& kv : element_to_animations_map_) {
const auto& element_animations = kv.second;
- if (element_animations->needs_push_properties()) {
- auto element_animations_impl =
- host_impl->GetElementAnimationsForElementId(kv.first);
- if (element_animations_impl)
- element_animations->PushPropertiesTo(
- std::move(element_animations_impl));
+ if (auto element_animations_impl =
+ host_impl->GetElementAnimationsForElementId(kv.first)) {
+ element_animations->PushPropertiesTo(std::move(element_animations_impl));
}
}
@@ -347,13 +339,6 @@ bool AnimationHost::UpdateAnimationState(bool start_ready_animations,
return true;
}
-base::Closure AnimationHost::TakeMutations() {
- if (mutator_)
- return mutator_->TakeMutations();
-
- return base::Closure();
-}
-
std::unique_ptr<MutatorEvents> AnimationHost::CreateEvents() {
return std::make_unique<AnimationEvents>();
}
@@ -471,24 +456,6 @@ bool AnimationHost::HasAnyAnimationTargetingProperty(
return element_animations->HasAnyAnimationTargetingProperty(property);
}
-bool AnimationHost::HasTransformAnimationThatInflatesBounds(
- ElementId element_id) const {
- auto element_animations = GetElementAnimationsForElementId(element_id);
- return element_animations
- ? element_animations->HasTransformAnimationThatInflatesBounds()
- : false;
-}
-
-bool AnimationHost::TransformAnimationBoundsForBox(ElementId element_id,
- const gfx::BoxF& box,
- gfx::BoxF* bounds) const {
- *bounds = gfx::BoxF();
- auto element_animations = GetElementAnimationsForElementId(element_id);
- return element_animations
- ? element_animations->TransformAnimationBoundsForBox(box, bounds)
- : true;
-}
-
bool AnimationHost::HasOnlyTranslationTransforms(
ElementId element_id,
ElementListType list_type) const {
diff --git a/chromium/cc/animation/animation_host.h b/chromium/cc/animation/animation_host.h
index a40f99f6e5e..c2381fb59fb 100644
--- a/chromium/cc/animation/animation_host.h
+++ b/chromium/cc/animation/animation_host.h
@@ -105,8 +105,6 @@ class CC_ANIMATION_EXPORT AnimationHost : public MutatorHost,
bool UpdateAnimationState(bool start_ready_animations,
MutatorEvents* events) override;
- base::Closure TakeMutations() override;
-
std::unique_ptr<MutatorEvents> CreateEvents() override;
void SetAnimationEvents(std::unique_ptr<MutatorEvents> events) override;
@@ -133,13 +131,6 @@ class CC_ANIMATION_EXPORT AnimationHost : public MutatorHost,
ElementId element_id,
TargetProperty::Type property) const override;
- bool HasTransformAnimationThatInflatesBounds(
- ElementId element_id) const override;
-
- bool TransformAnimationBoundsForBox(ElementId element_id,
- const gfx::BoxF& box,
- gfx::BoxF* bounds) const override;
-
bool HasOnlyTranslationTransforms(ElementId element_id,
ElementListType list_type) const override;
bool AnimationsPreserveAxisAlignment(ElementId element_id) const override;
diff --git a/chromium/cc/animation/animation_player.cc b/chromium/cc/animation/animation_player.cc
index b44c73633db..ed055b4e332 100644
--- a/chromium/cc/animation/animation_player.cc
+++ b/chromium/cc/animation/animation_player.cc
@@ -12,6 +12,7 @@
#include "cc/animation/animation_delegate.h"
#include "cc/animation/animation_events.h"
#include "cc/animation/animation_host.h"
+#include "cc/animation/animation_ticker.h"
#include "cc/animation/animation_timeline.h"
#include "cc/animation/scroll_offset_animation_curve.h"
#include "cc/animation/transform_operations.h"
@@ -20,25 +21,20 @@
namespace cc {
scoped_refptr<AnimationPlayer> AnimationPlayer::Create(int id) {
- return make_scoped_refptr(new AnimationPlayer(id));
+ return base::WrapRefCounted(new AnimationPlayer(id));
}
AnimationPlayer::AnimationPlayer(int id)
: animation_host_(),
animation_timeline_(),
- element_animations_(),
animation_delegate_(),
id_(id),
- needs_push_properties_(false),
- needs_to_start_animations_(false),
- is_ticking_(false),
- scroll_offset_animation_was_interrupted_(false) {
+ animation_ticker_(new AnimationTicker(this)) {
DCHECK(id_);
}
AnimationPlayer::~AnimationPlayer() {
DCHECK(!animation_timeline_);
- DCHECK(!element_animations_);
}
scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const {
@@ -46,6 +42,10 @@ scoped_refptr<AnimationPlayer> AnimationPlayer::CreateImplInstance() const {
return player;
}
+ElementId AnimationPlayer::element_id() const {
+ return animation_ticker_->element_id();
+}
+
void AnimationPlayer::SetAnimationHost(AnimationHost* animation_host) {
animation_host_ = animation_host;
}
@@ -56,21 +56,27 @@ void AnimationPlayer::SetAnimationTimeline(AnimationTimeline* timeline) {
// We need to unregister player to manage ElementAnimations and observers
// properly.
- if (element_id_ && element_animations_)
+ if (animation_ticker_->has_attached_element() &&
+ animation_ticker_->has_bound_element_animations())
UnregisterPlayer();
animation_timeline_ = timeline;
// Register player only if layer AND host attached.
- if (element_id_ && animation_host_)
+ if (animation_ticker_->has_attached_element() && animation_host_)
RegisterPlayer();
}
-void AnimationPlayer::AttachElement(ElementId element_id) {
- DCHECK(!element_id_);
- DCHECK(element_id);
+bool AnimationPlayer::has_any_animation() const {
+ return animation_ticker_->has_any_animation();
+}
- element_id_ = element_id;
+scoped_refptr<ElementAnimations> AnimationPlayer::element_animations() const {
+ return animation_ticker_->element_animations();
+}
+
+void AnimationPlayer::AttachElement(ElementId element_id) {
+ animation_ticker_->AttachElement(element_id);
// Register player only if layer AND host attached.
if (animation_host_)
@@ -78,346 +84,104 @@ void AnimationPlayer::AttachElement(ElementId element_id) {
}
void AnimationPlayer::DetachElement() {
- DCHECK(element_id_);
+ DCHECK(animation_ticker_->has_attached_element());
if (animation_host_)
UnregisterPlayer();
- element_id_ = ElementId();
+ animation_ticker_->DetachElement();
}
void AnimationPlayer::RegisterPlayer() {
- DCHECK(element_id_);
DCHECK(animation_host_);
- DCHECK(!element_animations_);
+ DCHECK(animation_ticker_->has_attached_element());
+ DCHECK(!animation_ticker_->has_bound_element_animations());
// Create ElementAnimations or re-use existing.
- animation_host_->RegisterPlayerForElement(element_id_, this);
- // Get local reference to shared ElementAnimations.
- BindElementAnimations();
+ animation_host_->RegisterPlayerForElement(animation_ticker_->element_id(),
+ this);
}
void AnimationPlayer::UnregisterPlayer() {
- DCHECK(element_id_);
DCHECK(animation_host_);
- DCHECK(element_animations_);
+ DCHECK(animation_ticker_->has_attached_element());
+ DCHECK(animation_ticker_->has_bound_element_animations());
- UnbindElementAnimations();
// Destroy ElementAnimations or release it if it's still needed.
- animation_host_->UnregisterPlayerForElement(element_id_, this);
-}
-
-void AnimationPlayer::BindElementAnimations() {
- DCHECK(!element_animations_);
- element_animations_ =
- animation_host_->GetElementAnimationsForElementId(element_id_);
- DCHECK(element_animations_);
-
- if (!animations_.empty())
- AnimationAdded();
-
- SetNeedsPushProperties();
-}
-
-void AnimationPlayer::UnbindElementAnimations() {
- SetNeedsPushProperties();
- element_animations_ = nullptr;
+ animation_host_->UnregisterPlayerForElement(animation_ticker_->element_id(),
+ this);
}
void AnimationPlayer::AddAnimation(std::unique_ptr<Animation> animation) {
- DCHECK(animation->target_property_id() != TargetProperty::SCROLL_OFFSET ||
- (animation_host_ && animation_host_->SupportsScrollAnimations()));
- DCHECK(!animation->is_impl_only() ||
- animation->target_property_id() == TargetProperty::SCROLL_OFFSET);
-
- animations_.push_back(std::move(animation));
- if (element_animations_) {
- AnimationAdded();
- SetNeedsPushProperties();
- }
-}
-
-void AnimationPlayer::AnimationAdded() {
- DCHECK(element_animations_);
-
- SetNeedsCommit();
- needs_to_start_animations_ = true;
-
- UpdateTickingState(UpdateTickingType::NORMAL);
- element_animations_->UpdateClientAnimationState();
+ animation_ticker_->AddAnimation(std::move(animation));
}
void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) {
- const base::TimeDelta time_delta = base::TimeDelta::FromSecondsD(time_offset);
-
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (animations_[i]->id() == animation_id) {
- animations_[i]->SetRunState(Animation::PAUSED,
- time_delta + animations_[i]->start_time() +
- animations_[i]->time_offset());
- }
- }
-
- if (element_animations_) {
- SetNeedsCommit();
- SetNeedsPushProperties();
- }
+ animation_ticker_->PauseAnimation(animation_id, time_offset);
}
void AnimationPlayer::RemoveAnimation(int animation_id) {
- bool animation_removed = false;
-
- // Since we want to use the animations that we're going to remove, we need to
- // use a stable_parition here instead of remove_if. Remove_if leaves the
- // removed items in an unspecified state.
- auto animations_to_remove = std::stable_partition(
- animations_.begin(), animations_.end(),
- [animation_id](const std::unique_ptr<Animation>& animation) {
- return animation->id() != animation_id;
- });
- for (auto it = animations_to_remove; it != animations_.end(); ++it) {
- if ((*it)->target_property_id() == TargetProperty::SCROLL_OFFSET) {
- if (element_animations_)
- scroll_offset_animation_was_interrupted_ = true;
- } else if (!(*it)->is_finished()) {
- animation_removed = true;
- }
- }
-
- animations_.erase(animations_to_remove, animations_.end());
-
- if (element_animations_) {
- UpdateTickingState(UpdateTickingType::NORMAL);
- if (animation_removed)
- element_animations_->UpdateClientAnimationState();
- SetNeedsCommit();
- SetNeedsPushProperties();
- }
+ animation_ticker_->RemoveAnimation(animation_id);
}
void AnimationPlayer::AbortAnimation(int animation_id) {
- if (Animation* animation = GetAnimationById(animation_id)) {
- if (!animation->is_finished()) {
- animation->SetRunState(Animation::ABORTED, last_tick_time_);
- if (element_animations_)
- element_animations_->UpdateClientAnimationState();
- }
- }
-
- if (element_animations_) {
- SetNeedsCommit();
- SetNeedsPushProperties();
- }
+ animation_ticker_->AbortAnimation(animation_id);
}
void AnimationPlayer::AbortAnimations(TargetProperty::Type target_property,
bool needs_completion) {
- if (needs_completion)
- DCHECK(target_property == TargetProperty::SCROLL_OFFSET);
-
- bool aborted_animation = false;
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (animations_[i]->target_property_id() == target_property &&
- !animations_[i]->is_finished()) {
- // Currently only impl-only scroll offset animations can be completed on
- // the main thread.
- if (needs_completion && animations_[i]->is_impl_only()) {
- animations_[i]->SetRunState(Animation::ABORTED_BUT_NEEDS_COMPLETION,
- last_tick_time_);
- } else {
- animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_);
- }
- aborted_animation = true;
- }
- }
-
- if (element_animations_) {
- if (aborted_animation)
- element_animations_->UpdateClientAnimationState();
- SetNeedsCommit();
- SetNeedsPushProperties();
- }
+ animation_ticker_->AbortAnimations(target_property, needs_completion);
}
void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) {
- if (!needs_push_properties_)
- return;
- needs_push_properties_ = false;
-
- // Create or destroy ElementAnimations.
- if (element_id_ != player_impl->element_id()) {
- if (player_impl->element_id())
- player_impl->DetachElement();
- if (element_id_)
- player_impl->AttachElement(element_id_);
- }
-
- if (!has_any_animation() && !player_impl->has_any_animation())
- return;
-
- MarkAbortedAnimationsForDeletion(player_impl);
- PurgeAnimationsMarkedForDeletion(/* impl_only */ false);
- PushNewAnimationsToImplThread(player_impl);
-
- // Remove finished impl side animations only after pushing,
- // and only after the animations are deleted on the main thread
- // this insures we will never push an animation twice.
- RemoveAnimationsCompletedOnMainThread(player_impl);
-
- PushPropertiesToImplThread(player_impl);
-
- player_impl->UpdateTickingState(UpdateTickingType::NORMAL);
+ animation_ticker_->PushPropertiesTo(player_impl->animation_ticker_.get());
}
void AnimationPlayer::Tick(base::TimeTicks monotonic_time) {
DCHECK(!monotonic_time.is_null());
- DCHECK(element_animations_);
-
- if (!element_animations_->has_element_in_any_list())
- return;
-
- if (needs_to_start_animations())
- StartAnimations(monotonic_time);
-
- TickAnimations(monotonic_time);
-
- last_tick_time_ = monotonic_time;
- element_animations_->UpdateClientAnimationState();
+ animation_ticker_->Tick(monotonic_time);
}
void AnimationPlayer::UpdateState(bool start_ready_animations,
AnimationEvents* events) {
- DCHECK(element_animations_);
- if (!element_animations_->has_element_in_active_list())
- return;
-
- // Animate hasn't been called, this happens if an element has been added
- // between the Commit and Draw phases.
- if (last_tick_time_ == base::TimeTicks())
- return;
-
- if (start_ready_animations)
- PromoteStartedAnimations(last_tick_time_, events);
-
- MarkFinishedAnimations(last_tick_time_);
- MarkAnimationsForDeletion(last_tick_time_, events);
- PurgeAnimationsMarkedForDeletion(/* impl_only */ true);
-
- if (start_ready_animations) {
- if (needs_to_start_animations()) {
- StartAnimations(last_tick_time_);
- PromoteStartedAnimations(last_tick_time_, events);
- }
- }
-
- UpdateTickingState(UpdateTickingType::NORMAL);
+ animation_ticker_->UpdateState(start_ready_animations, events);
+ animation_ticker_->UpdateTickingState(UpdateTickingType::NORMAL);
}
-void AnimationPlayer::UpdateTickingState(UpdateTickingType type) {
- bool force = type == UpdateTickingType::FORCE;
- if (animation_host_) {
- bool was_ticking = is_ticking_;
- is_ticking_ = HasNonDeletedAnimation();
-
- bool has_element_in_any_list =
- element_animations_->has_element_in_any_list();
-
- if (is_ticking_ && ((!was_ticking && has_element_in_any_list) || force)) {
- animation_host_->AddToTicking(this);
- } else if (!is_ticking_ && (was_ticking || force)) {
- RemoveFromTicking();
- }
- }
+void AnimationPlayer::AddToTicking() {
+ DCHECK(animation_host_);
+ animation_host_->AddToTicking(this);
}
-void AnimationPlayer::RemoveFromTicking() {
+void AnimationPlayer::AnimationRemovedFromTicking() {
DCHECK(animation_host_);
- // Resetting last_tick_time_ here ensures that calling ::UpdateState
- // before ::Animate doesn't start an animation.
- is_ticking_ = false;
- last_tick_time_ = base::TimeTicks();
animation_host_->RemoveFromTicking(this);
}
-bool AnimationPlayer::NotifyAnimationStarted(const AnimationEvent& event) {
- DCHECK(!event.is_impl_only);
-
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (animations_[i]->group() == event.group_id &&
- animations_[i]->target_property_id() == event.target_property &&
- animations_[i]->needs_synchronized_start_time()) {
- animations_[i]->set_needs_synchronized_start_time(false);
- if (!animations_[i]->has_set_start_time())
- animations_[i]->set_start_time(event.monotonic_time);
-
- if (animation_delegate_) {
- animation_delegate_->NotifyAnimationStarted(
- event.monotonic_time, event.target_property, event.group_id);
- }
- return true;
- }
+void AnimationPlayer::NotifyAnimationStarted(const AnimationEvent& event) {
+ if (animation_delegate_) {
+ animation_delegate_->NotifyAnimationStarted(
+ event.monotonic_time, event.target_property, event.group_id);
}
-
- return false;
}
-bool AnimationPlayer::NotifyAnimationFinished(const AnimationEvent& event) {
- DCHECK(!event.is_impl_only);
-
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (animations_[i]->group() == event.group_id &&
- animations_[i]->target_property_id() == event.target_property) {
- animations_[i]->set_received_finished_event(true);
-
- if (animation_delegate_) {
- animation_delegate_->NotifyAnimationFinished(
- event.monotonic_time, event.target_property, event.group_id);
- }
- return true;
- }
+void AnimationPlayer::NotifyAnimationFinished(const AnimationEvent& event) {
+ if (animation_delegate_) {
+ animation_delegate_->NotifyAnimationFinished(
+ event.monotonic_time, event.target_property, event.group_id);
}
-
- // This is for the case when an animation is already removed on main thread,
- // but the impl version of it sent a finished event and is now waiting for
- // deletion. We would need to delete that animation during push properties.
- SetNeedsPushProperties();
- return false;
}
-bool AnimationPlayer::NotifyAnimationFinishedForTesting(
- TargetProperty::Type target_property,
- int group_id) {
- AnimationEvent event(AnimationEvent::FINISHED, element_id_, group_id,
- target_property, base::TimeTicks());
- return NotifyAnimationFinished(event);
-}
-
-bool AnimationPlayer::NotifyAnimationAborted(const AnimationEvent& event) {
- DCHECK(!event.is_impl_only);
-
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (animations_[i]->group() == event.group_id &&
- animations_[i]->target_property_id() == event.target_property) {
- animations_[i]->SetRunState(Animation::ABORTED, event.monotonic_time);
- animations_[i]->set_received_finished_event(true);
- if (animation_delegate_) {
- animation_delegate_->NotifyAnimationAborted(
- event.monotonic_time, event.target_property, event.group_id);
- }
- return true;
- }
+void AnimationPlayer::NotifyAnimationAborted(const AnimationEvent& event) {
+ if (animation_delegate_) {
+ animation_delegate_->NotifyAnimationAborted(
+ event.monotonic_time, event.target_property, event.group_id);
}
-
- return false;
}
void AnimationPlayer::NotifyAnimationTakeover(const AnimationEvent& event) {
- DCHECK(!event.is_impl_only);
DCHECK(event.target_property == TargetProperty::SCROLL_OFFSET);
- // We need to purge animations marked for deletion on CT.
- SetNeedsPushProperties();
-
if (animation_delegate_) {
DCHECK(event.curve);
std::unique_ptr<AnimationCurve> animation_curve = event.curve->Clone();
@@ -427,778 +191,40 @@ void AnimationPlayer::NotifyAnimationTakeover(const AnimationEvent& event) {
}
}
+bool AnimationPlayer::NotifyAnimationFinishedForTesting(
+ TargetProperty::Type target_property,
+ int group_id) {
+ AnimationEvent event(AnimationEvent::FINISHED,
+ animation_ticker_->element_id(), group_id,
+ target_property, base::TimeTicks());
+ return animation_ticker_->NotifyAnimationFinished(event);
+}
+
void AnimationPlayer::SetNeedsCommit() {
DCHECK(animation_host_);
animation_host_->SetNeedsCommit();
}
void AnimationPlayer::SetNeedsPushProperties() {
- needs_push_properties_ = true;
-
DCHECK(animation_timeline_);
animation_timeline_->SetNeedsPushProperties();
-
- DCHECK(element_animations_);
- element_animations_->SetNeedsPushProperties();
-}
-
-bool AnimationPlayer::HasTickingAnimation() const {
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (!animations_[i]->is_finished())
- return true;
- }
- return false;
-}
-
-bool AnimationPlayer::HasNonDeletedAnimation() const {
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (animations_[i]->run_state() != Animation::WAITING_FOR_DELETION)
- return true;
- }
-
- return false;
-}
-
-void AnimationPlayer::StartAnimations(base::TimeTicks monotonic_time) {
- DCHECK(needs_to_start_animations_);
- needs_to_start_animations_ = false;
- // First collect running properties affecting each type of element.
- TargetProperties blocked_properties_for_active_elements;
- TargetProperties blocked_properties_for_pending_elements;
- std::vector<size_t> animations_waiting_for_target;
-
- animations_waiting_for_target.reserve(animations_.size());
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (animations_[i]->run_state() == Animation::STARTING ||
- animations_[i]->run_state() == Animation::RUNNING) {
- int property = animations_[i]->target_property_id();
- if (animations_[i]->affects_active_elements()) {
- blocked_properties_for_active_elements[property] = true;
- }
- if (animations_[i]->affects_pending_elements()) {
- blocked_properties_for_pending_elements[property] = true;
- }
- } else if (animations_[i]->run_state() ==
- Animation::WAITING_FOR_TARGET_AVAILABILITY) {
- animations_waiting_for_target.push_back(i);
- }
- }
-
- for (size_t i = 0; i < animations_waiting_for_target.size(); ++i) {
- // Collect all properties for animations with the same group id (they
- // should all also be in the list of animations).
- size_t animation_index = animations_waiting_for_target[i];
- Animation* animation_waiting_for_target =
- animations_[animation_index].get();
- // Check for the run state again even though the animation was waiting
- // for target because it might have changed the run state while handling
- // previous animation in this loop (if they belong to same group).
- if (animation_waiting_for_target->run_state() ==
- Animation::WAITING_FOR_TARGET_AVAILABILITY) {
- TargetProperties enqueued_properties;
- bool affects_active_elements =
- animation_waiting_for_target->affects_active_elements();
- bool affects_pending_elements =
- animation_waiting_for_target->affects_pending_elements();
- enqueued_properties[animation_waiting_for_target->target_property_id()] =
- true;
- for (size_t j = animation_index + 1; j < animations_.size(); ++j) {
- if (animation_waiting_for_target->group() == animations_[j]->group()) {
- enqueued_properties[animations_[j]->target_property_id()] = true;
- affects_active_elements |= animations_[j]->affects_active_elements();
- affects_pending_elements |=
- animations_[j]->affects_pending_elements();
- }
- }
-
- // Check to see if intersection of the list of properties affected by
- // the group and the list of currently blocked properties is null, taking
- // into account the type(s) of elements affected by the group. In any
- // case, the group's target properties need to be added to the lists of
- // blocked properties.
- bool null_intersection = true;
- for (int property = TargetProperty::FIRST_TARGET_PROPERTY;
- property <= TargetProperty::LAST_TARGET_PROPERTY; ++property) {
- if (enqueued_properties[property]) {
- if (affects_active_elements) {
- if (blocked_properties_for_active_elements[property])
- null_intersection = false;
- else
- blocked_properties_for_active_elements[property] = true;
- }
- if (affects_pending_elements) {
- if (blocked_properties_for_pending_elements[property])
- null_intersection = false;
- else
- blocked_properties_for_pending_elements[property] = true;
- }
- }
- }
-
- // If the intersection is null, then we are free to start the animations
- // in the group.
- if (null_intersection) {
- animation_waiting_for_target->SetRunState(Animation::STARTING,
- monotonic_time);
- for (size_t j = animation_index + 1; j < animations_.size(); ++j) {
- if (animation_waiting_for_target->group() ==
- animations_[j]->group()) {
- animations_[j]->SetRunState(Animation::STARTING, monotonic_time);
- }
- }
- } else {
- needs_to_start_animations_ = true;
- }
- }
- }
-}
-
-void AnimationPlayer::PromoteStartedAnimations(base::TimeTicks monotonic_time,
- AnimationEvents* events) {
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (animations_[i]->run_state() == Animation::STARTING &&
- animations_[i]->affects_active_elements()) {
- animations_[i]->SetRunState(Animation::RUNNING, monotonic_time);
- if (!animations_[i]->has_set_start_time() &&
- !animations_[i]->needs_synchronized_start_time())
- animations_[i]->set_start_time(monotonic_time);
- if (events) {
- base::TimeTicks start_time;
- if (animations_[i]->has_set_start_time())
- start_time = animations_[i]->start_time();
- else
- start_time = monotonic_time;
- AnimationEvent started_event(
- AnimationEvent::STARTED, element_id_, animations_[i]->group(),
- animations_[i]->target_property_id(), start_time);
- started_event.is_impl_only = animations_[i]->is_impl_only();
- if (started_event.is_impl_only) {
- // Notify delegate directly, do not record the event.
- if (animation_delegate_) {
- animation_delegate_->NotifyAnimationStarted(
- started_event.monotonic_time, started_event.target_property,
- started_event.group_id);
- }
- } else {
- events->events_.push_back(started_event);
- }
- }
- }
- }
-}
-
-void AnimationPlayer::MarkAnimationsForDeletion(base::TimeTicks monotonic_time,
- AnimationEvents* events) {
- bool marked_animations_for_deletions = false;
- std::vector<size_t> animations_with_same_group_id;
-
- animations_with_same_group_id.reserve(animations_.size());
- // Non-aborted animations are marked for deletion after a corresponding
- // AnimationEvent::FINISHED event is sent or received. This means that if
- // we don't have an events vector, we must ensure that non-aborted animations
- // have received a finished event before marking them for deletion.
- for (size_t i = 0; i < animations_.size(); i++) {
- int group_id = animations_[i]->group();
- if (animations_[i]->run_state() == Animation::ABORTED) {
- if (events && !animations_[i]->is_impl_only()) {
- AnimationEvent aborted_event(
- AnimationEvent::ABORTED, element_id_, group_id,
- animations_[i]->target_property_id(), monotonic_time);
- events->events_.push_back(aborted_event);
- }
- // If on the compositor or on the main thread and received finish event,
- // animation can be marked for deletion.
- if (events || animations_[i]->received_finished_event()) {
- animations_[i]->SetRunState(Animation::WAITING_FOR_DELETION,
- monotonic_time);
- marked_animations_for_deletions = true;
- }
- continue;
- }
-
- // If running on the compositor and need to complete an aborted animation
- // on the main thread.
- if (events &&
- animations_[i]->run_state() ==
- Animation::ABORTED_BUT_NEEDS_COMPLETION) {
- AnimationEvent aborted_event(
- AnimationEvent::TAKEOVER, element_id_, group_id,
- animations_[i]->target_property_id(), monotonic_time);
- aborted_event.animation_start_time = animations_[i]->start_time();
- const ScrollOffsetAnimationCurve* scroll_offset_animation_curve =
- animations_[i]->curve()->ToScrollOffsetAnimationCurve();
- aborted_event.curve = scroll_offset_animation_curve->Clone();
- // Notify the compositor that the animation is finished.
- if (animation_delegate_) {
- animation_delegate_->NotifyAnimationFinished(
- aborted_event.monotonic_time, aborted_event.target_property,
- aborted_event.group_id);
- }
- // Notify main thread.
- events->events_.push_back(aborted_event);
-
- // Remove the animation from the compositor.
- animations_[i]->SetRunState(Animation::WAITING_FOR_DELETION,
- monotonic_time);
- marked_animations_for_deletions = true;
- continue;
- }
-
- bool all_anims_with_same_id_are_finished = false;
-
- // Since deleting an animation on the main thread leads to its deletion
- // on the impl thread, we only mark a FINISHED main thread animation for
- // deletion once it has received a FINISHED event from the impl thread.
- bool animation_i_will_send_or_has_received_finish_event =
- animations_[i]->is_controlling_instance() ||
- animations_[i]->is_impl_only() ||
- animations_[i]->received_finished_event();
- // If an animation is finished, and not already marked for deletion,
- // find out if all other animations in the same group are also finished.
- if (animations_[i]->run_state() == Animation::FINISHED &&
- animation_i_will_send_or_has_received_finish_event) {
- // Clear the animations_with_same_group_id if it was added for
- // the previous animation's iteration.
- if (animations_with_same_group_id.size() > 0)
- animations_with_same_group_id.clear();
- all_anims_with_same_id_are_finished = true;
- for (size_t j = 0; j < animations_.size(); ++j) {
- bool animation_j_will_send_or_has_received_finish_event =
- animations_[j]->is_controlling_instance() ||
- animations_[j]->is_impl_only() ||
- animations_[j]->received_finished_event();
- if (group_id == animations_[j]->group()) {
- if (!animations_[j]->is_finished() ||
- (animations_[j]->run_state() == Animation::FINISHED &&
- !animation_j_will_send_or_has_received_finish_event)) {
- all_anims_with_same_id_are_finished = false;
- break;
- } else if (j >= i &&
- animations_[j]->run_state() != Animation::ABORTED) {
- // Mark down the animations which belong to the same group
- // and is not yet aborted. If this current iteration finds that all
- // animations with same ID are finished, then the marked
- // animations below will be set to WAITING_FOR_DELETION in next
- // iteration.
- animations_with_same_group_id.push_back(j);
- }
- }
- }
- }
- if (all_anims_with_same_id_are_finished) {
- // We now need to remove all animations with the same group id as
- // group_id (and send along animation finished notifications, if
- // necessary).
- for (size_t j = 0; j < animations_with_same_group_id.size(); j++) {
- size_t animation_index = animations_with_same_group_id[j];
- if (events) {
- AnimationEvent finished_event(
- AnimationEvent::FINISHED, element_id_,
- animations_[animation_index]->group(),
- animations_[animation_index]->target_property_id(),
- monotonic_time);
- finished_event.is_impl_only =
- animations_[animation_index]->is_impl_only();
- if (finished_event.is_impl_only) {
- // Notify delegate directly, do not record the event.
- if (animation_delegate_) {
- animation_delegate_->NotifyAnimationFinished(
- finished_event.monotonic_time, finished_event.target_property,
- finished_event.group_id);
- }
- } else {
- events->events_.push_back(finished_event);
- }
- }
- animations_[animation_index]->SetRunState(
- Animation::WAITING_FOR_DELETION, monotonic_time);
- }
- marked_animations_for_deletions = true;
- }
- }
-
- // Notify about animations waiting for deletion.
- // We need to purge animations marked for deletion, which happens in
- // PushProperties().
- if (marked_animations_for_deletions)
- SetNeedsPushProperties();
-}
-
-void AnimationPlayer::TickAnimation(base::TimeTicks monotonic_time,
- Animation* animation,
- AnimationTarget* target) {
- if ((animation->run_state() != Animation::STARTING &&
- animation->run_state() != Animation::RUNNING &&
- animation->run_state() != Animation::PAUSED) ||
- !animation->InEffect(monotonic_time)) {
- return;
- }
-
- AnimationCurve* curve = animation->curve();
- base::TimeDelta trimmed =
- animation->TrimTimeToCurrentIteration(monotonic_time);
-
- switch (curve->Type()) {
- case AnimationCurve::TRANSFORM:
- target->NotifyClientTransformOperationsAnimated(
- curve->ToTransformAnimationCurve()->GetValue(trimmed),
- animation->target_property_id(), animation);
- break;
- case AnimationCurve::FLOAT:
- target->NotifyClientFloatAnimated(
- curve->ToFloatAnimationCurve()->GetValue(trimmed),
- animation->target_property_id(), animation);
- break;
- case AnimationCurve::FILTER:
- target->NotifyClientFilterAnimated(
- curve->ToFilterAnimationCurve()->GetValue(trimmed),
- animation->target_property_id(), animation);
- break;
- case AnimationCurve::COLOR:
- target->NotifyClientColorAnimated(
- curve->ToColorAnimationCurve()->GetValue(trimmed),
- animation->target_property_id(), animation);
- break;
- case AnimationCurve::SCROLL_OFFSET:
- target->NotifyClientScrollOffsetAnimated(
- curve->ToScrollOffsetAnimationCurve()->GetValue(trimmed),
- animation->target_property_id(), animation);
- break;
- case AnimationCurve::SIZE:
- target->NotifyClientSizeAnimated(
- curve->ToSizeAnimationCurve()->GetValue(trimmed),
- animation->target_property_id(), animation);
- break;
- }
-}
-
-void AnimationPlayer::TickAnimations(base::TimeTicks monotonic_time) {
- DCHECK(element_animations_);
- for (auto& animation : animations_)
- TickAnimation(monotonic_time, animation.get(), element_animations_.get());
- last_tick_time_ = monotonic_time;
-}
-
-void AnimationPlayer::MarkFinishedAnimations(base::TimeTicks monotonic_time) {
- bool animation_finished = false;
-
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (!animations_[i]->is_finished() &&
- animations_[i]->IsFinishedAt(monotonic_time)) {
- animations_[i]->SetRunState(Animation::FINISHED, monotonic_time);
- animation_finished = true;
- SetNeedsPushProperties();
- }
- if (!animations_[i]->affects_active_elements() &&
- !animations_[i]->affects_pending_elements()) {
- switch (animations_[i]->run_state()) {
- case Animation::WAITING_FOR_TARGET_AVAILABILITY:
- case Animation::STARTING:
- case Animation::RUNNING:
- case Animation::PAUSED:
- animations_[i]->SetRunState(Animation::FINISHED, monotonic_time);
- animation_finished = true;
- break;
- default:
- break;
- }
- }
- }
-
- DCHECK(element_animations_);
- if (animation_finished)
- element_animations_->UpdateClientAnimationState();
}
void AnimationPlayer::ActivateAnimations() {
- bool animation_activated = false;
-
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (animations_[i]->affects_active_elements() !=
- animations_[i]->affects_pending_elements()) {
- animation_activated = true;
- }
- animations_[i]->set_affects_active_elements(
- animations_[i]->affects_pending_elements());
- }
-
- if (animation_activated)
- element_animations_->UpdateClientAnimationState();
-
- scroll_offset_animation_was_interrupted_ = false;
- UpdateTickingState(UpdateTickingType::NORMAL);
-}
-
-bool AnimationPlayer::HasTransformAnimationThatInflatesBounds() const {
- return IsCurrentlyAnimatingProperty(TargetProperty::TRANSFORM,
- ElementListType::ACTIVE) ||
- IsCurrentlyAnimatingProperty(TargetProperty::TRANSFORM,
- ElementListType::PENDING);
-}
-
-bool AnimationPlayer::TransformAnimationBoundsForBox(const gfx::BoxF& box,
- gfx::BoxF* bounds) const {
- DCHECK(HasTransformAnimationThatInflatesBounds())
- << "TransformAnimationBoundsForBox will give incorrect results if there "
- << "are no transform animations affecting bounds, non-animated transform "
- << "is not known";
-
- // Compute bounds based on animations for which is_finished() is false.
- // Do nothing if there are no such animations; in this case, it is assumed
- // that callers will take care of computing bounds based on the owning layer's
- // actual transform.
- *bounds = gfx::BoxF();
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (animations_[i]->is_finished() ||
- animations_[i]->target_property_id() != TargetProperty::TRANSFORM)
- continue;
-
- const TransformAnimationCurve* transform_animation_curve =
- animations_[i]->curve()->ToTransformAnimationCurve();
- gfx::BoxF animation_bounds;
- bool success =
- transform_animation_curve->AnimatedBoundsForBox(box, &animation_bounds);
- if (!success)
- return false;
- bounds->Union(animation_bounds);
- }
-
- return true;
-}
-
-bool AnimationPlayer::HasOnlyTranslationTransforms(
- ElementListType list_type) const {
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (animations_[i]->is_finished() ||
- animations_[i]->target_property_id() != TargetProperty::TRANSFORM)
- continue;
-
- if ((list_type == ElementListType::ACTIVE &&
- !animations_[i]->affects_active_elements()) ||
- (list_type == ElementListType::PENDING &&
- !animations_[i]->affects_pending_elements()))
- continue;
-
- const TransformAnimationCurve* transform_animation_curve =
- animations_[i]->curve()->ToTransformAnimationCurve();
- if (!transform_animation_curve->IsTranslation())
- return false;
- }
-
- return true;
-}
-
-bool AnimationPlayer::AnimationsPreserveAxisAlignment() const {
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (animations_[i]->is_finished() ||
- animations_[i]->target_property_id() != TargetProperty::TRANSFORM)
- continue;
-
- const TransformAnimationCurve* transform_animation_curve =
- animations_[i]->curve()->ToTransformAnimationCurve();
- if (!transform_animation_curve->PreservesAxisAlignment())
- return false;
- }
-
- return true;
-}
-
-bool AnimationPlayer::AnimationStartScale(ElementListType list_type,
- float* start_scale) const {
- *start_scale = 0.f;
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (animations_[i]->is_finished() ||
- animations_[i]->target_property_id() != TargetProperty::TRANSFORM)
- continue;
-
- if ((list_type == ElementListType::ACTIVE &&
- !animations_[i]->affects_active_elements()) ||
- (list_type == ElementListType::PENDING &&
- !animations_[i]->affects_pending_elements()))
- continue;
-
- bool forward_direction = true;
- switch (animations_[i]->direction()) {
- case Animation::Direction::NORMAL:
- case Animation::Direction::ALTERNATE_NORMAL:
- forward_direction = animations_[i]->playback_rate() >= 0.0;
- break;
- case Animation::Direction::REVERSE:
- case Animation::Direction::ALTERNATE_REVERSE:
- forward_direction = animations_[i]->playback_rate() < 0.0;
- break;
- }
-
- const TransformAnimationCurve* transform_animation_curve =
- animations_[i]->curve()->ToTransformAnimationCurve();
- float animation_start_scale = 0.f;
- if (!transform_animation_curve->AnimationStartScale(forward_direction,
- &animation_start_scale))
- return false;
- *start_scale = std::max(*start_scale, animation_start_scale);
- }
- return true;
-}
-
-bool AnimationPlayer::MaximumTargetScale(ElementListType list_type,
- float* max_scale) const {
- *max_scale = 0.f;
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (animations_[i]->is_finished() ||
- animations_[i]->target_property_id() != TargetProperty::TRANSFORM)
- continue;
-
- if ((list_type == ElementListType::ACTIVE &&
- !animations_[i]->affects_active_elements()) ||
- (list_type == ElementListType::PENDING &&
- !animations_[i]->affects_pending_elements()))
- continue;
-
- bool forward_direction = true;
- switch (animations_[i]->direction()) {
- case Animation::Direction::NORMAL:
- case Animation::Direction::ALTERNATE_NORMAL:
- forward_direction = animations_[i]->playback_rate() >= 0.0;
- break;
- case Animation::Direction::REVERSE:
- case Animation::Direction::ALTERNATE_REVERSE:
- forward_direction = animations_[i]->playback_rate() < 0.0;
- break;
- }
-
- const TransformAnimationCurve* transform_animation_curve =
- animations_[i]->curve()->ToTransformAnimationCurve();
- float animation_scale = 0.f;
- if (!transform_animation_curve->MaximumTargetScale(forward_direction,
- &animation_scale))
- return false;
- *max_scale = std::max(*max_scale, animation_scale);
- }
-
- return true;
-}
-
-bool AnimationPlayer::IsPotentiallyAnimatingProperty(
- TargetProperty::Type target_property,
- ElementListType list_type) const {
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (!animations_[i]->is_finished() &&
- animations_[i]->target_property_id() == target_property) {
- if ((list_type == ElementListType::ACTIVE &&
- animations_[i]->affects_active_elements()) ||
- (list_type == ElementListType::PENDING &&
- animations_[i]->affects_pending_elements()))
- return true;
- }
- }
- return false;
-}
-
-bool AnimationPlayer::IsCurrentlyAnimatingProperty(
- TargetProperty::Type target_property,
- ElementListType list_type) const {
- for (size_t i = 0; i < animations_.size(); ++i) {
- if (!animations_[i]->is_finished() &&
- animations_[i]->InEffect(last_tick_time_) &&
- animations_[i]->target_property_id() == target_property) {
- if ((list_type == ElementListType::ACTIVE &&
- animations_[i]->affects_active_elements()) ||
- (list_type == ElementListType::PENDING &&
- animations_[i]->affects_pending_elements()))
- return true;
- }
- }
- return false;
-}
-
-bool AnimationPlayer::HasElementInActiveList() const {
- DCHECK(element_animations_);
- return element_animations_->has_element_in_active_list();
-}
-
-gfx::ScrollOffset AnimationPlayer::ScrollOffsetForAnimation() const {
- DCHECK(element_animations_);
- return element_animations_->ScrollOffsetForAnimation();
+ animation_ticker_->ActivateAnimations();
+ animation_ticker_->UpdateTickingState(UpdateTickingType::NORMAL);
}
Animation* AnimationPlayer::GetAnimation(
TargetProperty::Type target_property) const {
- for (size_t i = 0; i < animations_.size(); ++i) {
- size_t index = animations_.size() - i - 1;
- if (animations_[index]->target_property_id() == target_property)
- return animations_[index].get();
- }
- return nullptr;
-}
-
-Animation* AnimationPlayer::GetAnimationById(int animation_id) const {
- for (size_t i = 0; i < animations_.size(); ++i)
- if (animations_[i]->id() == animation_id)
- return animations_[i].get();
- return nullptr;
-}
-
-void AnimationPlayer::GetPropertyAnimationState(
- PropertyAnimationState* pending_state,
- PropertyAnimationState* active_state) const {
- pending_state->Clear();
- active_state->Clear();
-
- for (const auto& animation : animations_) {
- if (!animation->is_finished()) {
- bool in_effect = animation->InEffect(last_tick_time_);
- bool active = animation->affects_active_elements();
- bool pending = animation->affects_pending_elements();
- int property = animation->target_property_id();
-
- if (pending)
- pending_state->potentially_animating[property] = true;
- if (pending && in_effect)
- pending_state->currently_running[property] = true;
-
- if (active)
- active_state->potentially_animating[property] = true;
- if (active && in_effect)
- active_state->currently_running[property] = true;
- }
- }
-}
-
-void AnimationPlayer::MarkAbortedAnimationsForDeletion(
- AnimationPlayer* animation_player_impl) const {
- bool animation_aborted = false;
-
- auto& animations_impl = animation_player_impl->animations_;
- for (const auto& animation_impl : animations_impl) {
- // If the animation has been aborted on the main thread, mark it for
- // deletion.
- if (Animation* animation = GetAnimationById(animation_impl->id())) {
- if (animation->run_state() == Animation::ABORTED) {
- animation_impl->SetRunState(Animation::WAITING_FOR_DELETION,
- animation_player_impl->last_tick_time_);
- animation->SetRunState(Animation::WAITING_FOR_DELETION,
- last_tick_time_);
- animation_aborted = true;
- }
- }
- }
-
- if (element_animations_ && animation_aborted)
- element_animations_->SetNeedsUpdateImplClientState();
-}
-
-void AnimationPlayer::PurgeAnimationsMarkedForDeletion(bool impl_only) {
- base::EraseIf(
- animations_, [impl_only](const std::unique_ptr<Animation>& animation) {
- return animation->run_state() == Animation::WAITING_FOR_DELETION &&
- (!impl_only || animation->is_impl_only());
- });
-}
-
-void AnimationPlayer::PushNewAnimationsToImplThread(
- AnimationPlayer* animation_player_impl) const {
- // Any new animations owned by the main thread's AnimationPlayer are cloned
- // and added to the impl thread's AnimationPlayer.
- for (size_t i = 0; i < animations_.size(); ++i) {
- // If the animation is already running on the impl thread, there is no
- // need to copy it over.
- if (animation_player_impl->GetAnimationById(animations_[i]->id()))
- continue;
-
- if (animations_[i]->target_property_id() == TargetProperty::SCROLL_OFFSET &&
- !animations_[i]
- ->curve()
- ->ToScrollOffsetAnimationCurve()
- ->HasSetInitialValue()) {
- gfx::ScrollOffset current_scroll_offset;
- if (animation_player_impl->HasElementInActiveList()) {
- current_scroll_offset =
- animation_player_impl->ScrollOffsetForAnimation();
- } else {
- // The owning layer isn't yet in the active tree, so the main thread
- // scroll offset will be up to date.
- current_scroll_offset = ScrollOffsetForAnimation();
- }
- animations_[i]->curve()->ToScrollOffsetAnimationCurve()->SetInitialValue(
- current_scroll_offset);
- }
-
- // The new animation should be set to run as soon as possible.
- Animation::RunState initial_run_state =
- Animation::WAITING_FOR_TARGET_AVAILABILITY;
- std::unique_ptr<Animation> to_add(
- animations_[i]->CloneAndInitialize(initial_run_state));
- DCHECK(!to_add->needs_synchronized_start_time());
- to_add->set_affects_active_elements(false);
- animation_player_impl->AddAnimation(std::move(to_add));
- }
-}
-
-static bool IsCompleted(Animation* animation,
- const AnimationPlayer* main_thread_player) {
- if (animation->is_impl_only()) {
- return (animation->run_state() == Animation::WAITING_FOR_DELETION);
- } else {
- Animation* main_thread_animation =
- main_thread_player->GetAnimationById(animation->id());
- return !main_thread_animation || main_thread_animation->is_finished();
- }
-}
-
-void AnimationPlayer::RemoveAnimationsCompletedOnMainThread(
- AnimationPlayer* animation_player_impl) const {
- bool animation_completed = false;
-
- // Animations removed on the main thread should no longer affect pending
- // elements, and should stop affecting active elements after the next call
- // to ActivateAnimations. If already WAITING_FOR_DELETION, they can be removed
- // immediately.
- auto& animations = animation_player_impl->animations_;
- for (const auto& animation : animations) {
- if (IsCompleted(animation.get(), this)) {
- animation->set_affects_pending_elements(false);
- animation_completed = true;
- }
- }
- auto affects_active_only_and_is_waiting_for_deletion =
- [](const std::unique_ptr<Animation>& animation) {
- return animation->run_state() == Animation::WAITING_FOR_DELETION &&
- !animation->affects_pending_elements();
- };
- base::EraseIf(animations, affects_active_only_and_is_waiting_for_deletion);
-
- if (element_animations_ && animation_completed)
- element_animations_->SetNeedsUpdateImplClientState();
-}
-
-void AnimationPlayer::PushPropertiesToImplThread(
- AnimationPlayer* animation_player_impl) {
- for (size_t i = 0; i < animations_.size(); ++i) {
- Animation* current_impl =
- animation_player_impl->GetAnimationById(animations_[i]->id());
- if (current_impl)
- animations_[i]->PushPropertiesTo(current_impl);
- }
-
- animation_player_impl->scroll_offset_animation_was_interrupted_ =
- scroll_offset_animation_was_interrupted_;
- scroll_offset_animation_was_interrupted_ = false;
+ return animation_ticker_->GetAnimation(target_property);
}
std::string AnimationPlayer::ToString() const {
return base::StringPrintf(
"AnimationPlayer{id=%d, element_id=%s, animations=[%s]}", id_,
- element_id_.ToString().c_str(), AnimationsToString().c_str());
-}
-
-std::string AnimationPlayer::AnimationsToString() const {
- std::string str;
- for (size_t i = 0; i < animations_.size(); i++) {
- if (i > 0)
- str.append(", ");
- str.append(animations_[i]->ToString());
- }
- return str;
+ animation_ticker_->element_id().ToString().c_str(),
+ animation_ticker_->AnimationsToString().c_str());
}
} // namespace cc
diff --git a/chromium/cc/animation/animation_player.h b/chromium/cc/animation/animation_player.h
index 277854b28b9..7faaf494aed 100644
--- a/chromium/cc/animation/animation_player.h
+++ b/chromium/cc/animation/animation_player.h
@@ -22,17 +22,23 @@ class AnimationDelegate;
class AnimationEvents;
class AnimationHost;
class AnimationTimeline;
+class AnimationTicker;
struct AnimationEvent;
-struct PropertyAnimationState;
-
-// An AnimationPlayer owns all animations to be run on particular CC Layer.
-// Multiple AnimationPlayers can be attached to one layer. In this case,
-// they share common ElementAnimations so the
-// ElementAnimations-to-Layer relationship is 1:1.
-// For now, the blink logic is responsible for handling of conflicting
-// same-property animations.
-// Each AnimationPlayer has its copy on the impl thread.
-// This is a CC counterpart for blink::AnimationPlayer (in 1:1 relationship).
+
+// An AnimationPlayer manages grouped sets of animations (each set of which are
+// stored in an AnimationTicker), and handles the interaction with the
+// AnimationHost and AnimationTimeline.
+//
+// This class is a CC counterpart for blink::Animation, currently in a 1:1
+// relationship. Currently the blink logic is responsible for handling of
+// conflicting same-property animations.
+//
+// Each cc AnimationPlayer has a copy on the impl thread, and will take care of
+// synchronizing properties to/from the impl thread when requested.
+//
+// NOTE(smcgruer): As of 2017/09/06 there is a 1:1 relationship between
+// AnimationPlayer and the AnimationTicker. This is intended to become a 1:N
+// relationship to allow for grouped animations.
class CC_ANIMATION_EXPORT AnimationPlayer
: public base::RefCounted<AnimationPlayer> {
public:
@@ -40,13 +46,14 @@ class CC_ANIMATION_EXPORT AnimationPlayer
scoped_refptr<AnimationPlayer> CreateImplInstance() const;
int id() const { return id_; }
- ElementId element_id() const { return element_id_; }
+ ElementId element_id() const;
// Parent AnimationHost. AnimationPlayer can be detached from
// AnimationTimeline.
AnimationHost* animation_host() { return animation_host_; }
const AnimationHost* animation_host() const { return animation_host_; }
void SetAnimationHost(AnimationHost* animation_host);
+ bool has_animation_host() const { return !!animation_host_; }
// Parent AnimationTimeline.
AnimationTimeline* animation_timeline() { return animation_timeline_; }
@@ -55,10 +62,12 @@ class CC_ANIMATION_EXPORT AnimationPlayer
}
void SetAnimationTimeline(AnimationTimeline* timeline);
- // ElementAnimations object where this player is listed.
- scoped_refptr<ElementAnimations> element_animations() const {
- return element_animations_;
- }
+ AnimationTicker* animation_ticker() const { return animation_ticker_.get(); }
+
+ // TODO(smcgruer): Only used by a ui/ unittest: remove.
+ bool has_any_animation() const;
+
+ scoped_refptr<ElementAnimations> element_animations() const;
void set_animation_delegate(AnimationDelegate* delegate) {
animation_delegate_ = delegate;
@@ -79,152 +88,48 @@ class CC_ANIMATION_EXPORT AnimationPlayer
void Tick(base::TimeTicks monotonic_time);
void UpdateState(bool start_ready_animations, AnimationEvents* events);
- void UpdateTickingState(UpdateTickingType type);
- void RemoveFromTicking();
+ void AddToTicking();
+ void AnimationRemovedFromTicking();
// AnimationDelegate routing.
- bool NotifyAnimationStarted(const AnimationEvent& event);
- bool NotifyAnimationFinished(const AnimationEvent& event);
- bool NotifyAnimationAborted(const AnimationEvent& event);
+ void NotifyAnimationStarted(const AnimationEvent& event);
+ void NotifyAnimationFinished(const AnimationEvent& event);
+ void NotifyAnimationAborted(const AnimationEvent& event);
void NotifyAnimationTakeover(const AnimationEvent& event);
bool NotifyAnimationFinishedForTesting(TargetProperty::Type target_property,
int group_id);
- // Returns true if there are any animations that have neither finished nor
- // aborted.
- bool HasTickingAnimation() const;
-
- // Returns true if there are any animations at all to process.
- bool has_any_animation() const { return !animations_.empty(); }
-
- bool needs_push_properties() const { return needs_push_properties_; }
void SetNeedsPushProperties();
- bool HasNonDeletedAnimation() const;
-
- bool needs_to_start_animations() const { return needs_to_start_animations_; }
-
- void StartAnimations(base::TimeTicks monotonic_time);
- void PromoteStartedAnimations(base::TimeTicks monotonic_time,
- AnimationEvents* events);
- void MarkAnimationsForDeletion(base::TimeTicks monotonic_time,
- AnimationEvents* events);
-
- static void TickAnimation(base::TimeTicks monotonic_time,
- Animation* animation,
- AnimationTarget* target);
- void TickAnimations(base::TimeTicks monotonic_time);
-
- void MarkFinishedAnimations(base::TimeTicks monotonic_time);
-
// Make animations affect active elements if and only if they affect
// pending elements. Any animations that no longer affect any elements
// are deleted.
void ActivateAnimations();
- bool HasTransformAnimationThatInflatesBounds() const;
-
- bool TransformAnimationBoundsForBox(const gfx::BoxF& box,
- gfx::BoxF* bounds) const;
- bool HasOnlyTranslationTransforms(ElementListType list_type) const;
- bool AnimationsPreserveAxisAlignment() const;
-
- // Sets |start_scale| to the maximum of starting animation scale along any
- // dimension at any destination in active animations. Returns false if the
- // starting scale cannot be computed.
- bool AnimationStartScale(ElementListType list_type, float* start_scale) const;
-
- // Sets |max_scale| to the maximum scale along any dimension at any
- // destination in active animations. Returns false if the maximum scale cannot
- // be computed.
- bool MaximumTargetScale(ElementListType list_type, float* max_scale) const;
-
- // Returns true if there is an animation that is either currently animating
- // the given property or scheduled to animate this property in the future, and
- // that affects the given tree type.
- bool IsPotentiallyAnimatingProperty(TargetProperty::Type target_property,
- ElementListType list_type) const;
-
- // Returns true if there is an animation that is currently animating the given
- // property and that affects the given tree type.
- bool IsCurrentlyAnimatingProperty(TargetProperty::Type target_property,
- ElementListType list_type) const;
-
- bool HasElementInActiveList() const;
- gfx::ScrollOffset ScrollOffsetForAnimation() const;
-
// Returns the animation animating the given property that is either
// running, or is next to run, if such an animation exists.
Animation* GetAnimation(TargetProperty::Type target_property) const;
- // Returns animation for the given unique animation id.
- Animation* GetAnimationById(int animation_id) const;
-
- void GetPropertyAnimationState(PropertyAnimationState* pending_state,
- PropertyAnimationState* active_state) const;
-
- // When a scroll animation is removed on the main thread, its compositor
- // thread counterpart continues producing scroll deltas until activation.
- // These scroll deltas need to be cleared at activation, so that the active
- // element's scroll offset matches the offset provided by the main thread
- // rather than a combination of this offset and scroll deltas produced by
- // the removed animation. This is to provide the illusion of synchronicity to
- // JS that simultaneously removes an animation and sets the scroll offset.
- bool scroll_offset_animation_was_interrupted() const {
- return scroll_offset_animation_was_interrupted_;
- }
-
std::string ToString() const;
+ void SetNeedsCommit();
+
private:
friend class base::RefCounted<AnimationPlayer>;
explicit AnimationPlayer(int id);
~AnimationPlayer();
- void SetNeedsCommit();
-
void RegisterPlayer();
void UnregisterPlayer();
- void BindElementAnimations();
- void UnbindElementAnimations();
-
- void AnimationAdded();
-
- void MarkAbortedAnimationsForDeletion(
- AnimationPlayer* animation_player_impl) const;
- void PurgeAnimationsMarkedForDeletion(bool impl_only);
- void PushNewAnimationsToImplThread(
- AnimationPlayer* animation_player_impl) const;
- void RemoveAnimationsCompletedOnMainThread(
- AnimationPlayer* animation_player_impl) const;
- void PushPropertiesToImplThread(AnimationPlayer* animation_player_impl);
-
- std::string AnimationsToString() const;
-
- using Animations = std::vector<std::unique_ptr<Animation>>;
- Animations animations_;
-
AnimationHost* animation_host_;
AnimationTimeline* animation_timeline_;
- // element_animations isn't null if player attached to an element (layer).
- scoped_refptr<ElementAnimations> element_animations_;
AnimationDelegate* animation_delegate_;
int id_;
- ElementId element_id_;
- bool needs_push_properties_;
- base::TimeTicks last_tick_time_;
-
- // Only try to start animations when new animations are added or when the
- // previous attempt at starting animations failed to start all animations.
- bool needs_to_start_animations_;
-
- // This is used to ensure that we don't spam the animation host.
- bool is_ticking_;
- bool scroll_offset_animation_was_interrupted_;
+ std::unique_ptr<AnimationTicker> animation_ticker_;
DISALLOW_COPY_AND_ASSIGN(AnimationPlayer);
};
diff --git a/chromium/cc/animation/animation_player_unittest.cc b/chromium/cc/animation/animation_player_unittest.cc
index 91891566d65..6eb366e6261 100644
--- a/chromium/cc/animation/animation_player_unittest.cc
+++ b/chromium/cc/animation/animation_player_unittest.cc
@@ -8,6 +8,7 @@
#include "cc/animation/animation_delegate.h"
#include "cc/animation/animation_host.h"
#include "cc/animation/animation_id_provider.h"
+#include "cc/animation/animation_ticker.h"
#include "cc/animation/animation_timeline.h"
#include "cc/animation/element_animations.h"
#include "cc/test/animation_test_common.h"
@@ -25,64 +26,65 @@ class AnimationPlayerTest : public AnimationTimelinesTest {
// See element_animations_unittest.cc for active/pending observers tests.
TEST_F(AnimationPlayerTest, AttachDetachLayerIfTimelineAttached) {
- EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(false));
+ EXPECT_TRUE(CheckTickerTimelineNeedsPushProperties(false));
host_->AddAnimationTimeline(timeline_);
EXPECT_TRUE(timeline_->needs_push_properties());
- EXPECT_FALSE(player_->needs_push_properties());
+ EXPECT_FALSE(player_->animation_ticker()->needs_push_properties());
timeline_->AttachPlayer(player_);
EXPECT_FALSE(player_->element_animations());
EXPECT_FALSE(player_->element_id());
EXPECT_TRUE(timeline_->needs_push_properties());
- EXPECT_FALSE(player_->needs_push_properties());
+ EXPECT_FALSE(player_->animation_ticker()->needs_push_properties());
host_->PushPropertiesTo(host_impl_);
- EXPECT_FALSE(GetImplPlayerForLayerId(element_id_));
+ EXPECT_FALSE(GetImplTickerForLayerId(element_id_));
GetImplTimelineAndPlayerByID();
EXPECT_FALSE(player_impl_->element_animations());
EXPECT_FALSE(player_impl_->element_id());
- EXPECT_FALSE(player_->needs_push_properties());
+ EXPECT_FALSE(player_->animation_ticker()->needs_push_properties());
EXPECT_FALSE(timeline_->needs_push_properties());
player_->AttachElement(element_id_);
- EXPECT_EQ(player_, GetPlayerForElementId(element_id_));
+ EXPECT_EQ(player_->animation_ticker(), GetTickerForElementId(element_id_));
EXPECT_TRUE(player_->element_animations());
EXPECT_EQ(player_->element_id(), element_id_);
- EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(true));
+ EXPECT_TRUE(CheckTickerTimelineNeedsPushProperties(true));
host_->PushPropertiesTo(host_impl_);
- EXPECT_EQ(player_impl_, GetImplPlayerForLayerId(element_id_));
+ EXPECT_EQ(player_impl_->animation_ticker(),
+ GetImplTickerForLayerId(element_id_));
EXPECT_TRUE(player_impl_->element_animations());
EXPECT_EQ(player_impl_->element_id(), element_id_);
- EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(false));
+ EXPECT_TRUE(CheckTickerTimelineNeedsPushProperties(false));
player_->DetachElement();
- EXPECT_FALSE(GetPlayerForElementId(element_id_));
+ EXPECT_FALSE(GetTickerForElementId(element_id_));
EXPECT_FALSE(player_->element_animations());
EXPECT_FALSE(player_->element_id());
- EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(true));
+ EXPECT_TRUE(CheckTickerTimelineNeedsPushProperties(true));
host_->PushPropertiesTo(host_impl_);
- EXPECT_FALSE(GetImplPlayerForLayerId(element_id_));
+ EXPECT_FALSE(GetImplTickerForLayerId(element_id_));
EXPECT_FALSE(player_impl_->element_animations());
EXPECT_FALSE(player_impl_->element_id());
- EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(false));
+ EXPECT_TRUE(CheckTickerTimelineNeedsPushProperties(false));
timeline_->DetachPlayer(player_);
EXPECT_FALSE(player_->animation_timeline());
EXPECT_FALSE(player_->element_animations());
EXPECT_FALSE(player_->element_id());
EXPECT_TRUE(timeline_->needs_push_properties());
- EXPECT_FALSE(player_->needs_push_properties());
+ EXPECT_FALSE(player_->animation_ticker()->needs_push_properties());
host_->PushPropertiesTo(host_impl_);
- EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(false));
+ EXPECT_TRUE(CheckTickerTimelineNeedsPushProperties(false));
}
TEST_F(AnimationPlayerTest, AttachDetachTimelineIfLayerAttached) {
@@ -90,29 +92,29 @@ TEST_F(AnimationPlayerTest, AttachDetachTimelineIfLayerAttached) {
EXPECT_FALSE(player_->element_animations());
EXPECT_FALSE(player_->element_id());
- EXPECT_FALSE(player_->needs_push_properties());
+ EXPECT_FALSE(player_->animation_ticker()->needs_push_properties());
player_->AttachElement(element_id_);
EXPECT_FALSE(player_->animation_timeline());
- EXPECT_FALSE(GetPlayerForElementId(element_id_));
+ EXPECT_FALSE(GetTickerForElementId(element_id_));
EXPECT_FALSE(player_->element_animations());
EXPECT_EQ(player_->element_id(), element_id_);
- EXPECT_FALSE(player_->needs_push_properties());
+ EXPECT_FALSE(player_->animation_ticker()->needs_push_properties());
timeline_->AttachPlayer(player_);
EXPECT_EQ(timeline_, player_->animation_timeline());
- EXPECT_EQ(player_, GetPlayerForElementId(element_id_));
+ EXPECT_EQ(player_->animation_ticker(), GetTickerForElementId(element_id_));
EXPECT_TRUE(player_->element_animations());
EXPECT_EQ(player_->element_id(), element_id_);
- EXPECT_TRUE(player_->needs_push_properties());
+ EXPECT_TRUE(player_->animation_ticker()->needs_push_properties());
// Removing player from timeline detaches layer.
timeline_->DetachPlayer(player_);
EXPECT_FALSE(player_->animation_timeline());
- EXPECT_FALSE(GetPlayerForElementId(element_id_));
+ EXPECT_FALSE(GetTickerForElementId(element_id_));
EXPECT_FALSE(player_->element_animations());
EXPECT_FALSE(player_->element_id());
- EXPECT_TRUE(player_->needs_push_properties());
+ EXPECT_TRUE(player_->animation_ticker()->needs_push_properties());
}
TEST_F(AnimationPlayerTest, PropertiesMutate) {
@@ -123,10 +125,10 @@ TEST_F(AnimationPlayerTest, PropertiesMutate) {
host_->AddAnimationTimeline(timeline_);
timeline_->AttachPlayer(player_);
player_->AttachElement(element_id_);
- EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(true));
+ EXPECT_TRUE(CheckTickerTimelineNeedsPushProperties(true));
host_->PushPropertiesTo(host_impl_);
- EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(false));
+ EXPECT_TRUE(CheckTickerTimelineNeedsPushProperties(false));
const float start_opacity = .7f;
const float end_opacity = .3f;
@@ -145,10 +147,10 @@ TEST_F(AnimationPlayerTest, PropertiesMutate) {
transform_y);
AddAnimatedFilterToPlayer(player_.get(), duration, start_brightness,
end_brightness);
- EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(true));
+ EXPECT_TRUE(CheckTickerTimelineNeedsPushProperties(true));
host_->PushPropertiesTo(host_impl_);
- EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(false));
+ EXPECT_TRUE(CheckTickerTimelineNeedsPushProperties(false));
EXPECT_FALSE(client_.IsPropertyMutated(element_id_, ElementListType::ACTIVE,
TargetProperty::OPACITY));
@@ -169,11 +171,11 @@ TEST_F(AnimationPlayerTest, PropertiesMutate) {
base::TimeTicks time;
time += base::TimeDelta::FromSecondsD(0.1);
TickAnimationsTransferEvents(time, 3u);
- EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(false));
+ EXPECT_TRUE(CheckTickerTimelineNeedsPushProperties(false));
time += base::TimeDelta::FromSecondsD(duration);
TickAnimationsTransferEvents(time, 3u);
- EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(true));
+ EXPECT_TRUE(CheckTickerTimelineNeedsPushProperties(true));
client_.ExpectOpacityPropertyMutated(element_id_, ElementListType::ACTIVE,
end_opacity);
@@ -257,8 +259,8 @@ TEST_F(AnimationPlayerTest, AttachTwoPlayersToOneLayer) {
EXPECT_TRUE(delegate2.started());
EXPECT_FALSE(delegate2.finished());
- EXPECT_FALSE(player1->needs_push_properties());
- EXPECT_FALSE(player2->needs_push_properties());
+ EXPECT_FALSE(player1->animation_ticker()->needs_push_properties());
+ EXPECT_FALSE(player2->animation_ticker()->needs_push_properties());
time += base::TimeDelta::FromSecondsD(duration);
TickAnimationsTransferEvents(time, 2u);
@@ -266,8 +268,8 @@ TEST_F(AnimationPlayerTest, AttachTwoPlayersToOneLayer) {
EXPECT_TRUE(delegate1.finished());
EXPECT_TRUE(delegate2.finished());
- EXPECT_TRUE(player1->needs_push_properties());
- EXPECT_TRUE(player2->needs_push_properties());
+ EXPECT_TRUE(player1->animation_ticker()->needs_push_properties());
+ EXPECT_TRUE(player2->animation_ticker()->needs_push_properties());
client_.ExpectOpacityPropertyMutated(element_id_, ElementListType::ACTIVE,
end_opacity);
@@ -299,15 +301,15 @@ TEST_F(AnimationPlayerTest, AddRemoveAnimationToNonAttachedPlayer) {
AddOpacityTransitionToPlayer(player_.get(), duration, start_opacity,
end_opacity, false);
- EXPECT_FALSE(player_->needs_push_properties());
+ EXPECT_FALSE(player_->animation_ticker()->needs_push_properties());
host_->AddAnimationTimeline(timeline_);
timeline_->AttachPlayer(player_);
- EXPECT_FALSE(player_->needs_push_properties());
+ EXPECT_FALSE(player_->animation_ticker()->needs_push_properties());
EXPECT_FALSE(player_->element_animations());
player_->RemoveAnimation(filter_id);
- EXPECT_FALSE(player_->needs_push_properties());
+ EXPECT_FALSE(player_->animation_ticker()->needs_push_properties());
player_->AttachElement(element_id_);
@@ -316,7 +318,7 @@ TEST_F(AnimationPlayerTest, AddRemoveAnimationToNonAttachedPlayer) {
TargetProperty::FILTER));
EXPECT_TRUE(player_->element_animations()->HasAnyAnimationTargetingProperty(
TargetProperty::OPACITY));
- EXPECT_TRUE(player_->needs_push_properties());
+ EXPECT_TRUE(player_->animation_ticker()->needs_push_properties());
host_->PushPropertiesTo(host_impl_);
@@ -386,27 +388,29 @@ TEST_F(AnimationPlayerTest, SwitchToLayer) {
GetImplTimelineAndPlayerByID();
- EXPECT_EQ(player_, GetPlayerForElementId(element_id_));
+ EXPECT_EQ(player_->animation_ticker(), GetTickerForElementId(element_id_));
EXPECT_TRUE(player_->element_animations());
EXPECT_EQ(player_->element_id(), element_id_);
- EXPECT_EQ(player_impl_, GetImplPlayerForLayerId(element_id_));
+ EXPECT_EQ(player_impl_->animation_ticker(),
+ GetImplTickerForLayerId(element_id_));
EXPECT_TRUE(player_impl_->element_animations());
EXPECT_EQ(player_impl_->element_id(), element_id_);
- EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(false));
+ EXPECT_TRUE(CheckTickerTimelineNeedsPushProperties(false));
const ElementId new_element_id(NextTestLayerId());
player_->DetachElement();
player_->AttachElement(new_element_id);
- EXPECT_EQ(player_, GetPlayerForElementId(new_element_id));
+ EXPECT_EQ(player_->animation_ticker(), GetTickerForElementId(new_element_id));
EXPECT_TRUE(player_->element_animations());
EXPECT_EQ(player_->element_id(), new_element_id);
- EXPECT_TRUE(CheckPlayerTimelineNeedsPushProperties(true));
+ EXPECT_TRUE(CheckTickerTimelineNeedsPushProperties(true));
host_->PushPropertiesTo(host_impl_);
- EXPECT_EQ(player_impl_, GetImplPlayerForLayerId(new_element_id));
+ EXPECT_EQ(player_impl_->animation_ticker(),
+ GetImplTickerForLayerId(new_element_id));
EXPECT_TRUE(player_impl_->element_animations());
EXPECT_EQ(player_impl_->element_id(), new_element_id);
}
diff --git a/chromium/cc/animation/animation_ticker.cc b/chromium/cc/animation/animation_ticker.cc
new file mode 100644
index 00000000000..d65c10b1261
--- /dev/null
+++ b/chromium/cc/animation/animation_ticker.cc
@@ -0,0 +1,1030 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/animation/animation_ticker.h"
+
+#include "base/stl_util.h"
+#include "base/time/time.h"
+#include "cc/animation/animation.h"
+#include "cc/animation/animation_curve.h"
+#include "cc/animation/animation_host.h"
+#include "cc/animation/animation_player.h"
+#include "cc/animation/scroll_offset_animation_curve.h"
+#include "cc/animation/transform_operations.h"
+#include "cc/trees/property_animation_state.h"
+
+namespace cc {
+
+AnimationTicker::AnimationTicker(AnimationPlayer* animation_player)
+ : animation_player_(animation_player),
+ element_animations_(),
+ needs_to_start_animations_(false),
+ scroll_offset_animation_was_interrupted_(false),
+ is_ticking_(false),
+ needs_push_properties_(false) {
+ DCHECK(animation_player_);
+}
+
+AnimationTicker::~AnimationTicker() {
+ DCHECK(!has_bound_element_animations());
+}
+
+void AnimationTicker::SetNeedsPushProperties() {
+ needs_push_properties_ = true;
+
+ // TODO(smcgruer): We only need the below calls when needs_push_properties_
+ // goes from false to true - see http://crbug.com/764405
+ DCHECK(element_animations());
+ element_animations()->SetNeedsPushProperties();
+
+ animation_player_->SetNeedsPushProperties();
+}
+
+void AnimationTicker::BindElementAnimations(
+ ElementAnimations* element_animations) {
+ DCHECK(element_animations);
+ DCHECK(!element_animations_);
+ element_animations_ = element_animations;
+
+ if (has_any_animation())
+ AnimationAdded();
+ SetNeedsPushProperties();
+}
+
+void AnimationTicker::UnbindElementAnimations() {
+ SetNeedsPushProperties();
+ element_animations_ = nullptr;
+}
+
+void AnimationTicker::AttachElement(ElementId element_id) {
+ DCHECK(!element_id_);
+ DCHECK(element_id);
+ element_id_ = element_id;
+}
+
+void AnimationTicker::DetachElement() {
+ DCHECK(element_id_);
+ element_id_ = ElementId();
+}
+
+void AnimationTicker::Tick(base::TimeTicks monotonic_time) {
+ DCHECK(has_bound_element_animations());
+ if (!element_animations_->has_element_in_any_list())
+ return;
+
+ if (needs_to_start_animations_)
+ StartAnimations(monotonic_time);
+
+ for (auto& animation : animations_)
+ TickAnimation(monotonic_time, animation.get(), element_animations_.get());
+
+ last_tick_time_ = monotonic_time;
+ element_animations_->UpdateClientAnimationState();
+}
+
+void AnimationTicker::TickAnimation(base::TimeTicks monotonic_time,
+ Animation* animation,
+ AnimationTarget* target) {
+ if ((animation->run_state() != Animation::STARTING &&
+ animation->run_state() != Animation::RUNNING &&
+ animation->run_state() != Animation::PAUSED) ||
+ !animation->InEffect(monotonic_time)) {
+ return;
+ }
+
+ AnimationCurve* curve = animation->curve();
+ base::TimeDelta trimmed =
+ animation->TrimTimeToCurrentIteration(monotonic_time);
+
+ switch (curve->Type()) {
+ case AnimationCurve::TRANSFORM:
+ target->NotifyClientTransformOperationsAnimated(
+ curve->ToTransformAnimationCurve()->GetValue(trimmed),
+ animation->target_property_id(), animation);
+ break;
+ case AnimationCurve::FLOAT:
+ target->NotifyClientFloatAnimated(
+ curve->ToFloatAnimationCurve()->GetValue(trimmed),
+ animation->target_property_id(), animation);
+ break;
+ case AnimationCurve::FILTER:
+ target->NotifyClientFilterAnimated(
+ curve->ToFilterAnimationCurve()->GetValue(trimmed),
+ animation->target_property_id(), animation);
+ break;
+ case AnimationCurve::COLOR:
+ target->NotifyClientColorAnimated(
+ curve->ToColorAnimationCurve()->GetValue(trimmed),
+ animation->target_property_id(), animation);
+ break;
+ case AnimationCurve::SCROLL_OFFSET:
+ target->NotifyClientScrollOffsetAnimated(
+ curve->ToScrollOffsetAnimationCurve()->GetValue(trimmed),
+ animation->target_property_id(), animation);
+ break;
+ case AnimationCurve::SIZE:
+ target->NotifyClientSizeAnimated(
+ curve->ToSizeAnimationCurve()->GetValue(trimmed),
+ animation->target_property_id(), animation);
+ break;
+ }
+}
+
+void AnimationTicker::RemoveFromTicking() {
+ is_ticking_ = false;
+ // Resetting last_tick_time_ here ensures that calling ::UpdateState
+ // before ::Animate doesn't start an animation.
+ last_tick_time_ = base::TimeTicks();
+ animation_player_->AnimationRemovedFromTicking();
+}
+
+void AnimationTicker::UpdateState(bool start_ready_animations,
+ AnimationEvents* events) {
+ DCHECK(has_bound_element_animations());
+ if (!element_animations_->has_element_in_active_list())
+ return;
+
+ // Animate hasn't been called, this happens if an element has been added
+ // between the Commit and Draw phases.
+ if (last_tick_time_ == base::TimeTicks())
+ return;
+
+ if (start_ready_animations)
+ PromoteStartedAnimations(events);
+
+ MarkFinishedAnimations(last_tick_time_);
+ MarkAnimationsForDeletion(last_tick_time_, events);
+ PurgeAnimationsMarkedForDeletion(/* impl_only */ true);
+
+ if (start_ready_animations) {
+ if (needs_to_start_animations_) {
+ StartAnimations(last_tick_time_);
+ PromoteStartedAnimations(events);
+ }
+ }
+}
+
+void AnimationTicker::UpdateTickingState(UpdateTickingType type) {
+ bool force = type == UpdateTickingType::FORCE;
+ if (animation_player_->has_animation_host()) {
+ bool was_ticking = is_ticking_;
+ is_ticking_ = HasNonDeletedAnimation();
+
+ bool has_element_in_any_list =
+ element_animations_->has_element_in_any_list();
+
+ if (is_ticking_ && ((!was_ticking && has_element_in_any_list) || force)) {
+ animation_player_->AddToTicking();
+ } else if (!is_ticking_ && (was_ticking || force)) {
+ RemoveFromTicking();
+ }
+ }
+}
+
+void AnimationTicker::AddAnimation(std::unique_ptr<Animation> animation) {
+ AnimationHost* animation_host = animation_player_->animation_host();
+ DCHECK(animation->target_property_id() != TargetProperty::SCROLL_OFFSET ||
+ (animation_host && animation_host->SupportsScrollAnimations()));
+ DCHECK(!animation->is_impl_only() ||
+ animation->target_property_id() == TargetProperty::SCROLL_OFFSET);
+
+ animations_.push_back(std::move(animation));
+
+ if (has_bound_element_animations()) {
+ AnimationAdded();
+ SetNeedsPushProperties();
+ }
+}
+
+void AnimationTicker::PauseAnimation(int animation_id, double time_offset) {
+ const base::TimeDelta time_delta = base::TimeDelta::FromSecondsD(time_offset);
+ for (auto& animation : animations_) {
+ if (animation->id() == animation_id) {
+ animation->SetRunState(
+ Animation::PAUSED,
+ time_delta + animation->start_time() + animation->time_offset());
+ }
+ }
+
+ if (has_bound_element_animations()) {
+ animation_player_->SetNeedsCommit();
+ SetNeedsPushProperties();
+ }
+}
+
+void AnimationTicker::RemoveAnimation(int animation_id) {
+ bool animation_removed = false;
+
+ // Since we want to use the animations that we're going to remove, we need to
+ // use a stable_parition here instead of remove_if. Remove_if leaves the
+ // removed items in an unspecified state.
+ auto animations_to_remove = std::stable_partition(
+ animations_.begin(), animations_.end(),
+ [animation_id](const std::unique_ptr<Animation>& animation) {
+ return animation->id() != animation_id;
+ });
+ for (auto it = animations_to_remove; it != animations_.end(); ++it) {
+ if ((*it)->target_property_id() == TargetProperty::SCROLL_OFFSET) {
+ if (has_bound_element_animations())
+ scroll_offset_animation_was_interrupted_ = true;
+ } else if (!(*it)->is_finished()) {
+ animation_removed = true;
+ }
+ }
+
+ animations_.erase(animations_to_remove, animations_.end());
+
+ if (has_bound_element_animations()) {
+ UpdateTickingState(UpdateTickingType::NORMAL);
+ if (animation_removed)
+ element_animations_->UpdateClientAnimationState();
+ animation_player_->SetNeedsCommit();
+ SetNeedsPushProperties();
+ }
+}
+
+void AnimationTicker::AbortAnimation(int animation_id) {
+ if (Animation* animation = GetAnimationById(animation_id)) {
+ if (!animation->is_finished()) {
+ animation->SetRunState(Animation::ABORTED, last_tick_time_);
+ if (has_bound_element_animations())
+ element_animations_->UpdateClientAnimationState();
+ }
+ }
+
+ if (has_bound_element_animations()) {
+ animation_player_->SetNeedsCommit();
+ SetNeedsPushProperties();
+ }
+}
+
+void AnimationTicker::AbortAnimations(TargetProperty::Type target_property,
+ bool needs_completion) {
+ if (needs_completion)
+ DCHECK(target_property == TargetProperty::SCROLL_OFFSET);
+
+ bool aborted_animation = false;
+ for (auto& animation : animations_) {
+ if (animation->target_property_id() == target_property &&
+ !animation->is_finished()) {
+ // Currently only impl-only scroll offset animations can be completed on
+ // the main thread.
+ if (needs_completion && animation->is_impl_only()) {
+ animation->SetRunState(Animation::ABORTED_BUT_NEEDS_COMPLETION,
+ last_tick_time_);
+ } else {
+ animation->SetRunState(Animation::ABORTED, last_tick_time_);
+ }
+ aborted_animation = true;
+ }
+ }
+
+ if (has_bound_element_animations()) {
+ if (aborted_animation)
+ element_animations_->UpdateClientAnimationState();
+ animation_player_->SetNeedsCommit();
+ SetNeedsPushProperties();
+ }
+}
+
+void AnimationTicker::ActivateAnimations() {
+ DCHECK(has_bound_element_animations());
+
+ bool animation_activated = false;
+ for (auto& animation : animations_) {
+ if (animation->affects_active_elements() !=
+ animation->affects_pending_elements()) {
+ animation_activated = true;
+ }
+ animation->set_affects_active_elements(
+ animation->affects_pending_elements());
+ }
+
+ if (animation_activated)
+ element_animations_->UpdateClientAnimationState();
+
+ scroll_offset_animation_was_interrupted_ = false;
+}
+
+void AnimationTicker::AnimationAdded() {
+ DCHECK(has_bound_element_animations());
+
+ animation_player_->SetNeedsCommit();
+ needs_to_start_animations_ = true;
+
+ UpdateTickingState(UpdateTickingType::NORMAL);
+ element_animations_->UpdateClientAnimationState();
+}
+
+bool AnimationTicker::NotifyAnimationStarted(const AnimationEvent& event) {
+ DCHECK(!event.is_impl_only);
+ for (auto& animation : animations_) {
+ if (animation->group() == event.group_id &&
+ animation->target_property_id() == event.target_property &&
+ animation->needs_synchronized_start_time()) {
+ animation->set_needs_synchronized_start_time(false);
+ if (!animation->has_set_start_time())
+ animation->set_start_time(event.monotonic_time);
+ animation_player_->NotifyAnimationStarted(event);
+ return true;
+ }
+ }
+ return false;
+}
+
+bool AnimationTicker::NotifyAnimationFinished(const AnimationEvent& event) {
+ DCHECK(!event.is_impl_only);
+ for (auto& animation : animations_) {
+ if (animation->group() == event.group_id &&
+ animation->target_property_id() == event.target_property) {
+ animation->set_received_finished_event(true);
+ animation_player_->NotifyAnimationFinished(event);
+ return true;
+ }
+ }
+
+ // This is for the case when an animation is already removed on main thread,
+ // but the impl version of it sent a finished event and is now waiting for
+ // deletion. We would need to delete that animation during push properties.
+ SetNeedsPushProperties();
+ return false;
+}
+
+void AnimationTicker::NotifyAnimationTakeover(const AnimationEvent& event) {
+ DCHECK(!event.is_impl_only);
+
+ // We need to purge animations marked for deletion on CT.
+ SetNeedsPushProperties();
+
+ animation_player_->NotifyAnimationTakeover(event);
+}
+
+bool AnimationTicker::NotifyAnimationAborted(const AnimationEvent& event) {
+ DCHECK(!event.is_impl_only);
+ for (auto& animation : animations_) {
+ if (animation->group() == event.group_id &&
+ animation->target_property_id() == event.target_property) {
+ animation->SetRunState(Animation::ABORTED, event.monotonic_time);
+ animation->set_received_finished_event(true);
+ animation_player_->NotifyAnimationAborted(event);
+ return true;
+ }
+ }
+ return false;
+}
+
+bool AnimationTicker::HasTickingAnimation() const {
+ for (const auto& animation : animations_) {
+ if (!animation->is_finished())
+ return true;
+ }
+ return false;
+}
+
+bool AnimationTicker::HasNonDeletedAnimation() const {
+ for (const auto& animation : animations_) {
+ if (animation->run_state() != Animation::WAITING_FOR_DELETION)
+ return true;
+ }
+ return false;
+}
+
+bool AnimationTicker::HasOnlyTranslationTransforms(
+ ElementListType list_type) const {
+ for (const auto& animation : animations_) {
+ if (animation->is_finished() ||
+ animation->target_property_id() != TargetProperty::TRANSFORM)
+ continue;
+
+ if ((list_type == ElementListType::ACTIVE &&
+ !animation->affects_active_elements()) ||
+ (list_type == ElementListType::PENDING &&
+ !animation->affects_pending_elements()))
+ continue;
+
+ const TransformAnimationCurve* transform_animation_curve =
+ animation->curve()->ToTransformAnimationCurve();
+ if (!transform_animation_curve->IsTranslation())
+ return false;
+ }
+ return true;
+}
+
+bool AnimationTicker::AnimationsPreserveAxisAlignment() const {
+ for (const auto& animation : animations_) {
+ if (animation->is_finished() ||
+ animation->target_property_id() != TargetProperty::TRANSFORM)
+ continue;
+
+ const TransformAnimationCurve* transform_animation_curve =
+ animation->curve()->ToTransformAnimationCurve();
+ if (!transform_animation_curve->PreservesAxisAlignment())
+ return false;
+ }
+ return true;
+}
+
+bool AnimationTicker::AnimationStartScale(ElementListType list_type,
+ float* start_scale) const {
+ *start_scale = 0.f;
+ for (const auto& animation : animations_) {
+ if (animation->is_finished() ||
+ animation->target_property_id() != TargetProperty::TRANSFORM)
+ continue;
+
+ if ((list_type == ElementListType::ACTIVE &&
+ !animation->affects_active_elements()) ||
+ (list_type == ElementListType::PENDING &&
+ !animation->affects_pending_elements()))
+ continue;
+
+ bool forward_direction = true;
+ switch (animation->direction()) {
+ case Animation::Direction::NORMAL:
+ case Animation::Direction::ALTERNATE_NORMAL:
+ forward_direction = animation->playback_rate() >= 0.0;
+ break;
+ case Animation::Direction::REVERSE:
+ case Animation::Direction::ALTERNATE_REVERSE:
+ forward_direction = animation->playback_rate() < 0.0;
+ break;
+ }
+
+ const TransformAnimationCurve* transform_animation_curve =
+ animation->curve()->ToTransformAnimationCurve();
+ float animation_start_scale = 0.f;
+ if (!transform_animation_curve->AnimationStartScale(forward_direction,
+ &animation_start_scale))
+ return false;
+ *start_scale = std::max(*start_scale, animation_start_scale);
+ }
+ return true;
+}
+
+bool AnimationTicker::MaximumTargetScale(ElementListType list_type,
+ float* max_scale) const {
+ *max_scale = 0.f;
+ for (const auto& animation : animations_) {
+ if (animation->is_finished() ||
+ animation->target_property_id() != TargetProperty::TRANSFORM)
+ continue;
+
+ if ((list_type == ElementListType::ACTIVE &&
+ !animation->affects_active_elements()) ||
+ (list_type == ElementListType::PENDING &&
+ !animation->affects_pending_elements()))
+ continue;
+
+ bool forward_direction = true;
+ switch (animation->direction()) {
+ case Animation::Direction::NORMAL:
+ case Animation::Direction::ALTERNATE_NORMAL:
+ forward_direction = animation->playback_rate() >= 0.0;
+ break;
+ case Animation::Direction::REVERSE:
+ case Animation::Direction::ALTERNATE_REVERSE:
+ forward_direction = animation->playback_rate() < 0.0;
+ break;
+ }
+
+ const TransformAnimationCurve* transform_animation_curve =
+ animation->curve()->ToTransformAnimationCurve();
+ float animation_scale = 0.f;
+ if (!transform_animation_curve->MaximumTargetScale(forward_direction,
+ &animation_scale))
+ return false;
+ *max_scale = std::max(*max_scale, animation_scale);
+ }
+
+ return true;
+}
+
+bool AnimationTicker::IsPotentiallyAnimatingProperty(
+ TargetProperty::Type target_property,
+ ElementListType list_type) const {
+ for (const auto& animation : animations_) {
+ if (!animation->is_finished() &&
+ animation->target_property_id() == target_property) {
+ if ((list_type == ElementListType::ACTIVE &&
+ animation->affects_active_elements()) ||
+ (list_type == ElementListType::PENDING &&
+ animation->affects_pending_elements()))
+ return true;
+ }
+ }
+ return false;
+}
+
+bool AnimationTicker::IsCurrentlyAnimatingProperty(
+ TargetProperty::Type target_property,
+ ElementListType list_type) const {
+ for (const auto& animation : animations_) {
+ if (!animation->is_finished() && animation->InEffect(last_tick_time_) &&
+ animation->target_property_id() == target_property) {
+ if ((list_type == ElementListType::ACTIVE &&
+ animation->affects_active_elements()) ||
+ (list_type == ElementListType::PENDING &&
+ animation->affects_pending_elements()))
+ return true;
+ }
+ }
+ return false;
+}
+
+Animation* AnimationTicker::GetAnimation(
+ TargetProperty::Type target_property) const {
+ for (size_t i = 0; i < animations_.size(); ++i) {
+ size_t index = animations_.size() - i - 1;
+ if (animations_[index]->target_property_id() == target_property)
+ return animations_[index].get();
+ }
+ return nullptr;
+}
+
+Animation* AnimationTicker::GetAnimationById(int animation_id) const {
+ for (auto& animation : animations_)
+ if (animation->id() == animation_id)
+ return animation.get();
+ return nullptr;
+}
+
+void AnimationTicker::GetPropertyAnimationState(
+ PropertyAnimationState* pending_state,
+ PropertyAnimationState* active_state) const {
+ pending_state->Clear();
+ active_state->Clear();
+
+ for (const auto& animation : animations_) {
+ if (!animation->is_finished()) {
+ bool in_effect = animation->InEffect(last_tick_time_);
+ bool active = animation->affects_active_elements();
+ bool pending = animation->affects_pending_elements();
+ int property = animation->target_property_id();
+
+ if (pending)
+ pending_state->potentially_animating[property] = true;
+ if (pending && in_effect)
+ pending_state->currently_running[property] = true;
+
+ if (active)
+ active_state->potentially_animating[property] = true;
+ if (active && in_effect)
+ active_state->currently_running[property] = true;
+ }
+ }
+}
+
+void AnimationTicker::MarkAbortedAnimationsForDeletion(
+ AnimationTicker* animation_ticker_impl) {
+ bool animation_aborted = false;
+
+ auto& animations_impl = animation_ticker_impl->animations_;
+ for (const auto& animation_impl : animations_impl) {
+ // If the animation has been aborted on the main thread, mark it for
+ // deletion.
+ if (Animation* animation = GetAnimationById(animation_impl->id())) {
+ if (animation->run_state() == Animation::ABORTED) {
+ animation_impl->SetRunState(Animation::WAITING_FOR_DELETION,
+ animation_ticker_impl->last_tick_time_);
+ animation->SetRunState(Animation::WAITING_FOR_DELETION,
+ last_tick_time_);
+ animation_aborted = true;
+ }
+ }
+ }
+
+ if (has_bound_element_animations() && animation_aborted)
+ element_animations_->SetNeedsPushProperties();
+}
+
+void AnimationTicker::PurgeAnimationsMarkedForDeletion(bool impl_only) {
+ base::EraseIf(
+ animations_, [impl_only](const std::unique_ptr<Animation>& animation) {
+ return animation->run_state() == Animation::WAITING_FOR_DELETION &&
+ (!impl_only || animation->is_impl_only());
+ });
+}
+
+void AnimationTicker::PushNewAnimationsToImplThread(
+ AnimationTicker* animation_ticker_impl) const {
+ // Any new animations owned by the main thread's AnimationPlayer are cloned
+ // and added to the impl thread's AnimationPlayer.
+ for (const auto& animation : animations_) {
+ // If the animation is already running on the impl thread, there is no
+ // need to copy it over.
+ if (animation_ticker_impl->GetAnimationById(animation->id()))
+ continue;
+
+ if (animation->target_property_id() == TargetProperty::SCROLL_OFFSET &&
+ !animation->curve()
+ ->ToScrollOffsetAnimationCurve()
+ ->HasSetInitialValue()) {
+ gfx::ScrollOffset current_scroll_offset;
+ if (animation_ticker_impl->HasElementInActiveList()) {
+ current_scroll_offset =
+ animation_ticker_impl->ScrollOffsetForAnimation();
+ } else {
+ // The owning layer isn't yet in the active tree, so the main thread
+ // scroll offset will be up to date.
+ current_scroll_offset = ScrollOffsetForAnimation();
+ }
+ animation->curve()->ToScrollOffsetAnimationCurve()->SetInitialValue(
+ current_scroll_offset);
+ }
+
+ // The new animation should be set to run as soon as possible.
+ Animation::RunState initial_run_state =
+ Animation::WAITING_FOR_TARGET_AVAILABILITY;
+ std::unique_ptr<Animation> to_add(
+ animation->CloneAndInitialize(initial_run_state));
+ DCHECK(!to_add->needs_synchronized_start_time());
+ to_add->set_affects_active_elements(false);
+ animation_ticker_impl->AddAnimation(std::move(to_add));
+ }
+}
+
+namespace {
+bool IsCompleted(Animation* animation,
+ const AnimationTicker* main_thread_ticker) {
+ if (animation->is_impl_only()) {
+ return (animation->run_state() == Animation::WAITING_FOR_DELETION);
+ } else {
+ Animation* main_thread_animation =
+ main_thread_ticker->GetAnimationById(animation->id());
+ return !main_thread_animation || main_thread_animation->is_finished();
+ }
+}
+} // namespace
+
+void AnimationTicker::RemoveAnimationsCompletedOnMainThread(
+ AnimationTicker* animation_ticker_impl) const {
+ bool animation_completed = false;
+
+ // Animations removed on the main thread should no longer affect pending
+ // elements, and should stop affecting active elements after the next call
+ // to ActivateAnimations. If already WAITING_FOR_DELETION, they can be removed
+ // immediately.
+ auto& animations = animation_ticker_impl->animations_;
+ for (const auto& animation : animations) {
+ if (IsCompleted(animation.get(), this)) {
+ animation->set_affects_pending_elements(false);
+ animation_completed = true;
+ }
+ }
+ auto affects_active_only_and_is_waiting_for_deletion =
+ [](const std::unique_ptr<Animation>& animation) {
+ return animation->run_state() == Animation::WAITING_FOR_DELETION &&
+ !animation->affects_pending_elements();
+ };
+ base::EraseIf(animations, affects_active_only_and_is_waiting_for_deletion);
+
+ if (has_bound_element_animations() && animation_completed)
+ element_animations_->SetNeedsPushProperties();
+}
+
+void AnimationTicker::PushPropertiesTo(AnimationTicker* animation_ticker_impl) {
+ if (!needs_push_properties_)
+ return;
+ needs_push_properties_ = false;
+
+ // Synchronize the animation target between main and impl size.
+ if (element_id_ != animation_ticker_impl->element_id_) {
+ // We have to detach/attach via the AnimationPlayer as it may need to inform
+ // the host as well.
+ if (animation_ticker_impl->has_attached_element())
+ animation_ticker_impl->animation_player_->DetachElement();
+ if (element_id_)
+ animation_ticker_impl->animation_player_->AttachElement(element_id_);
+ }
+
+ // If neither main nor impl have any animations, there is nothing further to
+ // synchronize.
+ if (!has_any_animation() && !animation_ticker_impl->has_any_animation())
+ return;
+
+ // Synchronize the main-thread and impl-side animation lists, removing aborted
+ // animations and pushing any new animations.
+ MarkAbortedAnimationsForDeletion(animation_ticker_impl);
+ PurgeAnimationsMarkedForDeletion(/* impl_only */ false);
+ PushNewAnimationsToImplThread(animation_ticker_impl);
+
+ // Remove finished impl side animations only after pushing,
+ // and only after the animations are deleted on the main thread
+ // this insures we will never push an animation twice.
+ RemoveAnimationsCompletedOnMainThread(animation_ticker_impl);
+
+ // Now that the animation lists are synchronized, push the properties for the
+ // individual animations.
+ for (const auto& animation : animations_) {
+ Animation* current_impl =
+ animation_ticker_impl->GetAnimationById(animation->id());
+ if (current_impl)
+ animation->PushPropertiesTo(current_impl);
+ }
+ animation_ticker_impl->scroll_offset_animation_was_interrupted_ =
+ scroll_offset_animation_was_interrupted_;
+ scroll_offset_animation_was_interrupted_ = false;
+
+ animation_ticker_impl->UpdateTickingState(UpdateTickingType::NORMAL);
+}
+
+std::string AnimationTicker::AnimationsToString() const {
+ std::string str;
+ for (size_t i = 0; i < animations_.size(); i++) {
+ if (i > 0)
+ str.append(", ");
+ str.append(animations_[i]->ToString());
+ }
+ return str;
+}
+
+void AnimationTicker::StartAnimations(base::TimeTicks monotonic_time) {
+ DCHECK(needs_to_start_animations_);
+ needs_to_start_animations_ = false;
+
+ // First collect running properties affecting each type of element.
+ TargetProperties blocked_properties_for_active_elements;
+ TargetProperties blocked_properties_for_pending_elements;
+ std::vector<size_t> animations_waiting_for_target;
+
+ animations_waiting_for_target.reserve(animations_.size());
+ for (size_t i = 0; i < animations_.size(); ++i) {
+ auto& animation = animations_[i];
+ if (animation->run_state() == Animation::STARTING ||
+ animation->run_state() == Animation::RUNNING) {
+ int property = animation->target_property_id();
+ if (animation->affects_active_elements()) {
+ blocked_properties_for_active_elements[property] = true;
+ }
+ if (animation->affects_pending_elements()) {
+ blocked_properties_for_pending_elements[property] = true;
+ }
+ } else if (animation->run_state() ==
+ Animation::WAITING_FOR_TARGET_AVAILABILITY) {
+ animations_waiting_for_target.push_back(i);
+ }
+ }
+
+ for (size_t i = 0; i < animations_waiting_for_target.size(); ++i) {
+ // Collect all properties for animations with the same group id (they
+ // should all also be in the list of animations).
+ size_t animation_index = animations_waiting_for_target[i];
+ Animation* animation_waiting_for_target =
+ animations_[animation_index].get();
+ // Check for the run state again even though the animation was waiting
+ // for target because it might have changed the run state while handling
+ // previous animation in this loop (if they belong to same group).
+ if (animation_waiting_for_target->run_state() ==
+ Animation::WAITING_FOR_TARGET_AVAILABILITY) {
+ TargetProperties enqueued_properties;
+ bool affects_active_elements =
+ animation_waiting_for_target->affects_active_elements();
+ bool affects_pending_elements =
+ animation_waiting_for_target->affects_pending_elements();
+ enqueued_properties[animation_waiting_for_target->target_property_id()] =
+ true;
+ for (size_t j = animation_index + 1; j < animations_.size(); ++j) {
+ if (animation_waiting_for_target->group() == animations_[j]->group()) {
+ enqueued_properties[animations_[j]->target_property_id()] = true;
+ affects_active_elements |= animations_[j]->affects_active_elements();
+ affects_pending_elements |=
+ animations_[j]->affects_pending_elements();
+ }
+ }
+
+ // Check to see if intersection of the list of properties affected by
+ // the group and the list of currently blocked properties is null, taking
+ // into account the type(s) of elements affected by the group. In any
+ // case, the group's target properties need to be added to the lists of
+ // blocked properties.
+ bool null_intersection = true;
+ for (int property = TargetProperty::FIRST_TARGET_PROPERTY;
+ property <= TargetProperty::LAST_TARGET_PROPERTY; ++property) {
+ if (enqueued_properties[property]) {
+ if (affects_active_elements) {
+ if (blocked_properties_for_active_elements[property])
+ null_intersection = false;
+ else
+ blocked_properties_for_active_elements[property] = true;
+ }
+ if (affects_pending_elements) {
+ if (blocked_properties_for_pending_elements[property])
+ null_intersection = false;
+ else
+ blocked_properties_for_pending_elements[property] = true;
+ }
+ }
+ }
+
+ // If the intersection is null, then we are free to start the animations
+ // in the group.
+ if (null_intersection) {
+ animation_waiting_for_target->SetRunState(Animation::STARTING,
+ monotonic_time);
+ for (size_t j = animation_index + 1; j < animations_.size(); ++j) {
+ if (animation_waiting_for_target->group() ==
+ animations_[j]->group()) {
+ animations_[j]->SetRunState(Animation::STARTING, monotonic_time);
+ }
+ }
+ } else {
+ needs_to_start_animations_ = true;
+ }
+ }
+ }
+}
+
+void AnimationTicker::PromoteStartedAnimations(AnimationEvents* events) {
+ for (auto& animation : animations_) {
+ if (animation->run_state() == Animation::STARTING &&
+ animation->affects_active_elements()) {
+ animation->SetRunState(Animation::RUNNING, last_tick_time_);
+ if (!animation->has_set_start_time() &&
+ !animation->needs_synchronized_start_time())
+ animation->set_start_time(last_tick_time_);
+ if (events) {
+ base::TimeTicks start_time;
+ if (animation->has_set_start_time())
+ start_time = animation->start_time();
+ else
+ start_time = last_tick_time_;
+ AnimationEvent started_event(
+ AnimationEvent::STARTED, element_id_, animation->group(),
+ animation->target_property_id(), start_time);
+ started_event.is_impl_only = animation->is_impl_only();
+ if (started_event.is_impl_only) {
+ // Notify delegate directly, do not record the event.
+ animation_player_->NotifyAnimationStarted(started_event);
+ } else {
+ events->events_.push_back(started_event);
+ }
+ }
+ }
+ }
+}
+
+void AnimationTicker::MarkAnimationsForDeletion(base::TimeTicks monotonic_time,
+ AnimationEvents* events) {
+ bool marked_animations_for_deletions = false;
+ std::vector<size_t> animations_with_same_group_id;
+
+ animations_with_same_group_id.reserve(animations_.size());
+ // Non-aborted animations are marked for deletion after a corresponding
+ // AnimationEvent::FINISHED event is sent or received. This means that if
+ // we don't have an events vector, we must ensure that non-aborted animations
+ // have received a finished event before marking them for deletion.
+ for (size_t i = 0; i < animations_.size(); i++) {
+ auto& animation = animations_[i];
+ int group_id = animation->group();
+ if (animation->run_state() == Animation::ABORTED) {
+ if (events && !animation->is_impl_only()) {
+ AnimationEvent aborted_event(AnimationEvent::ABORTED, element_id_,
+ group_id, animation->target_property_id(),
+ monotonic_time);
+ events->events_.push_back(aborted_event);
+ }
+ // If on the compositor or on the main thread and received finish event,
+ // animation can be marked for deletion.
+ if (events || animation->received_finished_event()) {
+ animation->SetRunState(Animation::WAITING_FOR_DELETION, monotonic_time);
+ marked_animations_for_deletions = true;
+ }
+ continue;
+ }
+
+ // If running on the compositor and need to complete an aborted animation
+ // on the main thread.
+ if (events &&
+ animation->run_state() == Animation::ABORTED_BUT_NEEDS_COMPLETION) {
+ AnimationEvent aborted_event(AnimationEvent::TAKEOVER, element_id_,
+ group_id, animation->target_property_id(),
+ monotonic_time);
+ aborted_event.animation_start_time = animation->start_time();
+ const ScrollOffsetAnimationCurve* scroll_offset_animation_curve =
+ animation->curve()->ToScrollOffsetAnimationCurve();
+ aborted_event.curve = scroll_offset_animation_curve->Clone();
+ // Notify the compositor that the animation is finished.
+ animation_player_->NotifyAnimationFinished(aborted_event);
+ // Notify main thread.
+ events->events_.push_back(aborted_event);
+
+ // Remove the animation from the compositor.
+ animation->SetRunState(Animation::WAITING_FOR_DELETION, monotonic_time);
+ marked_animations_for_deletions = true;
+ continue;
+ }
+
+ bool all_anims_with_same_id_are_finished = false;
+
+ // Since deleting an animation on the main thread leads to its deletion
+ // on the impl thread, we only mark a FINISHED main thread animation for
+ // deletion once it has received a FINISHED event from the impl thread.
+ bool animation_i_will_send_or_has_received_finish_event =
+ animation->is_controlling_instance() || animation->is_impl_only() ||
+ animation->received_finished_event();
+ // If an animation is finished, and not already marked for deletion,
+ // find out if all other animations in the same group are also finished.
+ if (animation->run_state() == Animation::FINISHED &&
+ animation_i_will_send_or_has_received_finish_event) {
+ // Clear the animations_with_same_group_id if it was added for
+ // the previous animation's iteration.
+ if (animations_with_same_group_id.size() > 0)
+ animations_with_same_group_id.clear();
+ all_anims_with_same_id_are_finished = true;
+ for (size_t j = 0; j < animations_.size(); ++j) {
+ auto& animation_j = animations_[j];
+ bool animation_j_will_send_or_has_received_finish_event =
+ animation_j->is_controlling_instance() ||
+ animation_j->is_impl_only() ||
+ animation_j->received_finished_event();
+ if (group_id == animation_j->group()) {
+ if (!animation_j->is_finished() ||
+ (animation_j->run_state() == Animation::FINISHED &&
+ !animation_j_will_send_or_has_received_finish_event)) {
+ all_anims_with_same_id_are_finished = false;
+ break;
+ } else if (j >= i && animation_j->run_state() != Animation::ABORTED) {
+ // Mark down the animations which belong to the same group
+ // and is not yet aborted. If this current iteration finds that all
+ // animations with same ID are finished, then the marked
+ // animations below will be set to WAITING_FOR_DELETION in next
+ // iteration.
+ animations_with_same_group_id.push_back(j);
+ }
+ }
+ }
+ }
+
+ if (all_anims_with_same_id_are_finished) {
+ // We now need to remove all animations with the same group id as
+ // group_id (and send along animation finished notifications, if
+ // necessary).
+ for (size_t j = 0; j < animations_with_same_group_id.size(); j++) {
+ size_t animation_index = animations_with_same_group_id[j];
+ auto& grouped_animation = animations_[animation_index];
+ if (events) {
+ AnimationEvent finished_event(
+ AnimationEvent::FINISHED, element_id_, grouped_animation->group(),
+ grouped_animation->target_property_id(), monotonic_time);
+ finished_event.is_impl_only = grouped_animation->is_impl_only();
+ if (finished_event.is_impl_only) {
+ // Notify delegate directly, do not record the event.
+ animation_player_->NotifyAnimationFinished(finished_event);
+ } else {
+ events->events_.push_back(finished_event);
+ }
+ }
+ grouped_animation->SetRunState(Animation::WAITING_FOR_DELETION,
+ monotonic_time);
+ }
+ marked_animations_for_deletions = true;
+ }
+ }
+
+ // We need to purge animations marked for deletion, which happens in
+ // PushPropertiesTo().
+ if (marked_animations_for_deletions)
+ SetNeedsPushProperties();
+}
+
+void AnimationTicker::MarkFinishedAnimations(base::TimeTicks monotonic_time) {
+ DCHECK(has_bound_element_animations());
+
+ bool animation_finished = false;
+ for (auto& animation : animations_) {
+ if (!animation->is_finished() && animation->IsFinishedAt(monotonic_time)) {
+ animation->SetRunState(Animation::FINISHED, monotonic_time);
+ animation_finished = true;
+ SetNeedsPushProperties();
+ }
+ if (!animation->affects_active_elements() &&
+ !animation->affects_pending_elements()) {
+ switch (animation->run_state()) {
+ case Animation::WAITING_FOR_TARGET_AVAILABILITY:
+ case Animation::STARTING:
+ case Animation::RUNNING:
+ case Animation::PAUSED:
+ animation->SetRunState(Animation::FINISHED, monotonic_time);
+ animation_finished = true;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ if (animation_finished)
+ element_animations_->UpdateClientAnimationState();
+}
+
+bool AnimationTicker::HasElementInActiveList() const {
+ DCHECK(has_bound_element_animations());
+ return element_animations_->has_element_in_active_list();
+}
+
+gfx::ScrollOffset AnimationTicker::ScrollOffsetForAnimation() const {
+ DCHECK(has_bound_element_animations());
+ return element_animations_->ScrollOffsetForAnimation();
+}
+
+} // namespace cc
diff --git a/chromium/cc/animation/animation_ticker.h b/chromium/cc/animation/animation_ticker.h
new file mode 100644
index 00000000000..7ef9462feb7
--- /dev/null
+++ b/chromium/cc/animation/animation_ticker.h
@@ -0,0 +1,186 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_ANIMATION_ANIMATION_TICKER_H_
+#define CC_ANIMATION_ANIMATION_TICKER_H_
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/time/time.h"
+#include "cc/animation/animation_events.h"
+#include "cc/animation/animation_export.h"
+#include "cc/animation/element_animations.h"
+#include "cc/trees/element_id.h"
+#include "cc/trees/mutator_host_client.h"
+#include "cc/trees/target_property.h"
+#include "ui/gfx/geometry/box_f.h"
+#include "ui/gfx/geometry/scroll_offset.h"
+
+#include <memory>
+#include <vector>
+
+namespace cc {
+
+class Animation;
+class AnimationPlayer;
+struct PropertyAnimationState;
+
+// An AnimationTicker owns a group of Animations for a single target (identified
+// by a ElementId). It is responsible for managing the animations' running
+// states (starting, running, paused, etc), as well as ticking the animations
+// when it is requested to produce new outputs for a given time.
+//
+// Note that a single AnimationTicker may not own all the animations for a given
+// target. AnimationTicker is only a grouping mechanism for related animations.
+// The commonality between animations on the same target is found via
+// ElementAnimations - there is only one ElementAnimations for a given target.
+class CC_ANIMATION_EXPORT AnimationTicker {
+ public:
+ explicit AnimationTicker(AnimationPlayer* animation_player);
+ ~AnimationTicker();
+
+ // ElementAnimations object where this controller is listed.
+ scoped_refptr<ElementAnimations> element_animations() const {
+ return element_animations_;
+ }
+
+ bool has_bound_element_animations() const { return !!element_animations_; }
+
+ bool has_attached_element() const { return !!element_id_; }
+
+ ElementId element_id() const { return element_id_; }
+
+ // Returns true if there are any animations at all to process.
+ bool has_any_animation() const { return !animations_.empty(); }
+
+ // When a scroll animation is removed on the main thread, its compositor
+ // thread counterpart continues producing scroll deltas until activation.
+ // These scroll deltas need to be cleared at activation, so that the active
+ // element's scroll offset matches the offset provided by the main thread
+ // rather than a combination of this offset and scroll deltas produced by the
+ // removed animation. This is to provide the illusion of synchronicity to JS
+ // that simultaneously removes an animation and sets the scroll offset.
+ bool scroll_offset_animation_was_interrupted() const {
+ return scroll_offset_animation_was_interrupted_;
+ }
+
+ bool needs_push_properties() const { return needs_push_properties_; }
+ void SetNeedsPushProperties();
+
+ void BindElementAnimations(ElementAnimations* element_animations);
+ void UnbindElementAnimations();
+
+ void AttachElement(ElementId element_id);
+ void DetachElement();
+
+ void Tick(base::TimeTicks monotonic_time);
+ static void TickAnimation(base::TimeTicks monotonic_time,
+ Animation* animation,
+ AnimationTarget* target);
+ void RemoveFromTicking();
+
+ void UpdateState(bool start_ready_animations, AnimationEvents* events);
+ void UpdateTickingState(UpdateTickingType type);
+
+ void AddAnimation(std::unique_ptr<Animation> animation);
+ void PauseAnimation(int animation_id, double time_offset);
+ void RemoveAnimation(int animation_id);
+ void AbortAnimation(int animation_id);
+ void AbortAnimations(TargetProperty::Type target_property,
+ bool needs_completion);
+
+ void ActivateAnimations();
+
+ void AnimationAdded();
+
+ // The following methods should be called to notify the AnimationTicker that
+ // an animation event has been received for the same target (ElementId) as
+ // this ticker. If the event matches an Animation owned by this
+ // AnimationTicker the call will return true, else it will return false.
+ bool NotifyAnimationStarted(const AnimationEvent& event);
+ bool NotifyAnimationFinished(const AnimationEvent& event);
+ void NotifyAnimationTakeover(const AnimationEvent& event);
+ bool NotifyAnimationAborted(const AnimationEvent& event);
+
+ // Returns true if there are any animations that have neither finished nor
+ // aborted.
+ bool HasTickingAnimation() const;
+
+ bool HasNonDeletedAnimation() const;
+
+ bool HasOnlyTranslationTransforms(ElementListType list_type) const;
+
+ bool AnimationsPreserveAxisAlignment() const;
+
+ // Sets |start_scale| to the maximum of starting animation scale along any
+ // dimension at any destination in active animations. Returns false if the
+ // starting scale cannot be computed.
+ bool AnimationStartScale(ElementListType, float* start_scale) const;
+
+ // Sets |max_scale| to the maximum scale along any dimension at any
+ // destination in active animations. Returns false if the maximum scale cannot
+ // be computed.
+ bool MaximumTargetScale(ElementListType, float* max_scale) const;
+
+ // Returns true if there is an animation that is either currently animating
+ // the given property or scheduled to animate this property in the future, and
+ // that affects the given tree type.
+ bool IsPotentiallyAnimatingProperty(TargetProperty::Type target_property,
+ ElementListType list_type) const;
+
+ // Returns true if there is an animation that is currently animating the given
+ // property and that affects the given tree type.
+ bool IsCurrentlyAnimatingProperty(TargetProperty::Type target_property,
+ ElementListType list_type) const;
+
+ Animation* GetAnimation(TargetProperty::Type target_property) const;
+ Animation* GetAnimationById(int animation_id) const;
+
+ void GetPropertyAnimationState(PropertyAnimationState* pending_state,
+ PropertyAnimationState* active_state) const;
+
+ void MarkAbortedAnimationsForDeletion(AnimationTicker* element_ticker_impl);
+ void PurgeAnimationsMarkedForDeletion(bool impl_only);
+ void PushNewAnimationsToImplThread(
+ AnimationTicker* element_ticker_impl) const;
+ void RemoveAnimationsCompletedOnMainThread(
+ AnimationTicker* element_ticker_impl) const;
+ void PushPropertiesTo(AnimationTicker* animation_ticker_impl);
+
+ std::string AnimationsToString() const;
+
+ private:
+ void StartAnimations(base::TimeTicks monotonic_time);
+ void PromoteStartedAnimations(AnimationEvents* events);
+
+ void MarkAnimationsForDeletion(base::TimeTicks, AnimationEvents* events);
+ void MarkFinishedAnimations(base::TimeTicks monotonic_time);
+
+ bool HasElementInActiveList() const;
+ gfx::ScrollOffset ScrollOffsetForAnimation() const;
+
+ std::vector<std::unique_ptr<Animation>> animations_;
+ AnimationPlayer* animation_player_;
+ ElementId element_id_;
+
+ // element_animations_ is non-null if controller is attached to an element.
+ scoped_refptr<ElementAnimations> element_animations_;
+
+ // Only try to start animations when new animations are added or when the
+ // previous attempt at starting animations failed to start all animations.
+ bool needs_to_start_animations_;
+
+ bool scroll_offset_animation_was_interrupted_;
+
+ bool is_ticking_;
+ base::TimeTicks last_tick_time_;
+
+ bool needs_push_properties_;
+
+ DISALLOW_COPY_AND_ASSIGN(AnimationTicker);
+};
+
+} // namespace cc
+
+#endif // CC_ANIMATION_ANIMATION_TICKER_H_
diff --git a/chromium/cc/animation/animation_timeline.cc b/chromium/cc/animation/animation_timeline.cc
index d76e9821a5e..8b380e85a3b 100644
--- a/chromium/cc/animation/animation_timeline.cc
+++ b/chromium/cc/animation/animation_timeline.cc
@@ -12,7 +12,7 @@
namespace cc {
scoped_refptr<AnimationTimeline> AnimationTimeline::Create(int id) {
- return make_scoped_refptr(new AnimationTimeline(id));
+ return base::WrapRefCounted(new AnimationTimeline(id));
}
AnimationTimeline::AnimationTimeline(int id)
@@ -126,10 +126,9 @@ void AnimationTimeline::PushPropertiesToImplThread(
AnimationTimeline* timeline_impl) {
for (auto& kv : id_to_player_map_) {
AnimationPlayer* player = kv.second.get();
- if (player->needs_push_properties()) {
- AnimationPlayer* player_impl = timeline_impl->GetPlayerById(player->id());
- if (player_impl)
- player->PushPropertiesTo(player_impl);
+ if (AnimationPlayer* player_impl =
+ timeline_impl->GetPlayerById(player->id())) {
+ player->PushPropertiesTo(player_impl);
}
}
}
diff --git a/chromium/cc/animation/animation_unittest.cc b/chromium/cc/animation/animation_unittest.cc
index 6321b5c24fb..e5e65c1f283 100644
--- a/chromium/cc/animation/animation_unittest.cc
+++ b/chromium/cc/animation/animation_unittest.cc
@@ -5,6 +5,7 @@
#include "cc/animation/animation.h"
#include "base/memory/ptr_util.h"
+#include "base/strings/stringprintf.h"
#include "cc/test/animation_test_common.h"
#include "cc/trees/target_property.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -1003,12 +1004,14 @@ TEST(AnimationTest, InEffectFillModePlayback) {
}
TEST(AnimationTest, ToString) {
- EXPECT_EQ(
- "Animation{id=42, group=73, target_property_id=1, "
- "run_state=WAITING_FOR_TARGET_AVAILABILITY}",
+ std::unique_ptr<Animation> animation =
Animation::Create(std::make_unique<FakeFloatAnimationCurve>(15), 42, 73,
- TargetProperty::OPACITY)
- ->ToString());
+ TargetProperty::OPACITY);
+ EXPECT_EQ(
+ base::StringPrintf("Animation{id=%d, group=73, target_property_id=1, "
+ "run_state=WAITING_FOR_TARGET_AVAILABILITY}",
+ animation->id()),
+ animation->ToString());
}
} // namespace
diff --git a/chromium/cc/animation/element_animations.cc b/chromium/cc/animation/element_animations.cc
index 3a8f9c7b443..ad26a5f4e9f 100644
--- a/chromium/cc/animation/element_animations.cc
+++ b/chromium/cc/animation/element_animations.cc
@@ -10,21 +10,21 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
+#include "base/numerics/ranges.h"
#include "cc/animation/animation_delegate.h"
#include "cc/animation/animation_events.h"
#include "cc/animation/animation_host.h"
-#include "cc/animation/animation_player.h"
+#include "cc/animation/animation_ticker.h"
#include "cc/animation/keyframed_animation_curve.h"
#include "cc/animation/transform_operations.h"
#include "cc/base/filter_operations.h"
-#include "cc/base/math_util.h"
#include "cc/trees/mutator_host_client.h"
#include "ui/gfx/geometry/box_f.h"
namespace cc {
scoped_refptr<ElementAnimations> ElementAnimations::Create() {
- return make_scoped_refptr(new ElementAnimations());
+ return base::WrapRefCounted(new ElementAnimations());
}
ElementAnimations::ElementAnimations()
@@ -32,8 +32,7 @@ ElementAnimations::ElementAnimations()
element_id_(),
has_element_in_active_list_(false),
has_element_in_pending_list_(false),
- needs_push_properties_(false),
- needs_update_impl_client_state_(false) {}
+ needs_push_properties_(false) {}
ElementAnimations::~ElementAnimations() {}
@@ -49,7 +48,7 @@ void ElementAnimations::InitAffectedElementTypes() {
DCHECK(element_id_);
DCHECK(animation_host_);
- UpdatePlayersTickingState(UpdateTickingType::FORCE);
+ UpdateTickersTickingState(UpdateTickingType::FORCE);
DCHECK(animation_host_->mutator_host_client());
if (animation_host_->mutator_host_client()->IsElementInList(
@@ -92,7 +91,7 @@ void ElementAnimations::ClearAffectedElementTypes() {
}
set_has_element_in_pending_list(false);
- RemovePlayersFromTicking();
+ RemoveTickersFromTicking();
}
void ElementAnimations::ElementRegistered(ElementId element_id,
@@ -100,7 +99,7 @@ void ElementAnimations::ElementRegistered(ElementId element_id,
DCHECK_EQ(element_id_, element_id);
if (!has_element_in_any_list())
- UpdatePlayersTickingState(UpdateTickingType::FORCE);
+ UpdateTickersTickingState(UpdateTickingType::FORCE);
if (list_type == ElementListType::ACTIVE)
set_has_element_in_active_list(true);
@@ -117,19 +116,21 @@ void ElementAnimations::ElementUnregistered(ElementId element_id,
set_has_element_in_pending_list(false);
if (!has_element_in_any_list())
- RemovePlayersFromTicking();
+ RemoveTickersFromTicking();
}
-void ElementAnimations::AddPlayer(AnimationPlayer* player) {
- players_list_.AddObserver(player);
+void ElementAnimations::AddTicker(AnimationTicker* ticker) {
+ tickers_list_.AddObserver(ticker);
+ ticker->BindElementAnimations(this);
}
-void ElementAnimations::RemovePlayer(AnimationPlayer* player) {
- players_list_.RemoveObserver(player);
+void ElementAnimations::RemoveTicker(AnimationTicker* ticker) {
+ tickers_list_.RemoveObserver(ticker);
+ ticker->UnbindElementAnimations();
}
bool ElementAnimations::IsEmpty() const {
- return !players_list_.might_have_observers();
+ return !tickers_list_.might_have_observers();
}
void ElementAnimations::SetNeedsPushProperties() {
@@ -144,35 +145,32 @@ void ElementAnimations::PushPropertiesTo(
return;
needs_push_properties_ = false;
- // Update impl client state.
- if (needs_update_impl_client_state_)
- element_animations_impl->UpdateClientAnimationState();
- needs_update_impl_client_state_ = false;
+ element_animations_impl->UpdateClientAnimationState();
}
-void ElementAnimations::UpdatePlayersTickingState(
+void ElementAnimations::UpdateTickersTickingState(
UpdateTickingType update_ticking_type) const {
- for (auto& player : players_list_)
- player.UpdateTickingState(update_ticking_type);
+ for (auto& ticker : tickers_list_)
+ ticker.UpdateTickingState(update_ticking_type);
}
-void ElementAnimations::RemovePlayersFromTicking() const {
- for (auto& player : players_list_)
- player.RemoveFromTicking();
+void ElementAnimations::RemoveTickersFromTicking() const {
+ for (auto& ticker : tickers_list_)
+ ticker.RemoveFromTicking();
}
void ElementAnimations::NotifyAnimationStarted(const AnimationEvent& event) {
DCHECK(!event.is_impl_only);
- for (auto& player : players_list_) {
- if (player.NotifyAnimationStarted(event))
+ for (auto& ticker : tickers_list_) {
+ if (ticker.NotifyAnimationStarted(event))
break;
}
}
void ElementAnimations::NotifyAnimationFinished(const AnimationEvent& event) {
DCHECK(!event.is_impl_only);
- for (auto& player : players_list_) {
- if (player.NotifyAnimationFinished(event))
+ for (auto& ticker : tickers_list_) {
+ if (ticker.NotifyAnimationFinished(event))
break;
}
}
@@ -181,58 +179,33 @@ void ElementAnimations::NotifyAnimationTakeover(const AnimationEvent& event) {
DCHECK(!event.is_impl_only);
DCHECK(event.target_property == TargetProperty::SCROLL_OFFSET);
- for (auto& player : players_list_)
- player.NotifyAnimationTakeover(event);
+ for (auto& ticker : tickers_list_)
+ ticker.NotifyAnimationTakeover(event);
}
void ElementAnimations::NotifyAnimationAborted(const AnimationEvent& event) {
DCHECK(!event.is_impl_only);
- for (auto& player : players_list_) {
- if (player.NotifyAnimationAborted(event))
+ for (auto& ticker : tickers_list_) {
+ if (ticker.NotifyAnimationAborted(event))
break;
}
UpdateClientAnimationState();
}
-bool ElementAnimations::HasTransformAnimationThatInflatesBounds() const {
- for (auto& player : players_list_) {
- if (player.HasTransformAnimationThatInflatesBounds())
- return true;
- }
- return false;
-}
-
-bool ElementAnimations::TransformAnimationBoundsForBox(
- const gfx::BoxF& box,
- gfx::BoxF* bounds) const {
- *bounds = gfx::BoxF();
-
- for (auto& player : players_list_) {
- if (!player.HasTransformAnimationThatInflatesBounds())
- continue;
- gfx::BoxF player_bounds;
- bool success = player.TransformAnimationBoundsForBox(box, &player_bounds);
- if (!success)
- return false;
- bounds->Union(player_bounds);
- }
- return true;
-}
-
bool ElementAnimations::HasOnlyTranslationTransforms(
ElementListType list_type) const {
- for (auto& player : players_list_) {
- if (!player.HasOnlyTranslationTransforms(list_type))
+ for (auto& ticker : tickers_list_) {
+ if (!ticker.HasOnlyTranslationTransforms(list_type))
return false;
}
return true;
}
bool ElementAnimations::AnimationsPreserveAxisAlignment() const {
- for (auto& player : players_list_) {
- if (!player.AnimationsPreserveAxisAlignment())
+ for (auto& ticker : tickers_list_) {
+ if (!ticker.AnimationsPreserveAxisAlignment())
return false;
}
return true;
@@ -242,13 +215,13 @@ bool ElementAnimations::AnimationStartScale(ElementListType list_type,
float* start_scale) const {
*start_scale = 0.f;
- for (auto& player : players_list_) {
- float player_start_scale = 0.f;
- bool success = player.AnimationStartScale(list_type, &player_start_scale);
+ for (auto& ticker : tickers_list_) {
+ float ticker_start_scale = 0.f;
+ bool success = ticker.AnimationStartScale(list_type, &ticker_start_scale);
if (!success)
return false;
// Union: a maximum.
- *start_scale = std::max(*start_scale, player_start_scale);
+ *start_scale = std::max(*start_scale, ticker_start_scale);
}
return true;
@@ -258,36 +231,31 @@ bool ElementAnimations::MaximumTargetScale(ElementListType list_type,
float* max_scale) const {
*max_scale = 0.f;
- for (auto& player : players_list_) {
- float player_max_scale = 0.f;
- bool success = player.MaximumTargetScale(list_type, &player_max_scale);
+ for (auto& ticker : tickers_list_) {
+ float ticker_max_scale = 0.f;
+ bool success = ticker.MaximumTargetScale(list_type, &ticker_max_scale);
if (!success)
return false;
// Union: a maximum.
- *max_scale = std::max(*max_scale, player_max_scale);
+ *max_scale = std::max(*max_scale, ticker_max_scale);
}
return true;
}
bool ElementAnimations::ScrollOffsetAnimationWasInterrupted() const {
- for (auto& player : players_list_) {
- if (player.scroll_offset_animation_was_interrupted())
+ for (auto& ticker : tickers_list_) {
+ if (ticker.scroll_offset_animation_was_interrupted())
return true;
}
return false;
}
-void ElementAnimations::SetNeedsUpdateImplClientState() {
- needs_update_impl_client_state_ = true;
- SetNeedsPushProperties();
-}
-
void ElementAnimations::NotifyClientFloatAnimated(float opacity,
int target_property_id,
Animation* animation) {
DCHECK(animation->target_property_id() == TargetProperty::OPACITY);
- opacity = MathUtil::ClampToRange(opacity, 0.0f, 1.0f);
+ opacity = base::ClampToRange(opacity, 0.0f, 1.0f);
if (AnimationAffectsActiveElements(animation))
OnOpacityAnimated(ElementListType::ACTIVE, opacity);
if (AnimationAffectsPendingElements(animation))
@@ -338,12 +306,12 @@ void ElementAnimations::UpdateClientAnimationState() {
pending_state_.Clear();
active_state_.Clear();
- for (auto& player : players_list_) {
- PropertyAnimationState player_pending_state, player_active_state;
- player.GetPropertyAnimationState(&player_pending_state,
- &player_active_state);
- pending_state_ |= player_pending_state;
- active_state_ |= player_active_state;
+ for (auto& ticker : tickers_list_) {
+ PropertyAnimationState ticker_pending_state, ticker_active_state;
+ ticker.GetPropertyAnimationState(&ticker_pending_state,
+ &ticker_active_state);
+ pending_state_ |= ticker_pending_state;
+ active_state_ |= ticker_active_state;
}
TargetProperties allowed_properties = GetPropertiesMaskForAnimationState();
@@ -370,8 +338,8 @@ void ElementAnimations::UpdateClientAnimationState() {
}
bool ElementAnimations::HasTickingAnimation() const {
- for (auto& player : players_list_) {
- if (player.HasTickingAnimation())
+ for (auto& ticker : tickers_list_) {
+ if (ticker.HasTickingAnimation())
return true;
}
@@ -379,8 +347,8 @@ bool ElementAnimations::HasTickingAnimation() const {
}
bool ElementAnimations::HasAnyAnimation() const {
- for (auto& player : players_list_) {
- if (player.has_any_animation())
+ for (auto& ticker : tickers_list_) {
+ if (ticker.has_any_animation())
return true;
}
@@ -389,8 +357,8 @@ bool ElementAnimations::HasAnyAnimation() const {
bool ElementAnimations::HasAnyAnimationTargetingProperty(
TargetProperty::Type property) const {
- for (auto& player : players_list_) {
- if (player.GetAnimation(property))
+ for (auto& ticker : tickers_list_) {
+ if (ticker.GetAnimation(property))
return true;
}
return false;
@@ -399,8 +367,8 @@ bool ElementAnimations::HasAnyAnimationTargetingProperty(
bool ElementAnimations::IsPotentiallyAnimatingProperty(
TargetProperty::Type target_property,
ElementListType list_type) const {
- for (auto& player : players_list_) {
- if (player.IsPotentiallyAnimatingProperty(target_property, list_type))
+ for (auto& ticker : tickers_list_) {
+ if (ticker.IsPotentiallyAnimatingProperty(target_property, list_type))
return true;
}
@@ -410,8 +378,8 @@ bool ElementAnimations::IsPotentiallyAnimatingProperty(
bool ElementAnimations::IsCurrentlyAnimatingProperty(
TargetProperty::Type target_property,
ElementListType list_type) const {
- for (auto& player : players_list_) {
- if (player.IsCurrentlyAnimatingProperty(target_property, list_type))
+ for (auto& ticker : tickers_list_) {
+ if (ticker.IsCurrentlyAnimatingProperty(target_property, list_type))
return true;
}
diff --git a/chromium/cc/animation/element_animations.h b/chromium/cc/animation/element_animations.h
index 8f41e5c4382..1c2a03162dc 100644
--- a/chromium/cc/animation/element_animations.h
+++ b/chromium/cc/animation/element_animations.h
@@ -26,7 +26,7 @@ class BoxF;
namespace cc {
class AnimationHost;
-class AnimationPlayer;
+class AnimationTicker;
class FilterOperations;
class TransformOperations;
enum class ElementListType;
@@ -34,8 +34,9 @@ struct AnimationEvent;
enum class UpdateTickingType { NORMAL, FORCE };
-// An ElementAnimations owns a list of all AnimationPlayers, attached to
-// the element.
+// An ElementAnimations owns a list of all AnimationTickers attached to a single
+// target (represented by an ElementId).
+//
// This is a CC counterpart for blink::ElementAnimations (in 1:1 relationship).
// No pointer to/from respective blink::ElementAnimations object for now.
class CC_ANIMATION_EXPORT ElementAnimations
@@ -58,12 +59,12 @@ class CC_ANIMATION_EXPORT ElementAnimations
void ElementRegistered(ElementId element_id, ElementListType list_type);
void ElementUnregistered(ElementId element_id, ElementListType list_type);
- void AddPlayer(AnimationPlayer* player);
- void RemovePlayer(AnimationPlayer* player);
+ void AddTicker(AnimationTicker* ticker);
+ void RemoveTicker(AnimationTicker* ticker);
bool IsEmpty() const;
- typedef base::ObserverList<AnimationPlayer> PlayersList;
- const PlayersList& players_list() const { return players_list_; }
+ typedef base::ObserverList<AnimationTicker> TickersList;
+ const TickersList& tickers_list() const { return tickers_list_; }
// Ensures that the list of active animations on the main thread and the impl
// thread are kept in sync. This function does not take ownership of the impl
@@ -114,8 +115,6 @@ class CC_ANIMATION_EXPORT ElementAnimations
has_element_in_pending_list_ = has_element_in_pending_list;
}
- bool HasTransformAnimationThatInflatesBounds() const;
-
bool TransformAnimationBoundsForBox(const gfx::BoxF& box,
gfx::BoxF* bounds) const;
@@ -139,7 +138,6 @@ class CC_ANIMATION_EXPORT ElementAnimations
bool needs_push_properties() const { return needs_push_properties_; }
void UpdateClientAnimationState();
- void SetNeedsUpdateImplClientState();
void NotifyClientFloatAnimated(float opacity,
int target_property_id,
@@ -173,13 +171,13 @@ class CC_ANIMATION_EXPORT ElementAnimations
static TargetProperties GetPropertiesMaskForAnimationState();
- void UpdatePlayersTickingState(UpdateTickingType update_ticking_type) const;
- void RemovePlayersFromTicking() const;
+ void UpdateTickersTickingState(UpdateTickingType update_ticking_type) const;
+ void RemoveTickersFromTicking() const;
bool AnimationAffectsActiveElements(Animation* animation) const;
bool AnimationAffectsPendingElements(Animation* animation) const;
- PlayersList players_list_;
+ TickersList tickers_list_;
AnimationHost* animation_host_;
ElementId element_id_;
@@ -191,8 +189,6 @@ class CC_ANIMATION_EXPORT ElementAnimations
PropertyAnimationState active_state_;
PropertyAnimationState pending_state_;
- mutable bool needs_update_impl_client_state_;
-
DISALLOW_COPY_AND_ASSIGN(ElementAnimations);
};
diff --git a/chromium/cc/animation/element_animations_unittest.cc b/chromium/cc/animation/element_animations_unittest.cc
index 7e3242f3fda..9c88a5cbc65 100644
--- a/chromium/cc/animation/element_animations_unittest.cc
+++ b/chromium/cc/animation/element_animations_unittest.cc
@@ -10,6 +10,7 @@
#include "cc/animation/animation_host.h"
#include "cc/animation/animation_id_provider.h"
#include "cc/animation/animation_player.h"
+#include "cc/animation/animation_ticker.h"
#include "cc/animation/animation_timeline.h"
#include "cc/animation/keyframed_animation_curve.h"
#include "cc/animation/scroll_offset_animation_curve.h"
@@ -38,11 +39,25 @@ class ElementAnimationsTest : public AnimationTimelinesTest {
ElementAnimationsTest() {}
~ElementAnimationsTest() override {}
+ void SetUp() override {
+ AnimationTimelinesTest::SetUp();
+ ticker_ = player_->animation_ticker();
+ }
+
+ void CreateImplTimelineAndPlayer() override {
+ AnimationTimelinesTest::CreateImplTimelineAndPlayer();
+ ticker_impl_ = player_impl_->animation_ticker();
+ }
+
std::unique_ptr<AnimationEvents> CreateEventsForTesting() {
auto mutator_events = host_impl_->CreateEvents();
return base::WrapUnique(
static_cast<AnimationEvents*>(mutator_events.release()));
}
+
+ protected:
+ AnimationTicker* ticker_;
+ AnimationTicker* ticker_impl_;
};
// See animation_player_unittest.cc for integration with AnimationPlayer.
@@ -180,11 +195,11 @@ TEST_F(ElementAnimationsTest, AddRemovePlayers) {
player_impl_->element_animations();
EXPECT_TRUE(element_animations_impl);
+ const ElementAnimations::TickersList& tickers =
+ element_animations_impl_->tickers_list();
int list_size_before = 0;
- for (auto& player : element_animations_impl_->players_list()) {
- EXPECT_TRUE(timeline_->GetPlayerById(player.id()));
+ for (auto it = tickers.begin(); it != tickers.end(); ++it)
++list_size_before;
- }
EXPECT_EQ(3, list_size_before);
player2->DetachElement();
@@ -196,10 +211,8 @@ TEST_F(ElementAnimationsTest, AddRemovePlayers) {
EXPECT_EQ(element_animations_impl, player_impl_->element_animations());
int list_size_after = 0;
- for (auto& player : element_animations_impl_->players_list()) {
- EXPECT_TRUE(timeline_->GetPlayerById(player.id()));
+ for (auto it = tickers.begin(); it != tickers.end(); ++it)
++list_size_after;
- }
EXPECT_EQ(2, list_size_after);
}
@@ -208,22 +221,22 @@ TEST_F(ElementAnimationsTest, SyncNewAnimation) {
AttachTimelinePlayerLayer();
CreateImplTimelineAndPlayer();
+ EXPECT_FALSE(player_->GetAnimation(TargetProperty::OPACITY));
EXPECT_FALSE(player_impl_->GetAnimation(TargetProperty::OPACITY));
- EXPECT_FALSE(player_->needs_to_start_animations());
- EXPECT_FALSE(player_impl_->needs_to_start_animations());
-
int animation_id =
AddOpacityTransitionToPlayer(player_.get(), 1, 0, 1, false);
- EXPECT_TRUE(player_->needs_to_start_animations());
+ EXPECT_TRUE(ticker_->GetAnimationById(animation_id));
+ EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
+ ticker_->GetAnimationById(animation_id)->run_state());
+ EXPECT_FALSE(ticker_impl_->GetAnimationById(animation_id));
PushProperties();
- EXPECT_TRUE(player_impl_->needs_to_start_animations());
player_impl_->ActivateAnimations();
- EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
+ EXPECT_TRUE(ticker_impl_->GetAnimationById(animation_id));
EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
- player_impl_->GetAnimationById(animation_id)->run_state());
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
}
TEST_F(ElementAnimationsTest,
@@ -232,11 +245,9 @@ TEST_F(ElementAnimationsTest,
AttachTimelinePlayerLayer();
CreateImplTimelineAndPlayer();
+ EXPECT_FALSE(player_->GetAnimation(TargetProperty::SCROLL_OFFSET));
EXPECT_FALSE(player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET));
- EXPECT_FALSE(player_->needs_to_start_animations());
- EXPECT_FALSE(player_impl_->needs_to_start_animations());
-
gfx::ScrollOffset initial_value(100.f, 300.f);
gfx::ScrollOffset provider_initial_value(150.f, 300.f);
gfx::ScrollOffset target_value(300.f, 200.f);
@@ -255,7 +266,7 @@ TEST_F(ElementAnimationsTest,
player_->AddAnimation(std::move(animation_fixed));
PushProperties();
EXPECT_VECTOR2DF_EQ(initial_value,
- player_impl_->GetAnimationById(animation1_id)
+ ticker_impl_->GetAnimationById(animation1_id)
->curve()
->ToScrollOffsetAnimationCurve()
->GetValue(base::TimeDelta()));
@@ -271,7 +282,7 @@ TEST_F(ElementAnimationsTest,
player_->AddAnimation(std::move(animation));
PushProperties();
EXPECT_VECTOR2DF_EQ(provider_initial_value,
- player_impl_->GetAnimationById(animation2_id)
+ ticker_impl_->GetAnimationById(animation2_id)
->curve()
->ToScrollOffsetAnimationCurve()
->GetValue(base::TimeDelta()));
@@ -330,7 +341,7 @@ TEST_F(ElementAnimationsTest, AddedPlayerIsDestroyed) {
DCHECK(player2_impl);
player2_impl->ActivateAnimations();
- EXPECT_TRUE(player2_impl->GetAnimationById(animation_id));
+ EXPECT_TRUE(player2_impl->animation_ticker()->GetAnimationById(animation_id));
player2_impl->Tick(kInitialTickTime);
@@ -340,7 +351,7 @@ TEST_F(ElementAnimationsTest, AddedPlayerIsDestroyed) {
EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type);
// The actual detachment happens here, inside the callback
- player2->NotifyAnimationStarted(events->events_[0]);
+ player2->animation_ticker()->NotifyAnimationStarted(events->events_[0]);
EXPECT_TRUE(delegate.started());
}
@@ -359,9 +370,9 @@ TEST_F(ElementAnimationsTest, DoNotClobberStartTimes) {
PushProperties();
player_impl_->ActivateAnimations();
- EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
+ EXPECT_TRUE(ticker_impl_->GetAnimationById(animation_id));
EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
- player_impl_->GetAnimationById(animation_id)->run_state());
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
auto events = CreateEventsForTesting();
player_impl_->Tick(kInitialTickTime);
@@ -369,15 +380,15 @@ TEST_F(ElementAnimationsTest, DoNotClobberStartTimes) {
// Synchronize the start times.
EXPECT_EQ(1u, events->events_.size());
- player_->NotifyAnimationStarted(events->events_[0]);
- EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(),
- player_impl_->GetAnimationById(animation_id)->start_time());
+ ticker_->NotifyAnimationStarted(events->events_[0]);
+ EXPECT_EQ(ticker_->GetAnimationById(animation_id)->start_time(),
+ ticker_impl_->GetAnimationById(animation_id)->start_time());
// Start the animation on the main thread. Should not affect the start time.
player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(500));
player_impl_->UpdateState(true, nullptr);
- EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(),
- player_impl_->GetAnimationById(animation_id)->start_time());
+ EXPECT_EQ(ticker_->GetAnimationById(animation_id)->start_time(),
+ ticker_impl_->GetAnimationById(animation_id)->start_time());
}
TEST_F(ElementAnimationsTest, UseSpecifiedStartTimes) {
@@ -394,9 +405,9 @@ TEST_F(ElementAnimationsTest, UseSpecifiedStartTimes) {
PushProperties();
player_impl_->ActivateAnimations();
- EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
+ EXPECT_TRUE(ticker_impl_->GetAnimationById(animation_id));
EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
- player_impl_->GetAnimationById(animation_id)->run_state());
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
auto events = CreateEventsForTesting();
player_impl_->Tick(kInitialTickTime);
@@ -404,18 +415,18 @@ TEST_F(ElementAnimationsTest, UseSpecifiedStartTimes) {
// Synchronize the start times.
EXPECT_EQ(1u, events->events_.size());
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
- EXPECT_EQ(start_time, player_->GetAnimationById(animation_id)->start_time());
- EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(),
- player_impl_->GetAnimationById(animation_id)->start_time());
+ EXPECT_EQ(start_time, ticker_->GetAnimationById(animation_id)->start_time());
+ EXPECT_EQ(ticker_->GetAnimationById(animation_id)->start_time(),
+ ticker_impl_->GetAnimationById(animation_id)->start_time());
// Start the animation on the main thread. Should not affect the start time.
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(500));
player_->UpdateState(true, nullptr);
- EXPECT_EQ(start_time, player_->GetAnimationById(animation_id)->start_time());
- EXPECT_EQ(player_->GetAnimationById(animation_id)->start_time(),
- player_impl_->GetAnimationById(animation_id)->start_time());
+ EXPECT_EQ(start_time, ticker_->GetAnimationById(animation_id)->start_time());
+ EXPECT_EQ(ticker_->GetAnimationById(animation_id)->start_time(),
+ ticker_impl_->GetAnimationById(animation_id)->start_time());
}
// Tests that animationss activate and deactivate as expected.
@@ -449,7 +460,7 @@ TEST_F(ElementAnimationsTest, Activation) {
player_impl_->Tick(kInitialTickTime);
player_impl_->UpdateState(true, events.get());
EXPECT_EQ(1u, events->events_.size());
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
EXPECT_EQ(1u, host->ticking_players_for_testing().size());
EXPECT_EQ(1u, host_impl->ticking_players_for_testing().size());
@@ -475,7 +486,7 @@ TEST_F(ElementAnimationsTest, Activation) {
EXPECT_EQ(0u, host_impl->ticking_players_for_testing().size());
EXPECT_EQ(1u, events->events_.size());
- player_->NotifyAnimationFinished(events->events_[0]);
+ ticker_->NotifyAnimationFinished(events->events_[0]);
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1500));
player_->UpdateState(true, nullptr);
@@ -486,8 +497,8 @@ TEST_F(ElementAnimationsTest, Activation) {
PushProperties();
player_impl_->ActivateAnimations();
- EXPECT_FALSE(player_->has_any_animation());
- EXPECT_FALSE(player_impl_->has_any_animation());
+ EXPECT_FALSE(ticker_->has_any_animation());
+ EXPECT_FALSE(ticker_impl_->has_any_animation());
EXPECT_EQ(0u, host->ticking_players_for_testing().size());
EXPECT_EQ(0u, host_impl->ticking_players_for_testing().size());
}
@@ -505,15 +516,15 @@ TEST_F(ElementAnimationsTest, SyncPause) {
AddOpacityStepsToPlayer(player_.get(), duration, 0.2f, 0.4f, 2);
// Set start offset to be at the beginning of the second range.
- player_->GetAnimationById(animation_id)
+ ticker_->GetAnimationById(animation_id)
->set_time_offset(TimeDelta::FromSecondsD(1.01));
PushProperties();
player_impl_->ActivateAnimations();
- EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
+ EXPECT_TRUE(ticker_impl_->GetAnimationById(animation_id));
EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
- player_impl_->GetAnimationById(animation_id)->run_state());
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
TimeTicks time = kInitialTickTime;
@@ -525,27 +536,27 @@ TEST_F(ElementAnimationsTest, SyncPause) {
player_->Tick(time);
player_->UpdateState(true, nullptr);
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
EXPECT_EQ(Animation::RUNNING,
- player_impl_->GetAnimationById(animation_id)->run_state());
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
EXPECT_EQ(Animation::RUNNING,
- player_->GetAnimationById(animation_id)->run_state());
+ ticker_->GetAnimationById(animation_id)->run_state());
EXPECT_EQ(0.3f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
EXPECT_EQ(0.3f,
client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
EXPECT_EQ(kInitialTickTime,
- player_->GetAnimationById(animation_id)->start_time());
+ ticker_->GetAnimationById(animation_id)->start_time());
EXPECT_EQ(kInitialTickTime,
- player_impl_->GetAnimationById(animation_id)->start_time());
+ ticker_impl_->GetAnimationById(animation_id)->start_time());
// Pause the animation at the middle of the second range so the offset
// delays animation until the middle of the third range.
player_->PauseAnimation(animation_id, 1.5);
EXPECT_EQ(Animation::PAUSED,
- player_->GetAnimationById(animation_id)->run_state());
+ ticker_->GetAnimationById(animation_id)->run_state());
// The pause run state change should make it to the impl thread animations.
PushProperties();
@@ -557,7 +568,7 @@ TEST_F(ElementAnimationsTest, SyncPause) {
player_impl_->Tick(time);
EXPECT_EQ(Animation::PAUSED,
- player_impl_->GetAnimationById(animation_id)->run_state());
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
// Opacity value doesn't depend on time if paused at specified time offset.
EXPECT_EQ(0.4f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
@@ -580,9 +591,9 @@ TEST_F(ElementAnimationsTest, DoNotSyncFinishedAnimation) {
PushProperties();
player_impl_->ActivateAnimations();
- EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
+ EXPECT_TRUE(ticker_impl_->GetAnimationById(animation_id));
EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
- player_impl_->GetAnimationById(animation_id)->run_state());
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
events = CreateEventsForTesting();
player_impl_->Tick(kInitialTickTime);
@@ -591,7 +602,7 @@ TEST_F(ElementAnimationsTest, DoNotSyncFinishedAnimation) {
EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type);
// Notify main thread animations that the animation has started.
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
// Complete animation on impl thread.
events = CreateEventsForTesting();
@@ -600,15 +611,15 @@ TEST_F(ElementAnimationsTest, DoNotSyncFinishedAnimation) {
EXPECT_EQ(1u, events->events_.size());
EXPECT_EQ(AnimationEvent::FINISHED, events->events_[0].type);
- player_->NotifyAnimationFinished(events->events_[0]);
+ ticker_->NotifyAnimationFinished(events->events_[0]);
player_->Tick(kInitialTickTime + TimeDelta::FromSeconds(2));
player_->UpdateState(true, nullptr);
PushProperties();
player_impl_->ActivateAnimations();
- EXPECT_FALSE(player_->GetAnimationById(animation_id));
- EXPECT_FALSE(player_impl_->GetAnimationById(animation_id));
+ EXPECT_FALSE(ticker_->GetAnimationById(animation_id));
+ EXPECT_FALSE(ticker_impl_->GetAnimationById(animation_id));
}
// Ensure that a finished animation is eventually deleted by both the
@@ -623,10 +634,10 @@ TEST_F(ElementAnimationsTest, AnimationsAreDeleted) {
AddOpacityTransitionToPlayer(player_.get(), 1.0, 0.0f, 1.0f, false);
player_->Tick(kInitialTickTime);
player_->UpdateState(true, nullptr);
- EXPECT_TRUE(player_->needs_push_properties());
+ EXPECT_TRUE(ticker_->needs_push_properties());
PushProperties();
- EXPECT_FALSE(player_->needs_push_properties());
+ EXPECT_FALSE(ticker_->needs_push_properties());
EXPECT_FALSE(host_->needs_push_properties());
EXPECT_FALSE(host_impl_->needs_push_properties());
@@ -639,7 +650,7 @@ TEST_F(ElementAnimationsTest, AnimationsAreDeleted) {
// There should be a STARTED event for the animation.
EXPECT_EQ(1u, events->events_.size());
EXPECT_EQ(AnimationEvent::STARTED, events->events_[0].type);
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
player_->UpdateState(true, nullptr);
@@ -661,7 +672,7 @@ TEST_F(ElementAnimationsTest, AnimationsAreDeleted) {
EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY));
EXPECT_TRUE(player_impl_->GetAnimation(TargetProperty::OPACITY));
- player_->NotifyAnimationFinished(events->events_[0]);
+ ticker_->NotifyAnimationFinished(events->events_[0]);
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
player_->UpdateState(true, nullptr);
@@ -673,8 +684,8 @@ TEST_F(ElementAnimationsTest, AnimationsAreDeleted) {
// should have deleted the animation even though activation has not occurred,
// since the animation was already waiting for deletion when
// PushPropertiesTo was called.
- EXPECT_FALSE(player_->has_any_animation());
- EXPECT_FALSE(player_impl_->has_any_animation());
+ EXPECT_FALSE(ticker_->has_any_animation());
+ EXPECT_FALSE(ticker_impl_->has_any_animation());
}
// Tests that transitioning opacity from 0 to 1 works as expected.
@@ -695,20 +706,24 @@ TEST_F(ElementAnimationsTest, TrivialTransition) {
std::unique_ptr<Animation> to_add(CreateAnimation(
std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1, TargetProperty::OPACITY));
+ int animation_id = to_add->id();
- EXPECT_FALSE(player_->needs_to_start_animations());
+ EXPECT_FALSE(ticker_->GetAnimationById(animation_id));
player_->AddAnimation(std::move(to_add));
- EXPECT_TRUE(player_->needs_to_start_animations());
+ EXPECT_TRUE(ticker_->GetAnimationById(animation_id));
+ EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
+ ticker_->GetAnimationById(animation_id)->run_state());
player_->Tick(kInitialTickTime);
- EXPECT_FALSE(player_->needs_to_start_animations());
+ EXPECT_EQ(Animation::STARTING,
+ ticker_->GetAnimationById(animation_id)->run_state());
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
player_->UpdateState(true, events.get());
EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
- EXPECT_FALSE(player_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_->HasTickingAnimation());
}
TEST_F(ElementAnimationsTest, FilterTransition) {
@@ -735,7 +750,7 @@ TEST_F(ElementAnimationsTest, FilterTransition) {
player_->Tick(kInitialTickTime);
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(start_filters,
client_.GetFilters(element_id_, ElementListType::ACTIVE));
@@ -750,7 +765,7 @@ TEST_F(ElementAnimationsTest, FilterTransition) {
player_->UpdateState(true, events.get());
EXPECT_EQ(end_filters,
client_.GetFilters(element_id_, ElementListType::ACTIVE));
- EXPECT_FALSE(player_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_->HasTickingAnimation());
}
TEST_F(ElementAnimationsTest, ScrollOffsetTransition) {
@@ -785,20 +800,20 @@ TEST_F(ElementAnimationsTest, ScrollOffsetTransition) {
player_->Tick(kInitialTickTime);
player_->UpdateState(true, nullptr);
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(initial_value,
client_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
player_impl_->Tick(kInitialTickTime);
player_impl_->UpdateState(true, events.get());
- EXPECT_TRUE(player_impl_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_impl_->HasTickingAnimation());
EXPECT_EQ(initial_value,
client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
player_->Tick(kInitialTickTime + duration / 2);
player_->UpdateState(true, nullptr);
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_VECTOR2DF_EQ(
gfx::Vector2dF(200.f, 250.f),
client_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
@@ -813,13 +828,13 @@ TEST_F(ElementAnimationsTest, ScrollOffsetTransition) {
player_impl_->UpdateState(true, events.get());
EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset(
element_id_, ElementListType::ACTIVE));
- EXPECT_FALSE(player_impl_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_impl_->HasTickingAnimation());
player_->Tick(kInitialTickTime + duration);
player_->UpdateState(true, nullptr);
EXPECT_VECTOR2DF_EQ(target_value, client_.GetScrollOffset(
element_id_, ElementListType::ACTIVE));
- EXPECT_FALSE(player_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_->HasTickingAnimation());
}
TEST_F(ElementAnimationsTest, ScrollOffsetTransitionOnImplOnly) {
@@ -845,7 +860,7 @@ TEST_F(ElementAnimationsTest, ScrollOffsetTransitionOnImplOnly) {
player_impl_->Tick(kInitialTickTime);
player_impl_->UpdateState(true, events.get());
- EXPECT_TRUE(player_impl_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_impl_->HasTickingAnimation());
EXPECT_EQ(initial_value,
client_impl_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
@@ -862,7 +877,7 @@ TEST_F(ElementAnimationsTest, ScrollOffsetTransitionOnImplOnly) {
player_impl_->UpdateState(true, events.get());
EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset(
element_id_, ElementListType::ACTIVE));
- EXPECT_FALSE(player_impl_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_impl_->HasTickingAnimation());
}
// This test verifies that if an animation is added after a layer is animated,
@@ -956,7 +971,7 @@ TEST_F(ElementAnimationsTest, ScrollOffsetTransitionNoImplProvider) {
player_->Tick(kInitialTickTime);
player_->UpdateState(true, nullptr);
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(initial_value,
client_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
EXPECT_EQ(gfx::ScrollOffset(), client_impl_.GetScrollOffset(
@@ -964,7 +979,7 @@ TEST_F(ElementAnimationsTest, ScrollOffsetTransitionNoImplProvider) {
player_impl_->Tick(kInitialTickTime);
- EXPECT_TRUE(player_impl_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_impl_->HasTickingAnimation());
EXPECT_EQ(initial_value, client_impl_.GetScrollOffset(
element_id_, ElementListType::PENDING));
@@ -973,10 +988,10 @@ TEST_F(ElementAnimationsTest, ScrollOffsetTransitionNoImplProvider) {
player_impl_->UpdateState(true, events.get());
DCHECK_EQ(1UL, events->events_.size());
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
player_->Tick(kInitialTickTime + duration / 2);
player_->UpdateState(true, nullptr);
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_VECTOR2DF_EQ(
gfx::Vector2dF(400.f, 150.f),
client_.GetScrollOffset(element_id_, ElementListType::ACTIVE));
@@ -991,13 +1006,13 @@ TEST_F(ElementAnimationsTest, ScrollOffsetTransitionNoImplProvider) {
player_impl_->UpdateState(true, events.get());
EXPECT_VECTOR2DF_EQ(target_value, client_impl_.GetScrollOffset(
element_id_, ElementListType::PENDING));
- EXPECT_FALSE(player_impl_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_impl_->HasTickingAnimation());
player_->Tick(kInitialTickTime + duration);
player_->UpdateState(true, nullptr);
EXPECT_VECTOR2DF_EQ(target_value, client_.GetScrollOffset(
element_id_, ElementListType::ACTIVE));
- EXPECT_FALSE(player_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_->HasTickingAnimation());
}
TEST_F(ElementAnimationsTest, ScrollOffsetRemovalClearsScrollDelta) {
@@ -1021,18 +1036,18 @@ TEST_F(ElementAnimationsTest, ScrollOffsetRemovalClearsScrollDelta) {
player_->AddAnimation(std::move(animation));
PushProperties();
player_impl_->ActivateAnimations();
- EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
- EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_impl_->scroll_offset_animation_was_interrupted());
player_->RemoveAnimation(animation_id);
- EXPECT_TRUE(player_->scroll_offset_animation_was_interrupted());
+ EXPECT_TRUE(ticker_->scroll_offset_animation_was_interrupted());
PushProperties();
- EXPECT_TRUE(player_impl_->scroll_offset_animation_was_interrupted());
- EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
+ EXPECT_TRUE(ticker_impl_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_->scroll_offset_animation_was_interrupted());
player_impl_->ActivateAnimations();
- EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_impl_->scroll_offset_animation_was_interrupted());
// Now, test the 2-argument version of RemoveAnimation.
curve = ScrollOffsetAnimationCurve::Create(
@@ -1044,52 +1059,52 @@ TEST_F(ElementAnimationsTest, ScrollOffsetRemovalClearsScrollDelta) {
player_->AddAnimation(std::move(animation));
PushProperties();
player_impl_->ActivateAnimations();
- EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
- EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_impl_->scroll_offset_animation_was_interrupted());
player_->RemoveAnimation(animation_id);
- EXPECT_TRUE(player_->scroll_offset_animation_was_interrupted());
+ EXPECT_TRUE(ticker_->scroll_offset_animation_was_interrupted());
PushProperties();
- EXPECT_TRUE(player_impl_->scroll_offset_animation_was_interrupted());
- EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
+ EXPECT_TRUE(ticker_impl_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_->scroll_offset_animation_was_interrupted());
player_impl_->ActivateAnimations();
- EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_impl_->scroll_offset_animation_was_interrupted());
// Check that removing non-scroll-offset animations does not cause
// scroll_offset_animation_was_interrupted() to get set.
animation_id = AddAnimatedTransformToPlayer(player_.get(), 1.0, 1, 2);
PushProperties();
player_impl_->ActivateAnimations();
- EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
- EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_impl_->scroll_offset_animation_was_interrupted());
player_->RemoveAnimation(animation_id);
- EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_->scroll_offset_animation_was_interrupted());
PushProperties();
- EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
- EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_impl_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_->scroll_offset_animation_was_interrupted());
player_impl_->ActivateAnimations();
- EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_impl_->scroll_offset_animation_was_interrupted());
animation_id = AddAnimatedFilterToPlayer(player_.get(), 1.0, 0.1f, 0.2f);
PushProperties();
player_impl_->ActivateAnimations();
- EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
- EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_impl_->scroll_offset_animation_was_interrupted());
player_->RemoveAnimation(animation_id);
- EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_->scroll_offset_animation_was_interrupted());
PushProperties();
- EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
- EXPECT_FALSE(player_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_impl_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_->scroll_offset_animation_was_interrupted());
player_impl_->ActivateAnimations();
- EXPECT_FALSE(player_impl_->scroll_offset_animation_was_interrupted());
+ EXPECT_FALSE(ticker_impl_->scroll_offset_animation_was_interrupted());
}
// Tests that impl-only animations lead to start and finished notifications
@@ -1156,9 +1171,9 @@ TEST_F(ElementAnimationsTest, SpecifiedStartTimesAreSentToMainThreadDelegate) {
PushProperties();
player_impl_->ActivateAnimations();
- EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
+ EXPECT_TRUE(ticker_impl_->GetAnimationById(animation_id));
EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
- player_impl_->GetAnimationById(animation_id)->run_state());
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
auto events = CreateEventsForTesting();
player_impl_->Tick(kInitialTickTime);
@@ -1166,7 +1181,7 @@ TEST_F(ElementAnimationsTest, SpecifiedStartTimesAreSentToMainThreadDelegate) {
// Synchronize the start times.
EXPECT_EQ(1u, events->events_.size());
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
// Validate start time on the main thread delegate.
EXPECT_EQ(start_time, delegate.start_time());
@@ -1191,25 +1206,25 @@ TEST_F(ElementAnimationsTest,
player_->AddAnimation(std::move(to_add));
player_->Tick(kInitialTickTime);
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
// Send the synchronized start time.
- player_->NotifyAnimationStarted(AnimationEvent(
+ ticker_->NotifyAnimationStarted(AnimationEvent(
AnimationEvent::STARTED, ElementId(), 1, TargetProperty::OPACITY,
kInitialTickTime + TimeDelta::FromMilliseconds(2000)));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(5000));
player_->UpdateState(true, events.get());
EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
- EXPECT_FALSE(player_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_->HasTickingAnimation());
}
// Tests that two queued animations affecting the same property run in sequence.
@@ -1219,37 +1234,48 @@ TEST_F(ElementAnimationsTest, TrivialQueuing) {
auto events = CreateEventsForTesting();
- EXPECT_FALSE(player_->needs_to_start_animations());
-
- player_->AddAnimation(CreateAnimation(
+ int animation1_id = 1;
+ int animation2_id = 2;
+ player_->AddAnimation(Animation::Create(
std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
- 1, TargetProperty::OPACITY));
- player_->AddAnimation(CreateAnimation(
+ animation1_id, 1, TargetProperty::OPACITY));
+ player_->AddAnimation(Animation::Create(
std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)),
- 2, TargetProperty::OPACITY));
-
- EXPECT_TRUE(player_->needs_to_start_animations());
+ animation2_id, 2, TargetProperty::OPACITY));
player_->Tick(kInitialTickTime);
+ // The first animation should have been started.
+ EXPECT_TRUE(ticker_->GetAnimationById(animation1_id));
+ EXPECT_EQ(Animation::STARTING,
+ ticker_->GetAnimationById(animation1_id)->run_state());
+
// The second animation still needs to be started.
- EXPECT_TRUE(player_->needs_to_start_animations());
+ EXPECT_TRUE(ticker_->GetAnimationById(animation2_id));
+ EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
+ ticker_->GetAnimationById(animation2_id)->run_state());
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
- EXPECT_TRUE(player_->needs_to_start_animations());
player_->UpdateState(true, events.get());
- EXPECT_FALSE(player_->needs_to_start_animations());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ // Now the first should be finished, and the second started.
+ EXPECT_TRUE(ticker_->GetAnimationById(animation1_id));
+ EXPECT_EQ(Animation::FINISHED,
+ ticker_->GetAnimationById(animation1_id)->run_state());
+ EXPECT_TRUE(ticker_->GetAnimationById(animation2_id));
+ EXPECT_EQ(Animation::RUNNING,
+ ticker_->GetAnimationById(animation2_id)->run_state());
+
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
player_->UpdateState(true, events.get());
EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
- EXPECT_FALSE(player_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_->HasTickingAnimation());
}
// Tests interrupting a transition with another transition.
@@ -1264,7 +1290,7 @@ TEST_F(ElementAnimationsTest, Interrupt) {
1, TargetProperty::OPACITY));
player_->Tick(kInitialTickTime);
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
std::unique_ptr<Animation> to_add(CreateAnimation(
@@ -1277,12 +1303,12 @@ TEST_F(ElementAnimationsTest, Interrupt) {
// right in this call to animate.
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(500));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1500));
player_->UpdateState(true, events.get());
EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
- EXPECT_FALSE(player_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_->HasTickingAnimation());
}
// Tests scheduling two animations to run together when only one property is
@@ -1306,17 +1332,17 @@ TEST_F(ElementAnimationsTest, ScheduleTogetherWhenAPropertyIsBlocked) {
player_->Tick(kInitialTickTime);
player_->UpdateState(true, events.get());
EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
player_->UpdateState(true, events.get());
// Should not have started the float transition yet.
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
// The float animation should have started at time 1 and should be done.
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
player_->UpdateState(true, events.get());
EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
- EXPECT_FALSE(player_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_->HasTickingAnimation());
}
// Tests scheduling two animations to run together with different lengths and
@@ -1341,7 +1367,7 @@ TEST_F(ElementAnimationsTest, ScheduleTogetherWithAnAnimWaiting) {
// Animations with id 1 should both start now.
player_->Tick(kInitialTickTime);
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
// The opacity animation should have finished at time 1, but the group
// of animations with id 1 don't finish until time 2 because of the length
@@ -1349,7 +1375,7 @@ TEST_F(ElementAnimationsTest, ScheduleTogetherWithAnAnimWaiting) {
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
player_->UpdateState(true, events.get());
// Should not have started the float transition yet.
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
// The second opacity animation should start at time 2 and should be done by
@@ -1357,7 +1383,7 @@ TEST_F(ElementAnimationsTest, ScheduleTogetherWithAnAnimWaiting) {
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
player_->UpdateState(true, events.get());
EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
- EXPECT_FALSE(player_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_->HasTickingAnimation());
}
// Test that a looping animation loops and for the correct number of iterations.
@@ -1375,27 +1401,27 @@ TEST_F(ElementAnimationsTest, TrivialLooping) {
player_->Tick(kInitialTickTime);
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1250));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1750));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(2250));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(2750));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
player_->UpdateState(true, events.get());
- EXPECT_FALSE(player_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_->HasTickingAnimation());
EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
// Just be extra sure.
@@ -1419,31 +1445,31 @@ TEST_F(ElementAnimationsTest, InfiniteLooping) {
player_->Tick(kInitialTickTime);
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1250));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1750));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1073741824250));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.25f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1073741824750));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY));
player_->GetAnimation(TargetProperty::OPACITY)
->SetRunState(Animation::ABORTED,
kInitialTickTime + TimeDelta::FromMilliseconds(750));
- EXPECT_FALSE(player_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
}
@@ -1460,11 +1486,11 @@ TEST_F(ElementAnimationsTest, PauseResume) {
player_->Tick(kInitialTickTime);
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(500));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY));
@@ -1474,7 +1500,7 @@ TEST_F(ElementAnimationsTest, PauseResume) {
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1024000));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
EXPECT_TRUE(player_->GetAnimation(TargetProperty::OPACITY));
@@ -1483,12 +1509,12 @@ TEST_F(ElementAnimationsTest, PauseResume) {
kInitialTickTime + TimeDelta::FromMilliseconds(1024000));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1024250));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1024500));
player_->UpdateState(true, events.get());
- EXPECT_FALSE(player_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_->HasTickingAnimation());
EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
}
@@ -1511,24 +1537,24 @@ TEST_F(ElementAnimationsTest, AbortAGroupedAnimation) {
player_->Tick(kInitialTickTime);
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.5f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
- EXPECT_TRUE(player_->GetAnimationById(animation_id));
- player_->GetAnimationById(animation_id)
+ EXPECT_TRUE(ticker_->GetAnimationById(animation_id));
+ ticker_->GetAnimationById(animation_id)
->SetRunState(Animation::ABORTED,
kInitialTickTime + TimeDelta::FromMilliseconds(1000));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
player_->UpdateState(true, events.get());
- EXPECT_TRUE(!player_->HasTickingAnimation());
+ EXPECT_TRUE(!ticker_->HasTickingAnimation());
EXPECT_EQ(0.75f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
}
@@ -1547,12 +1573,12 @@ TEST_F(ElementAnimationsTest, PushUpdatesWhenSynchronizedStartTimeNeeded) {
player_->Tick(kInitialTickTime);
player_->UpdateState(true, events.get());
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
Animation* active_animation = player_->GetAnimation(TargetProperty::OPACITY);
EXPECT_TRUE(active_animation);
EXPECT_TRUE(active_animation->needs_synchronized_start_time());
- EXPECT_TRUE(player_->needs_push_properties());
+ EXPECT_TRUE(ticker_->needs_push_properties());
PushProperties();
player_impl_->ActivateAnimations();
@@ -1596,7 +1622,7 @@ TEST_F(ElementAnimationsTest, SkipUpdateState) {
EXPECT_NE(events->events_[0].type, events->events_[1].type);
// The float transition should still be at its starting point.
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(3000));
@@ -1604,7 +1630,7 @@ TEST_F(ElementAnimationsTest, SkipUpdateState) {
// The float tranisition should now be done.
EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
- EXPECT_FALSE(player_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_->HasTickingAnimation());
}
// Tests that an animation animations with only a pending observer gets ticked
@@ -1673,113 +1699,6 @@ TEST_F(ElementAnimationsTest, InactiveObserverGetsTicked) {
client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
}
-TEST_F(ElementAnimationsTest, TransformAnimationBounds) {
- AttachTimelinePlayerLayer();
- CreateImplTimelineAndPlayer();
-
- std::unique_ptr<KeyframedTransformAnimationCurve> curve1(
- KeyframedTransformAnimationCurve::Create());
-
- TransformOperations operations1;
- curve1->AddKeyframe(
- TransformKeyframe::Create(base::TimeDelta(), operations1, nullptr));
- operations1.AppendTranslate(10.0, 15.0, 0.0);
- curve1->AddKeyframe(TransformKeyframe::Create(
- base::TimeDelta::FromSecondsD(1.0), operations1, nullptr));
-
- std::unique_ptr<Animation> animation(
- Animation::Create(std::move(curve1), 1, 1, TargetProperty::TRANSFORM));
- player_impl_->AddAnimation(std::move(animation));
-
- std::unique_ptr<KeyframedTransformAnimationCurve> curve2(
- KeyframedTransformAnimationCurve::Create());
-
- TransformOperations operations2;
- curve2->AddKeyframe(
- TransformKeyframe::Create(base::TimeDelta(), operations2, nullptr));
- operations2.AppendScale(2.0, 3.0, 4.0);
- curve2->AddKeyframe(TransformKeyframe::Create(
- base::TimeDelta::FromSecondsD(1.0), operations2, nullptr));
-
- animation =
- Animation::Create(std::move(curve2), 2, 2, TargetProperty::TRANSFORM);
- player_impl_->AddAnimation(std::move(animation));
-
- gfx::BoxF box(1.f, 2.f, -1.f, 3.f, 4.f, 5.f);
- gfx::BoxF bounds;
-
- EXPECT_TRUE(player_impl_->TransformAnimationBoundsForBox(box, &bounds));
- EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 13.f, 19.f, 20.f).ToString(),
- bounds.ToString());
-
- player_impl_->GetAnimationById(1)->SetRunState(Animation::FINISHED,
- TicksFromSecondsF(0.0));
-
- // Only the unfinished animation should affect the animated bounds.
- EXPECT_TRUE(player_impl_->TransformAnimationBoundsForBox(box, &bounds));
- EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(),
- bounds.ToString());
-
- player_impl_->GetAnimationById(2)->SetRunState(Animation::FINISHED,
- TicksFromSecondsF(0.0));
-
- // There are no longer any running animations.
- EXPECT_FALSE(player_impl_->HasTransformAnimationThatInflatesBounds());
-
- // Add an animation whose bounds we don't yet support computing.
- std::unique_ptr<KeyframedTransformAnimationCurve> curve3(
- KeyframedTransformAnimationCurve::Create());
- TransformOperations operations3;
- gfx::Transform transform3;
- transform3.Scale3d(1.0, 2.0, 3.0);
- curve3->AddKeyframe(
- TransformKeyframe::Create(base::TimeDelta(), operations3, nullptr));
- operations3.AppendMatrix(transform3);
- curve3->AddKeyframe(TransformKeyframe::Create(
- base::TimeDelta::FromSecondsD(1.0), operations3, nullptr));
- animation =
- Animation::Create(std::move(curve3), 3, 3, TargetProperty::TRANSFORM);
- player_impl_->AddAnimation(std::move(animation));
- EXPECT_FALSE(player_impl_->TransformAnimationBoundsForBox(box, &bounds));
-}
-
-TEST_F(ElementAnimationsTest, TransformAnimationBoundsTwoPlayers) {
- AttachTimelinePlayerLayer();
- CreateImplTimelineAndPlayer();
-
- scoped_refptr<AnimationPlayer> player2 =
- AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
- timeline_->AttachPlayer(player2);
- player2->AttachElement(element_id_);
-
- std::unique_ptr<KeyframedTransformAnimationCurve> curve(
- KeyframedTransformAnimationCurve::Create());
-
- TransformOperations operations;
- curve->AddKeyframe(
- TransformKeyframe::Create(base::TimeDelta(), operations, nullptr));
- operations.AppendScale(2.0, 3.0, 4.0);
- curve->AddKeyframe(TransformKeyframe::Create(
- base::TimeDelta::FromSecondsD(1.0), operations, nullptr));
-
- std::unique_ptr<Animation> animation(
- Animation::Create(std::move(curve), 1, 1, TargetProperty::TRANSFORM));
- player2->AddAnimation(std::move(animation));
-
- gfx::BoxF box(1.f, 2.f, -1.f, 3.f, 4.f, 5.f);
- gfx::BoxF bounds;
-
- EXPECT_FALSE(player_impl_->HasTransformAnimationThatInflatesBounds());
- EXPECT_TRUE(player2->TransformAnimationBoundsForBox(box, &bounds));
- EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(),
- bounds.ToString());
-
- EXPECT_TRUE(
- element_animations_->TransformAnimationBoundsForBox(box, &bounds));
- EXPECT_EQ(gfx::BoxF(1.f, 2.f, -4.f, 7.f, 16.f, 20.f).ToString(),
- bounds.ToString());
-}
-
// Tests that AbortAnimations aborts all animations targeting the specified
// property.
TEST_F(ElementAnimationsTest, AbortAnimations) {
@@ -1809,21 +1728,21 @@ TEST_F(ElementAnimationsTest, AbortAnimations) {
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
player_->UpdateState(true, nullptr);
- EXPECT_EQ(Animation::FINISHED, player_->GetAnimationById(1)->run_state());
- EXPECT_EQ(Animation::FINISHED, player_->GetAnimationById(2)->run_state());
- EXPECT_EQ(Animation::RUNNING, player_->GetAnimationById(3)->run_state());
+ EXPECT_EQ(Animation::FINISHED, ticker_->GetAnimationById(1)->run_state());
+ EXPECT_EQ(Animation::FINISHED, ticker_->GetAnimationById(2)->run_state());
+ EXPECT_EQ(Animation::RUNNING, ticker_->GetAnimationById(3)->run_state());
EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
- player_->GetAnimationById(4)->run_state());
- EXPECT_EQ(Animation::RUNNING, player_->GetAnimationById(5)->run_state());
+ ticker_->GetAnimationById(4)->run_state());
+ EXPECT_EQ(Animation::RUNNING, ticker_->GetAnimationById(5)->run_state());
player_->AbortAnimations(TargetProperty::TRANSFORM, false);
// Only un-finished TRANSFORM animations should have been aborted.
- EXPECT_EQ(Animation::FINISHED, player_->GetAnimationById(1)->run_state());
- EXPECT_EQ(Animation::FINISHED, player_->GetAnimationById(2)->run_state());
- EXPECT_EQ(Animation::ABORTED, player_->GetAnimationById(3)->run_state());
- EXPECT_EQ(Animation::ABORTED, player_->GetAnimationById(4)->run_state());
- EXPECT_EQ(Animation::RUNNING, player_->GetAnimationById(5)->run_state());
+ EXPECT_EQ(Animation::FINISHED, ticker_->GetAnimationById(1)->run_state());
+ EXPECT_EQ(Animation::FINISHED, ticker_->GetAnimationById(2)->run_state());
+ EXPECT_EQ(Animation::ABORTED, ticker_->GetAnimationById(3)->run_state());
+ EXPECT_EQ(Animation::ABORTED, ticker_->GetAnimationById(4)->run_state());
+ EXPECT_EQ(Animation::RUNNING, ticker_->GetAnimationById(5)->run_state());
}
// An animation aborted on the main thread should get deleted on both threads.
@@ -1840,7 +1759,7 @@ TEST_F(ElementAnimationsTest, MainThreadAbortedAnimationGetsDeleted) {
player_impl_->ActivateAnimations();
- EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
+ EXPECT_TRUE(ticker_impl_->GetAnimationById(animation_id));
EXPECT_FALSE(host_->needs_push_properties());
player_->AbortAnimations(TargetProperty::OPACITY, false);
@@ -1853,16 +1772,15 @@ TEST_F(ElementAnimationsTest, MainThreadAbortedAnimationGetsDeleted) {
EXPECT_EQ(Animation::ABORTED,
player_->GetAnimation(TargetProperty::OPACITY)->run_state());
- EXPECT_TRUE(player_->needs_push_properties());
- EXPECT_TRUE(player_->needs_push_properties());
+ EXPECT_TRUE(ticker_->needs_push_properties());
EXPECT_TRUE(host_->needs_push_properties());
PushProperties();
+ EXPECT_FALSE(ticker_->needs_push_properties());
EXPECT_FALSE(host_->needs_push_properties());
- EXPECT_FALSE(player_->needs_push_properties());
- EXPECT_FALSE(player_->GetAnimationById(animation_id));
- EXPECT_FALSE(player_impl_->GetAnimationById(animation_id));
+ EXPECT_FALSE(ticker_->GetAnimationById(animation_id));
+ EXPECT_FALSE(ticker_impl_->GetAnimationById(animation_id));
}
// An animation aborted on the impl thread should get deleted on both threads.
@@ -1881,13 +1799,13 @@ TEST_F(ElementAnimationsTest, ImplThreadAbortedAnimationGetsDeleted) {
EXPECT_FALSE(host_->needs_push_properties());
player_impl_->ActivateAnimations();
- EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
+ EXPECT_TRUE(ticker_impl_->GetAnimationById(animation_id));
player_impl_->AbortAnimations(TargetProperty::OPACITY, false);
EXPECT_EQ(Animation::ABORTED,
player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state());
EXPECT_TRUE(host_impl_->needs_push_properties());
- EXPECT_TRUE(player_impl_->needs_push_properties());
+ EXPECT_TRUE(ticker_impl_->needs_push_properties());
auto events = CreateEventsForTesting();
player_impl_->Tick(kInitialTickTime);
@@ -1898,7 +1816,7 @@ TEST_F(ElementAnimationsTest, ImplThreadAbortedAnimationGetsDeleted) {
EXPECT_EQ(Animation::WAITING_FOR_DELETION,
player_impl_->GetAnimation(TargetProperty::OPACITY)->run_state());
- player_->NotifyAnimationAborted(events->events_[0]);
+ ticker_->NotifyAnimationAborted(events->events_[0]);
EXPECT_EQ(Animation::ABORTED,
player_->GetAnimation(TargetProperty::OPACITY)->run_state());
EXPECT_TRUE(delegate.aborted());
@@ -1912,8 +1830,8 @@ TEST_F(ElementAnimationsTest, ImplThreadAbortedAnimationGetsDeleted) {
PushProperties();
player_impl_->ActivateAnimations();
- EXPECT_FALSE(player_->GetAnimationById(animation_id));
- EXPECT_FALSE(player_impl_->GetAnimationById(animation_id));
+ EXPECT_FALSE(ticker_->GetAnimationById(animation_id));
+ EXPECT_FALSE(ticker_impl_->GetAnimationById(animation_id));
}
// Test that an impl-only scroll offset animation that needs to be completed on
@@ -1947,7 +1865,7 @@ TEST_F(ElementAnimationsTest, ImplThreadTakeoverAnimationGetsDeleted) {
EXPECT_FALSE(host_->needs_push_properties());
player_impl_->ActivateAnimations();
- EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
+ EXPECT_TRUE(ticker_impl_->GetAnimationById(animation_id));
player_impl_->AbortAnimations(TargetProperty::SCROLL_OFFSET, true);
EXPECT_TRUE(host_impl_->needs_push_properties());
@@ -1969,20 +1887,20 @@ TEST_F(ElementAnimationsTest, ImplThreadTakeoverAnimationGetsDeleted) {
EXPECT_EQ(nullptr, player_impl_->GetAnimation(TargetProperty::SCROLL_OFFSET));
// MT receives the event to take over.
- player_->NotifyAnimationTakeover(events->events_[0]);
+ ticker_->NotifyAnimationTakeover(events->events_[0]);
EXPECT_TRUE(delegate.takeover());
// AnimationPlayer::NotifyAnimationTakeover requests SetNeedsPushProperties
// to purge CT animations marked for deletion.
- EXPECT_TRUE(player_->needs_push_properties());
+ EXPECT_TRUE(ticker_->needs_push_properties());
// ElementAnimations::PurgeAnimationsMarkedForDeletion call happens only in
// ElementAnimations::PushPropertiesTo.
PushProperties();
player_impl_->ActivateAnimations();
- EXPECT_FALSE(player_->GetAnimationById(animation_id));
- EXPECT_FALSE(player_impl_->GetAnimationById(animation_id));
+ EXPECT_FALSE(ticker_->GetAnimationById(animation_id));
+ EXPECT_FALSE(ticker_impl_->GetAnimationById(animation_id));
}
// Ensure that we only generate FINISHED events for animations in a group
@@ -2025,8 +1943,8 @@ TEST_F(ElementAnimationsTest, FinishedEventsForGroup) {
// a FINISHED event yet.
EXPECT_EQ(0u, events->events_.size());
EXPECT_EQ(Animation::FINISHED,
- player_impl_->GetAnimationById(2)->run_state());
- EXPECT_EQ(Animation::RUNNING, player_impl_->GetAnimationById(1)->run_state());
+ ticker_impl_->GetAnimationById(2)->run_state());
+ EXPECT_EQ(Animation::RUNNING, ticker_impl_->GetAnimationById(1)->run_state());
player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
player_impl_->UpdateState(true, events.get());
@@ -2089,19 +2007,19 @@ TEST_F(ElementAnimationsTest, HasOnlyTranslationTransforms) {
CreateImplTimelineAndPlayer();
EXPECT_TRUE(
- player_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE));
+ ticker_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE));
EXPECT_TRUE(
- player_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING));
+ ticker_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING));
- player_impl_->AddAnimation(CreateAnimation(
+ ticker_impl_->AddAnimation(CreateAnimation(
std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
1, TargetProperty::OPACITY));
// Opacity animations aren't non-translation transforms.
EXPECT_TRUE(
- player_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE));
+ ticker_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE));
EXPECT_TRUE(
- player_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING));
+ ticker_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING));
std::unique_ptr<KeyframedTransformAnimationCurve> curve1(
KeyframedTransformAnimationCurve::Create());
@@ -2115,13 +2033,13 @@ TEST_F(ElementAnimationsTest, HasOnlyTranslationTransforms) {
std::unique_ptr<Animation> animation(
Animation::Create(std::move(curve1), 2, 2, TargetProperty::TRANSFORM));
- player_impl_->AddAnimation(std::move(animation));
+ ticker_impl_->AddAnimation(std::move(animation));
// The only transform animation we've added is a translation.
EXPECT_TRUE(
- player_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE));
+ ticker_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE));
EXPECT_TRUE(
- player_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING));
+ ticker_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING));
std::unique_ptr<KeyframedTransformAnimationCurve> curve2(
KeyframedTransformAnimationCurve::Create());
@@ -2136,35 +2054,35 @@ TEST_F(ElementAnimationsTest, HasOnlyTranslationTransforms) {
animation =
Animation::Create(std::move(curve2), 3, 3, TargetProperty::TRANSFORM);
animation->set_affects_active_elements(false);
- player_impl_->AddAnimation(std::move(animation));
+ ticker_impl_->AddAnimation(std::move(animation));
// A scale animation is not a translation.
EXPECT_FALSE(
- player_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING));
+ ticker_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING));
EXPECT_TRUE(
- player_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE));
+ ticker_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE));
- player_impl_->ActivateAnimations();
+ ticker_impl_->ActivateAnimations();
EXPECT_FALSE(
- player_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING));
+ ticker_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING));
EXPECT_FALSE(
- player_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE));
+ ticker_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE));
- player_impl_->GetAnimationById(3)->set_affects_pending_elements(false);
+ ticker_impl_->GetAnimationById(3)->set_affects_pending_elements(false);
EXPECT_TRUE(
- player_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING));
+ ticker_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING));
EXPECT_FALSE(
- player_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE));
+ ticker_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE));
- player_impl_->GetAnimationById(3)->SetRunState(Animation::FINISHED,
+ ticker_impl_->GetAnimationById(3)->SetRunState(Animation::FINISHED,
TicksFromSecondsF(0.0));
// Only unfinished animations should be considered by
// HasOnlyTranslationTransforms.
EXPECT_TRUE(
- player_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING));
+ ticker_impl_->HasOnlyTranslationTransforms(ElementListType::PENDING));
EXPECT_TRUE(
- player_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE));
+ ticker_impl_->HasOnlyTranslationTransforms(ElementListType::ACTIVE));
}
TEST_F(ElementAnimationsTest, AnimationStartScale) {
@@ -2188,19 +2106,19 @@ TEST_F(ElementAnimationsTest, AnimationStartScale) {
player_impl_->AddAnimation(std::move(animation));
float start_scale = 0.f;
- EXPECT_TRUE(player_impl_->AnimationStartScale(ElementListType::PENDING,
+ EXPECT_TRUE(ticker_impl_->AnimationStartScale(ElementListType::PENDING,
&start_scale));
EXPECT_EQ(4.f, start_scale);
EXPECT_TRUE(
- player_impl_->AnimationStartScale(ElementListType::ACTIVE, &start_scale));
+ ticker_impl_->AnimationStartScale(ElementListType::ACTIVE, &start_scale));
EXPECT_EQ(0.f, start_scale);
player_impl_->ActivateAnimations();
- EXPECT_TRUE(player_impl_->AnimationStartScale(ElementListType::PENDING,
+ EXPECT_TRUE(ticker_impl_->AnimationStartScale(ElementListType::PENDING,
&start_scale));
EXPECT_EQ(4.f, start_scale);
EXPECT_TRUE(
- player_impl_->AnimationStartScale(ElementListType::ACTIVE, &start_scale));
+ ticker_impl_->AnimationStartScale(ElementListType::ACTIVE, &start_scale));
EXPECT_EQ(4.f, start_scale);
std::unique_ptr<KeyframedTransformAnimationCurve> curve2(
@@ -2238,31 +2156,31 @@ TEST_F(ElementAnimationsTest, AnimationStartScale) {
animation->set_affects_active_elements(false);
player_impl_->AddAnimation(std::move(animation));
- EXPECT_TRUE(player_impl_->AnimationStartScale(ElementListType::PENDING,
+ EXPECT_TRUE(ticker_impl_->AnimationStartScale(ElementListType::PENDING,
&start_scale));
EXPECT_EQ(6.f, start_scale);
EXPECT_TRUE(
- player_impl_->AnimationStartScale(ElementListType::ACTIVE, &start_scale));
+ ticker_impl_->AnimationStartScale(ElementListType::ACTIVE, &start_scale));
EXPECT_EQ(0.f, start_scale);
player_impl_->ActivateAnimations();
- EXPECT_TRUE(player_impl_->AnimationStartScale(ElementListType::PENDING,
+ EXPECT_TRUE(ticker_impl_->AnimationStartScale(ElementListType::PENDING,
&start_scale));
EXPECT_EQ(6.f, start_scale);
EXPECT_TRUE(
- player_impl_->AnimationStartScale(ElementListType::ACTIVE, &start_scale));
+ ticker_impl_->AnimationStartScale(ElementListType::ACTIVE, &start_scale));
EXPECT_EQ(6.f, start_scale);
- player_impl_->GetAnimationById(2)->SetRunState(Animation::FINISHED,
+ ticker_impl_->GetAnimationById(2)->SetRunState(Animation::FINISHED,
TicksFromSecondsF(0.0));
// Only unfinished animations should be considered by
// AnimationStartScale.
- EXPECT_TRUE(player_impl_->AnimationStartScale(ElementListType::PENDING,
+ EXPECT_TRUE(ticker_impl_->AnimationStartScale(ElementListType::PENDING,
&start_scale));
EXPECT_EQ(5.f, start_scale);
EXPECT_TRUE(
- player_impl_->AnimationStartScale(ElementListType::ACTIVE, &start_scale));
+ ticker_impl_->AnimationStartScale(ElementListType::ACTIVE, &start_scale));
EXPECT_EQ(5.f, start_scale);
}
@@ -2273,10 +2191,10 @@ TEST_F(ElementAnimationsTest, MaximumTargetScale) {
float max_scale = 0.f;
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_EQ(0.f, max_scale);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
EXPECT_EQ(0.f, max_scale);
std::unique_ptr<KeyframedTransformAnimationCurve> curve1(
@@ -2295,18 +2213,18 @@ TEST_F(ElementAnimationsTest, MaximumTargetScale) {
player_impl_->AddAnimation(std::move(animation));
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_EQ(4.f, max_scale);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
EXPECT_EQ(0.f, max_scale);
player_impl_->ActivateAnimations();
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_EQ(4.f, max_scale);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
EXPECT_EQ(4.f, max_scale);
std::unique_ptr<KeyframedTransformAnimationCurve> curve2(
@@ -2325,18 +2243,18 @@ TEST_F(ElementAnimationsTest, MaximumTargetScale) {
player_impl_->AddAnimation(std::move(animation));
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_EQ(6.f, max_scale);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
EXPECT_EQ(4.f, max_scale);
player_impl_->ActivateAnimations();
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_EQ(6.f, max_scale);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
EXPECT_EQ(6.f, max_scale);
std::unique_ptr<KeyframedTransformAnimationCurve> curve3(
@@ -2355,29 +2273,29 @@ TEST_F(ElementAnimationsTest, MaximumTargetScale) {
player_impl_->AddAnimation(std::move(animation));
EXPECT_FALSE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
EXPECT_EQ(6.f, max_scale);
player_impl_->ActivateAnimations();
EXPECT_FALSE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_FALSE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
- player_impl_->GetAnimationById(3)->SetRunState(Animation::FINISHED,
+ ticker_impl_->GetAnimationById(3)->SetRunState(Animation::FINISHED,
TicksFromSecondsF(0.0));
- player_impl_->GetAnimationById(2)->SetRunState(Animation::FINISHED,
+ ticker_impl_->GetAnimationById(2)->SetRunState(Animation::FINISHED,
TicksFromSecondsF(0.0));
// Only unfinished animations should be considered by
// MaximumTargetScale.
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_EQ(4.f, max_scale);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
EXPECT_EQ(4.f, max_scale);
}
@@ -2409,37 +2327,37 @@ TEST_F(ElementAnimationsTest, MaximumTargetScaleWithDirection) {
// NORMAL direction with positive playback rate.
animation->set_direction(Animation::Direction::NORMAL);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_EQ(6.f, max_scale);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
EXPECT_EQ(6.f, max_scale);
// ALTERNATE direction with positive playback rate.
animation->set_direction(Animation::Direction::ALTERNATE_NORMAL);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_EQ(6.f, max_scale);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
EXPECT_EQ(6.f, max_scale);
// REVERSE direction with positive playback rate.
animation->set_direction(Animation::Direction::REVERSE);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_EQ(3.f, max_scale);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
EXPECT_EQ(3.f, max_scale);
// ALTERNATE reverse direction.
animation->set_direction(Animation::Direction::REVERSE);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_EQ(3.f, max_scale);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
EXPECT_EQ(3.f, max_scale);
animation->set_playback_rate(-1.0);
@@ -2447,37 +2365,37 @@ TEST_F(ElementAnimationsTest, MaximumTargetScaleWithDirection) {
// NORMAL direction with negative playback rate.
animation->set_direction(Animation::Direction::NORMAL);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_EQ(3.f, max_scale);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
EXPECT_EQ(3.f, max_scale);
// ALTERNATE direction with negative playback rate.
animation->set_direction(Animation::Direction::ALTERNATE_NORMAL);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_EQ(3.f, max_scale);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
EXPECT_EQ(3.f, max_scale);
// REVERSE direction with negative playback rate.
animation->set_direction(Animation::Direction::REVERSE);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_EQ(6.f, max_scale);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
EXPECT_EQ(6.f, max_scale);
// ALTERNATE reverse direction with negative playback rate.
animation->set_direction(Animation::Direction::REVERSE);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::PENDING, &max_scale));
EXPECT_EQ(6.f, max_scale);
EXPECT_TRUE(
- player_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
+ ticker_impl_->MaximumTargetScale(ElementListType::ACTIVE, &max_scale));
EXPECT_EQ(6.f, max_scale);
}
@@ -2488,31 +2406,30 @@ TEST_F(ElementAnimationsTest, NewlyPushedAnimationWaitsForActivation) {
auto events = CreateEventsForTesting();
- EXPECT_FALSE(player_->needs_to_start_animations());
int animation_id =
AddOpacityTransitionToPlayer(player_.get(), 1, 0.5f, 1.f, false);
- EXPECT_TRUE(player_->needs_to_start_animations());
+ EXPECT_TRUE(ticker_->GetAnimationById(animation_id));
+ EXPECT_FALSE(ticker_impl_->GetAnimationById(animation_id));
- EXPECT_FALSE(player_impl_->needs_to_start_animations());
PushProperties();
- EXPECT_TRUE(player_impl_->needs_to_start_animations());
- EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
+ EXPECT_TRUE(ticker_impl_->GetAnimationById(animation_id));
EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
- player_impl_->GetAnimationById(animation_id)->run_state());
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
EXPECT_TRUE(
- player_impl_->GetAnimationById(animation_id)->affects_pending_elements());
+ ticker_impl_->GetAnimationById(animation_id)->affects_pending_elements());
EXPECT_FALSE(
- player_impl_->GetAnimationById(animation_id)->affects_active_elements());
+ ticker_impl_->GetAnimationById(animation_id)->affects_active_elements());
player_impl_->Tick(kInitialTickTime);
- EXPECT_FALSE(player_impl_->needs_to_start_animations());
+ EXPECT_EQ(Animation::STARTING,
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
player_impl_->UpdateState(true, events.get());
// Since the animation hasn't been activated, it should still be STARTING
// rather than RUNNING.
EXPECT_EQ(Animation::STARTING,
- player_impl_->GetAnimationById(animation_id)->run_state());
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
// Since the animation hasn't been activated, only the pending observer
// should have been ticked.
@@ -2522,9 +2439,9 @@ TEST_F(ElementAnimationsTest, NewlyPushedAnimationWaitsForActivation) {
player_impl_->ActivateAnimations();
EXPECT_TRUE(
- player_impl_->GetAnimationById(animation_id)->affects_pending_elements());
+ ticker_impl_->GetAnimationById(animation_id)->affects_pending_elements());
EXPECT_TRUE(
- player_impl_->GetAnimationById(animation_id)->affects_active_elements());
+ ticker_impl_->GetAnimationById(animation_id)->affects_active_elements());
player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
player_impl_->UpdateState(true, events.get());
@@ -2532,7 +2449,7 @@ TEST_F(ElementAnimationsTest, NewlyPushedAnimationWaitsForActivation) {
// Since the animation has been activated, it should have reached the
// RUNNING state and the active observer should start to get ticked.
EXPECT_EQ(Animation::RUNNING,
- player_impl_->GetAnimationById(animation_id)->run_state());
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
EXPECT_EQ(0.5f,
client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
EXPECT_EQ(0.5f,
@@ -2551,13 +2468,13 @@ TEST_F(ElementAnimationsTest, ActivationBetweenAnimateAndUpdateState) {
PushProperties();
- EXPECT_TRUE(player_impl_->GetAnimationById(animation_id));
+ EXPECT_TRUE(ticker_impl_->GetAnimationById(animation_id));
EXPECT_EQ(Animation::WAITING_FOR_TARGET_AVAILABILITY,
- player_impl_->GetAnimationById(animation_id)->run_state());
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
EXPECT_TRUE(
- player_impl_->GetAnimationById(animation_id)->affects_pending_elements());
+ ticker_impl_->GetAnimationById(animation_id)->affects_pending_elements());
EXPECT_FALSE(
- player_impl_->GetAnimationById(animation_id)->affects_active_elements());
+ ticker_impl_->GetAnimationById(animation_id)->affects_active_elements());
player_impl_->Tick(kInitialTickTime);
@@ -2569,16 +2486,16 @@ TEST_F(ElementAnimationsTest, ActivationBetweenAnimateAndUpdateState) {
player_impl_->ActivateAnimations();
EXPECT_TRUE(
- player_impl_->GetAnimationById(animation_id)->affects_pending_elements());
+ ticker_impl_->GetAnimationById(animation_id)->affects_pending_elements());
EXPECT_TRUE(
- player_impl_->GetAnimationById(animation_id)->affects_active_elements());
+ ticker_impl_->GetAnimationById(animation_id)->affects_active_elements());
player_impl_->UpdateState(true, events.get());
// Since the animation has been activated, it should have reached the
// RUNNING state.
EXPECT_EQ(Animation::RUNNING,
- player_impl_->GetAnimationById(animation_id)->run_state());
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(500));
@@ -2639,7 +2556,7 @@ TEST_F(ElementAnimationsTest, ObserverNotifiedWhenTransformAnimationChanges) {
player_impl_->Tick(kInitialTickTime);
player_impl_->UpdateState(true, events.get());
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
events->events_.clear();
// Finish the animation.
@@ -2677,9 +2594,9 @@ TEST_F(ElementAnimationsTest, ObserverNotifiedWhenTransformAnimationChanges) {
// Case 2: An animation that's removed before it finishes.
int animation_id = AddAnimatedTransformToPlayer(player_.get(), 10.0, 2, 2);
int animation2_id = AddAnimatedTransformToPlayer(player_.get(), 10.0, 2, 1);
- player_->GetAnimationById(animation2_id)
+ ticker_->GetAnimationById(animation2_id)
->set_time_offset(base::TimeDelta::FromMilliseconds(-10000));
- player_->GetAnimationById(animation2_id)
+ ticker_->GetAnimationById(animation2_id)
->set_fill_mode(Animation::FillMode::NONE);
EXPECT_TRUE(client_.GetHasPotentialTransformAnimation(
element_id_, ElementListType::ACTIVE));
@@ -2708,7 +2625,7 @@ TEST_F(ElementAnimationsTest, ObserverNotifiedWhenTransformAnimationChanges) {
player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
player_impl_->UpdateState(true, events.get());
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
events->events_.clear();
player_->RemoveAnimation(animation_id);
@@ -2760,7 +2677,7 @@ TEST_F(ElementAnimationsTest, ObserverNotifiedWhenTransformAnimationChanges) {
player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
player_impl_->UpdateState(true, events.get());
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
events->events_.clear();
player_impl_->AbortAnimations(TargetProperty::TRANSFORM, false);
@@ -2784,9 +2701,9 @@ TEST_F(ElementAnimationsTest, ObserverNotifiedWhenTransformAnimationChanges) {
// Case 4 : An animation that's not in effect.
animation_id = AddAnimatedTransformToPlayer(player_.get(), 1.0, 1, 6);
- player_->GetAnimationById(animation_id)
+ ticker_->GetAnimationById(animation_id)
->set_time_offset(base::TimeDelta::FromMilliseconds(-10000));
- player_->GetAnimationById(animation_id)
+ ticker_->GetAnimationById(animation_id)
->set_fill_mode(Animation::FillMode::NONE);
PushProperties();
@@ -2857,7 +2774,7 @@ TEST_F(ElementAnimationsTest, ObserverNotifiedWhenOpacityAnimationChanges) {
player_impl_->Tick(kInitialTickTime);
player_impl_->UpdateState(true, events.get());
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
events->events_.clear();
// Finish the animation.
@@ -2919,7 +2836,7 @@ TEST_F(ElementAnimationsTest, ObserverNotifiedWhenOpacityAnimationChanges) {
player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
player_impl_->UpdateState(true, events.get());
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
events->events_.clear();
player_->RemoveAnimation(animation_id);
@@ -2971,7 +2888,7 @@ TEST_F(ElementAnimationsTest, ObserverNotifiedWhenOpacityAnimationChanges) {
player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
player_impl_->UpdateState(true, events.get());
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
events->events_.clear();
player_impl_->AbortAnimations(TargetProperty::OPACITY, false);
@@ -2996,9 +2913,9 @@ TEST_F(ElementAnimationsTest, ObserverNotifiedWhenOpacityAnimationChanges) {
// Case 4 : An animation that's not in effect.
animation_id = AddOpacityTransitionToPlayer(player_.get(), 1.0, 0.f, 0.5f,
false /*use_timing_function*/);
- player_->GetAnimationById(animation_id)
+ ticker_->GetAnimationById(animation_id)
->set_time_offset(base::TimeDelta::FromMilliseconds(-10000));
- player_->GetAnimationById(animation_id)
+ ticker_->GetAnimationById(animation_id)
->set_fill_mode(Animation::FillMode::NONE);
PushProperties();
@@ -3068,7 +2985,7 @@ TEST_F(ElementAnimationsTest, ObserverNotifiedWhenFilterAnimationChanges) {
player_impl_->Tick(kInitialTickTime);
player_impl_->UpdateState(true, events.get());
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
events->events_.clear();
// Finish the animation.
@@ -3129,7 +3046,7 @@ TEST_F(ElementAnimationsTest, ObserverNotifiedWhenFilterAnimationChanges) {
player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
player_impl_->UpdateState(true, events.get());
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
events->events_.clear();
player_->RemoveAnimation(animation_id);
@@ -3180,7 +3097,7 @@ TEST_F(ElementAnimationsTest, ObserverNotifiedWhenFilterAnimationChanges) {
player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
player_impl_->UpdateState(true, events.get());
- player_->NotifyAnimationStarted(events->events_[0]);
+ ticker_->NotifyAnimationStarted(events->events_[0]);
events->events_.clear();
player_impl_->AbortAnimations(TargetProperty::FILTER, false);
@@ -3204,9 +3121,9 @@ TEST_F(ElementAnimationsTest, ObserverNotifiedWhenFilterAnimationChanges) {
// Case 4 : An animation that's not in effect.
animation_id = AddAnimatedFilterToPlayer(player_.get(), 1.0, 0.f, 0.5f);
- player_->GetAnimationById(animation_id)
+ ticker_->GetAnimationById(animation_id)
->set_time_offset(base::TimeDelta::FromMilliseconds(-10000));
- player_->GetAnimationById(animation_id)
+ ticker_->GetAnimationById(animation_id)
->set_fill_mode(Animation::FillMode::NONE);
PushProperties();
@@ -3268,16 +3185,16 @@ TEST_F(ElementAnimationsTest, PushedDeletedAnimationWaitsForActivation) {
player_impl_->Tick(kInitialTickTime);
player_impl_->UpdateState(true, events.get());
EXPECT_EQ(Animation::RUNNING,
- player_impl_->GetAnimationById(animation_id)->run_state());
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
EXPECT_EQ(0.5f,
client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
EXPECT_EQ(0.5f,
client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
EXPECT_TRUE(
- player_impl_->GetAnimationById(animation_id)->affects_pending_elements());
+ ticker_impl_->GetAnimationById(animation_id)->affects_pending_elements());
EXPECT_TRUE(
- player_impl_->GetAnimationById(animation_id)->affects_active_elements());
+ ticker_impl_->GetAnimationById(animation_id)->affects_active_elements());
// Delete the animation on the main-thread animations.
player_->RemoveAnimation(
@@ -3286,9 +3203,9 @@ TEST_F(ElementAnimationsTest, PushedDeletedAnimationWaitsForActivation) {
// The animation should no longer affect pending elements.
EXPECT_FALSE(
- player_impl_->GetAnimationById(animation_id)->affects_pending_elements());
+ ticker_impl_->GetAnimationById(animation_id)->affects_pending_elements());
EXPECT_TRUE(
- player_impl_->GetAnimationById(animation_id)->affects_active_elements());
+ ticker_impl_->GetAnimationById(animation_id)->affects_active_elements());
player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(500));
player_impl_->UpdateState(true, events.get());
@@ -3307,14 +3224,14 @@ TEST_F(ElementAnimationsTest, PushedDeletedAnimationWaitsForActivation) {
// thread. UpdateState for this animation would put the animation to wait for
// deletion state.
EXPECT_EQ(Animation::WAITING_FOR_DELETION,
- player_impl_->GetAnimationById(animation_id)->run_state());
+ ticker_impl_->GetAnimationById(animation_id)->run_state());
EXPECT_EQ(1u, events->events_.size());
// The animation is finished on impl thread, and main thread will delete it
// during commit.
player_->animation_host()->SetAnimationEvents(std::move(events));
PushProperties();
- EXPECT_FALSE(player_impl_->has_any_animation());
+ EXPECT_FALSE(ticker_impl_->has_any_animation());
}
// Tests that an animation that affects only active elements won't block
@@ -3344,13 +3261,13 @@ TEST_F(ElementAnimationsTest, StartAnimationsAffectingDifferentObservers) {
// The original animation should only affect active elements, and the new
// animation should only affect pending elements.
- EXPECT_FALSE(player_impl_->GetAnimationById(first_animation_id)
+ EXPECT_FALSE(ticker_impl_->GetAnimationById(first_animation_id)
->affects_pending_elements());
- EXPECT_TRUE(player_impl_->GetAnimationById(first_animation_id)
+ EXPECT_TRUE(ticker_impl_->GetAnimationById(first_animation_id)
->affects_active_elements());
- EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id)
+ EXPECT_TRUE(ticker_impl_->GetAnimationById(second_animation_id)
->affects_pending_elements());
- EXPECT_FALSE(player_impl_->GetAnimationById(second_animation_id)
+ EXPECT_FALSE(ticker_impl_->GetAnimationById(second_animation_id)
->affects_active_elements());
player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(500));
@@ -3359,9 +3276,9 @@ TEST_F(ElementAnimationsTest, StartAnimationsAffectingDifferentObservers) {
// The original animation should still be running, and the new animation
// should be starting.
EXPECT_EQ(Animation::RUNNING,
- player_impl_->GetAnimationById(first_animation_id)->run_state());
+ ticker_impl_->GetAnimationById(first_animation_id)->run_state());
EXPECT_EQ(Animation::STARTING,
- player_impl_->GetAnimationById(second_animation_id)->run_state());
+ ticker_impl_->GetAnimationById(second_animation_id)->run_state());
// The active observer should have been ticked by the original animation,
// and the pending observer should have been ticked by the new animation.
@@ -3374,13 +3291,13 @@ TEST_F(ElementAnimationsTest, StartAnimationsAffectingDifferentObservers) {
// The original animation no longer affect either elements, and the new
// animation should now affect both elements.
- EXPECT_FALSE(player_impl_->GetAnimationById(first_animation_id)
+ EXPECT_FALSE(ticker_impl_->GetAnimationById(first_animation_id)
->affects_pending_elements());
- EXPECT_FALSE(player_impl_->GetAnimationById(first_animation_id)
+ EXPECT_FALSE(ticker_impl_->GetAnimationById(first_animation_id)
->affects_active_elements());
- EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id)
+ EXPECT_TRUE(ticker_impl_->GetAnimationById(second_animation_id)
->affects_pending_elements());
- EXPECT_TRUE(player_impl_->GetAnimationById(second_animation_id)
+ EXPECT_TRUE(ticker_impl_->GetAnimationById(second_animation_id)
->affects_active_elements());
player_impl_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1000));
@@ -3388,12 +3305,12 @@ TEST_F(ElementAnimationsTest, StartAnimationsAffectingDifferentObservers) {
// The original animation should be marked for waiting for deletion.
EXPECT_EQ(Animation::WAITING_FOR_DELETION,
- player_impl_->GetAnimationById(first_animation_id)->run_state());
+ ticker_impl_->GetAnimationById(first_animation_id)->run_state());
// The new animation should be running, and the active observer should have
// been ticked at the new animation's starting point.
EXPECT_EQ(Animation::RUNNING,
- player_impl_->GetAnimationById(second_animation_id)->run_state());
+ ticker_impl_->GetAnimationById(second_animation_id)->run_state());
EXPECT_EQ(1.f,
client_impl_.GetOpacity(element_id_, ElementListType::PENDING));
EXPECT_EQ(1.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE));
@@ -3411,43 +3328,43 @@ TEST_F(ElementAnimationsTest, TestIsCurrentlyAnimatingProperty) {
player_->AddAnimation(std::move(animation));
player_->Tick(kInitialTickTime);
- EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_TRUE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::PENDING));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::ACTIVE));
player_->UpdateState(true, nullptr);
- EXPECT_TRUE(player_->HasTickingAnimation());
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
- EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_TRUE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::PENDING));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::ACTIVE));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
ElementListType::PENDING));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
ElementListType::ACTIVE));
player_->ActivateAnimations();
- EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_TRUE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::PENDING));
- EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_TRUE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::ACTIVE));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
ElementListType::PENDING));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
ElementListType::ACTIVE));
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(10));
player_->UpdateState(true, nullptr);
- EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_TRUE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::PENDING));
- EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_TRUE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::ACTIVE));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
ElementListType::PENDING));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
ElementListType::ACTIVE));
EXPECT_EQ(0.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
@@ -3456,13 +3373,13 @@ TEST_F(ElementAnimationsTest, TestIsCurrentlyAnimatingProperty) {
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(1100));
player_->UpdateState(true, nullptr);
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::PENDING));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::ACTIVE));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
ElementListType::PENDING));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::FILTER,
ElementListType::ACTIVE));
EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE));
@@ -3488,34 +3405,34 @@ TEST_F(ElementAnimationsTest, TestIsAnimatingPropertyTimeOffsetFillMode) {
// Since the animation has a start delay, the elements it affects have a
// potentially running transform animation but aren't currently animating
// transform.
- EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty(
+ EXPECT_TRUE(ticker_->IsPotentiallyAnimatingProperty(
TargetProperty::OPACITY, ElementListType::PENDING));
- EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty(
+ EXPECT_FALSE(ticker_->IsPotentiallyAnimatingProperty(
TargetProperty::OPACITY, ElementListType::ACTIVE));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::PENDING));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::ACTIVE));
- EXPECT_TRUE(player_->HasTickingAnimation());
- EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty(
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_->IsPotentiallyAnimatingProperty(
TargetProperty::FILTER, ElementListType::PENDING));
- EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty(
+ EXPECT_FALSE(ticker_->IsPotentiallyAnimatingProperty(
TargetProperty::FILTER, ElementListType::ACTIVE));
player_->ActivateAnimations();
- EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty(
+ EXPECT_TRUE(ticker_->IsPotentiallyAnimatingProperty(
TargetProperty::OPACITY, ElementListType::PENDING));
- EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_TRUE(ticker_->IsPotentiallyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::ACTIVE));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::PENDING));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::ACTIVE));
- EXPECT_TRUE(player_->HasTickingAnimation());
- EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty(
+ EXPECT_TRUE(ticker_->HasTickingAnimation());
+ EXPECT_FALSE(ticker_->IsPotentiallyAnimatingProperty(
TargetProperty::FILTER, ElementListType::PENDING));
- EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty(
+ EXPECT_FALSE(ticker_->IsPotentiallyAnimatingProperty(
TargetProperty::FILTER, ElementListType::ACTIVE));
player_->UpdateState(true, nullptr);
@@ -3523,13 +3440,13 @@ TEST_F(ElementAnimationsTest, TestIsAnimatingPropertyTimeOffsetFillMode) {
// Tick past the start delay.
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(2000));
player_->UpdateState(true, nullptr);
- EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty(
+ EXPECT_TRUE(ticker_->IsPotentiallyAnimatingProperty(
TargetProperty::OPACITY, ElementListType::PENDING));
- EXPECT_TRUE(player_->IsPotentiallyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_TRUE(ticker_->IsPotentiallyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::ACTIVE));
- EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_TRUE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::PENDING));
- EXPECT_TRUE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_TRUE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::ACTIVE));
// After the animaton finishes, the elements it affects have neither a
@@ -3537,13 +3454,13 @@ TEST_F(ElementAnimationsTest, TestIsAnimatingPropertyTimeOffsetFillMode) {
// animation.
player_->Tick(kInitialTickTime + TimeDelta::FromMilliseconds(4000));
player_->UpdateState(true, nullptr);
- EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty(
+ EXPECT_FALSE(ticker_->IsPotentiallyAnimatingProperty(
TargetProperty::OPACITY, ElementListType::PENDING));
- EXPECT_FALSE(player_->IsPotentiallyAnimatingProperty(
+ EXPECT_FALSE(ticker_->IsPotentiallyAnimatingProperty(
TargetProperty::OPACITY, ElementListType::ACTIVE));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::PENDING));
- EXPECT_FALSE(player_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
+ EXPECT_FALSE(ticker_->IsCurrentlyAnimatingProperty(TargetProperty::OPACITY,
ElementListType::ACTIVE));
}
@@ -3576,7 +3493,7 @@ TEST_F(ElementAnimationsTest, RemoveAndReAddPlayerToTicking) {
std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 1.f, 0.5f)),
2, TargetProperty::OPACITY));
ASSERT_EQ(1u, host_->ticking_players_for_testing().size());
- player_->RemoveFromTicking();
+ ticker_->RemoveFromTicking();
ASSERT_EQ(0u, host_->ticking_players_for_testing().size());
// Ensure that adding a new animation will correctly update the ticking
diff --git a/chromium/cc/animation/keyframed_animation_curve.cc b/chromium/cc/animation/keyframed_animation_curve.cc
index 57e2b36932b..ab620f99b30 100644
--- a/chromium/cc/animation/keyframed_animation_curve.cc
+++ b/chromium/cc/animation/keyframed_animation_curve.cc
@@ -250,8 +250,8 @@ base::TimeDelta KeyframedColorAnimationCurve::Duration() const {
std::unique_ptr<AnimationCurve> KeyframedColorAnimationCurve::Clone() const {
std::unique_ptr<KeyframedColorAnimationCurve> to_return =
KeyframedColorAnimationCurve::Create();
- for (size_t i = 0; i < keyframes_.size(); ++i)
- to_return->AddKeyframe(keyframes_[i]->Clone());
+ for (const auto& keyframe : keyframes_)
+ to_return->AddKeyframe(keyframe->Clone());
if (timing_function_)
to_return->SetTimingFunction(timing_function_->Clone());
@@ -301,8 +301,8 @@ base::TimeDelta KeyframedFloatAnimationCurve::Duration() const {
std::unique_ptr<AnimationCurve> KeyframedFloatAnimationCurve::Clone() const {
std::unique_ptr<KeyframedFloatAnimationCurve> to_return =
KeyframedFloatAnimationCurve::Create();
- for (size_t i = 0; i < keyframes_.size(); ++i)
- to_return->AddKeyframe(keyframes_[i]->Clone());
+ for (const auto& keyframe : keyframes_)
+ to_return->AddKeyframe(keyframe->Clone());
if (timing_function_)
to_return->SetTimingFunction(timing_function_->Clone());
@@ -353,8 +353,8 @@ std::unique_ptr<AnimationCurve> KeyframedTransformAnimationCurve::Clone()
const {
std::unique_ptr<KeyframedTransformAnimationCurve> to_return =
KeyframedTransformAnimationCurve::Create();
- for (size_t i = 0; i < keyframes_.size(); ++i)
- to_return->AddKeyframe(keyframes_[i]->Clone());
+ for (const auto& keyframe : keyframes_)
+ to_return->AddKeyframe(keyframe->Clone());
if (timing_function_)
to_return->SetTimingFunction(timing_function_->Clone());
@@ -404,21 +404,21 @@ bool KeyframedTransformAnimationCurve::AnimatedBoundsForBox(
}
bool KeyframedTransformAnimationCurve::PreservesAxisAlignment() const {
- for (size_t i = 0; i < keyframes_.size(); ++i) {
- if (!keyframes_[i]->Value().PreservesAxisAlignment())
+ for (const auto& keyframe : keyframes_) {
+ if (!keyframe->Value().PreservesAxisAlignment())
return false;
}
return true;
}
bool KeyframedTransformAnimationCurve::IsTranslation() const {
- for (size_t i = 0; i < keyframes_.size(); ++i) {
- if (!keyframes_[i]->Value().IsTranslation() &&
- !keyframes_[i]->Value().IsIdentity())
+ for (const auto& keyframe : keyframes_) {
+ if (!keyframe->Value().IsTranslation() && !keyframe->Value().IsIdentity())
return false;
}
return true;
}
+
bool KeyframedTransformAnimationCurve::AnimationStartScale(
bool forward_direction,
float* start_scale) const {
@@ -479,8 +479,8 @@ base::TimeDelta KeyframedFilterAnimationCurve::Duration() const {
std::unique_ptr<AnimationCurve> KeyframedFilterAnimationCurve::Clone() const {
std::unique_ptr<KeyframedFilterAnimationCurve> to_return =
KeyframedFilterAnimationCurve::Create();
- for (size_t i = 0; i < keyframes_.size(); ++i)
- to_return->AddKeyframe(keyframes_[i]->Clone());
+ for (const auto& keyframe : keyframes_)
+ to_return->AddKeyframe(keyframe->Clone());
if (timing_function_)
to_return->SetTimingFunction(timing_function_->Clone());
@@ -508,8 +508,8 @@ FilterOperations KeyframedFilterAnimationCurve::GetValue(
}
bool KeyframedFilterAnimationCurve::HasFilterThatMovesPixels() const {
- for (size_t i = 0; i < keyframes_.size(); ++i) {
- if (keyframes_[i]->Value().HasFilterThatMovesPixels()) {
+ for (const auto& keyframe : keyframes_) {
+ if (keyframe->Value().HasFilterThatMovesPixels()) {
return true;
}
}
@@ -539,8 +539,8 @@ base::TimeDelta KeyframedSizeAnimationCurve::Duration() const {
std::unique_ptr<AnimationCurve> KeyframedSizeAnimationCurve::Clone() const {
std::unique_ptr<KeyframedSizeAnimationCurve> to_return =
KeyframedSizeAnimationCurve::Create();
- for (size_t i = 0; i < keyframes_.size(); ++i)
- to_return->AddKeyframe(keyframes_[i]->Clone());
+ for (const auto& keyframe : keyframes_)
+ to_return->AddKeyframe(keyframe->Clone());
if (timing_function_)
to_return->SetTimingFunction(timing_function_->Clone());
diff --git a/chromium/cc/animation/timing_function.cc b/chromium/cc/animation/timing_function.cc
index 0271c57bb44..e0c7577c2ec 100644
--- a/chromium/cc/animation/timing_function.cc
+++ b/chromium/cc/animation/timing_function.cc
@@ -4,11 +4,11 @@
#include "cc/animation/timing_function.h"
+#include <cmath>
#include <memory>
#include "base/logging.h"
#include "base/memory/ptr_util.h"
-#include "cc/base/math_util.h"
namespace cc {
diff --git a/chromium/cc/animation/transform_operation.cc b/chromium/cc/animation/transform_operation.cc
index 689d3598a58..8f792c92ab6 100644
--- a/chromium/cc/animation/transform_operation.cc
+++ b/chromium/cc/animation/transform_operation.cc
@@ -2,19 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Needed on Windows to get |M_PI| from <cmath>
-#ifdef _WIN32
-#define _USE_MATH_DEFINES
-#endif
-
#include <algorithm>
-#include <cmath>
#include <limits>
#include "base/logging.h"
+#include "base/numerics/math_constants.h"
+#include "base/numerics/ranges.h"
#include "cc/animation/transform_operation.h"
#include "cc/animation/transform_operations.h"
-#include "cc/base/math_util.h"
+#include "ui/gfx/geometry/angle_conversions.h"
#include "ui/gfx/geometry/box_f.h"
#include "ui/gfx/geometry/vector3d_f.h"
#include "ui/gfx/transform_util.h"
@@ -72,7 +68,7 @@ static bool ShareSameAxis(const TransformOperation* from,
to->rotate.axis.y * from->rotate.axis.y +
to->rotate.axis.z * from->rotate.axis.z;
SkMScalar error =
- std::abs(SK_MScalar1 - (dot * dot) / (length_2 * other_length_2));
+ SkMScalarAbs(SK_MScalar1 - (dot * dot) / (length_2 * other_length_2));
bool result = error < kAngleEpsilon;
if (result) {
*axis_x = to->rotate.axis.x;
@@ -124,31 +120,31 @@ bool TransformOperation::ApproximatelyEqual(const TransformOperation& other,
return false;
switch (type) {
case TransformOperation::TRANSFORM_OPERATION_TRANSLATE:
- return MathUtil::ApproximatelyEqual(translate.x, other.translate.x,
- tolerance) &&
- MathUtil::ApproximatelyEqual(translate.y, other.translate.y,
- tolerance) &&
- MathUtil::ApproximatelyEqual(translate.z, other.translate.z,
- tolerance);
+ return base::IsApproximatelyEqual(translate.x, other.translate.x,
+ tolerance) &&
+ base::IsApproximatelyEqual(translate.y, other.translate.y,
+ tolerance) &&
+ base::IsApproximatelyEqual(translate.z, other.translate.z,
+ tolerance);
case TransformOperation::TRANSFORM_OPERATION_ROTATE:
- return MathUtil::ApproximatelyEqual(rotate.axis.x, other.rotate.axis.x,
- tolerance) &&
- MathUtil::ApproximatelyEqual(rotate.axis.y, other.rotate.axis.y,
- tolerance) &&
- MathUtil::ApproximatelyEqual(rotate.axis.z, other.rotate.axis.z,
- tolerance) &&
- MathUtil::ApproximatelyEqual(rotate.angle, other.rotate.angle,
- tolerance);
+ return base::IsApproximatelyEqual(rotate.axis.x, other.rotate.axis.x,
+ tolerance) &&
+ base::IsApproximatelyEqual(rotate.axis.y, other.rotate.axis.y,
+ tolerance) &&
+ base::IsApproximatelyEqual(rotate.axis.z, other.rotate.axis.z,
+ tolerance) &&
+ base::IsApproximatelyEqual(rotate.angle, other.rotate.angle,
+ tolerance);
case TransformOperation::TRANSFORM_OPERATION_SCALE:
- return MathUtil::ApproximatelyEqual(scale.x, other.scale.x, tolerance) &&
- MathUtil::ApproximatelyEqual(scale.y, other.scale.y, tolerance) &&
- MathUtil::ApproximatelyEqual(scale.z, other.scale.z, tolerance);
+ return base::IsApproximatelyEqual(scale.x, other.scale.x, tolerance) &&
+ base::IsApproximatelyEqual(scale.y, other.scale.y, tolerance) &&
+ base::IsApproximatelyEqual(scale.z, other.scale.z, tolerance);
case TransformOperation::TRANSFORM_OPERATION_SKEW:
- return MathUtil::ApproximatelyEqual(skew.x, other.skew.x, tolerance) &&
- MathUtil::ApproximatelyEqual(skew.y, other.skew.y, tolerance);
+ return base::IsApproximatelyEqual(skew.x, other.skew.x, tolerance) &&
+ base::IsApproximatelyEqual(skew.y, other.skew.y, tolerance);
case TransformOperation::TRANSFORM_OPERATION_PERSPECTIVE:
- return MathUtil::ApproximatelyEqual(perspective_depth,
- other.perspective_depth, tolerance);
+ return base::IsApproximatelyEqual(perspective_depth,
+ other.perspective_depth, tolerance);
case TransformOperation::TRANSFORM_OPERATION_MATRIX:
// TODO(vollick): we could expose a tolerance on gfx::Transform, but it's
// complex since we need a different tolerance per component. Driving this
@@ -293,21 +289,13 @@ static void FindCandidatesInPlane(float px,
*num_candidates = 4;
candidates[0] = phi;
for (int i = 1; i < *num_candidates; ++i)
- candidates[i] = candidates[i - 1] + M_PI_2;
+ candidates[i] = candidates[i - 1] + base::kPiDouble / 2;
if (nz < 0.f) {
for (int i = 0; i < *num_candidates; ++i)
candidates[i] *= -1.f;
}
}
-static float RadiansToDegrees(float radians) {
- return (180.f * radians) / M_PI;
-}
-
-static float DegreesToRadians(float degrees) {
- return (M_PI * degrees) / 180.f;
-}
-
static void BoundingBoxForArc(const gfx::Point3F& point,
const TransformOperation* from,
const TransformOperation* to,
@@ -411,29 +399,29 @@ static void BoundingBoxForArc(const gfx::Point3F& point,
// maximum/minimum x, y, z values.
// x'(t) = r*cos(t)*v2.x - r*sin(t)*v1.x = 0
// tan(t) = v2.x/v1.x
- // t = atan2(v2.x, v1.x) + n*M_PI;
+ // t = atan2(v2.x, v1.x) + n*pi;
candidates[0] = atan2(v2.x(), v1.x());
- candidates[1] = candidates[0] + M_PI;
+ candidates[1] = candidates[0] + base::kPiDouble;
candidates[2] = atan2(v2.y(), v1.y());
- candidates[3] = candidates[2] + M_PI;
+ candidates[3] = candidates[2] + base::kPiDouble;
candidates[4] = atan2(v2.z(), v1.z());
- candidates[5] = candidates[4] + M_PI;
+ candidates[5] = candidates[4] + base::kPiDouble;
}
- double min_radians = DegreesToRadians(min_degrees);
- double max_radians = DegreesToRadians(max_degrees);
+ double min_radians = gfx::DegToRad(min_degrees);
+ double max_radians = gfx::DegToRad(max_degrees);
for (int i = 0; i < num_candidates; ++i) {
double radians = candidates[i];
while (radians < min_radians)
- radians += 2.0 * M_PI;
+ radians += 2.0 * base::kPiDouble;
while (radians > max_radians)
- radians -= 2.0 * M_PI;
+ radians -= 2.0 * base::kPiDouble;
if (radians < min_radians)
continue;
gfx::Transform rotation;
- rotation.RotateAbout(axis, RadiansToDegrees(radians));
+ rotation.RotateAbout(axis, gfx::RadToDeg(radians));
gfx::Point3F rotated = point;
rotation.TransformPoint(&rotated);
diff --git a/chromium/cc/animation/transform_operations.cc b/chromium/cc/animation/transform_operations.cc
index 309b4c8adf1..23f90c47ffb 100644
--- a/chromium/cc/animation/transform_operations.cc
+++ b/chromium/cc/animation/transform_operations.cc
@@ -2,11 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Needed on Windows to get |M_PI| from <cmath>
-#ifdef _WIN32
-#define _USE_MATH_DEFINES
-#endif
-
#include "cc/animation/transform_operations.h"
#include <stddef.h>
@@ -15,6 +10,7 @@
#include "cc/base/math_util.h"
#include "ui/gfx/animation/tween.h"
+#include "ui/gfx/geometry/angle_conversions.h"
#include "ui/gfx/geometry/box_f.h"
#include "ui/gfx/geometry/vector3d_f.h"
#include "ui/gfx/transform_util.h"
@@ -50,8 +46,8 @@ TransformOperations& TransformOperations::operator=(
gfx::Transform TransformOperations::Apply() const {
gfx::Transform to_return;
- for (size_t i = 0; i < operations_.size(); ++i)
- to_return.PreconcatTransform(operations_[i].matrix);
+ for (auto& operation : operations_)
+ to_return.PreconcatTransform(operation.matrix);
return to_return;
}
@@ -102,15 +98,15 @@ bool TransformOperations::BlendedBoundsForBox(const gfx::BoxF& box,
}
bool TransformOperations::PreservesAxisAlignment() const {
- for (size_t i = 0; i < operations_.size(); ++i) {
- switch (operations_[i].type) {
+ for (auto& operation : operations_) {
+ switch (operation.type) {
case TransformOperation::TRANSFORM_OPERATION_IDENTITY:
case TransformOperation::TRANSFORM_OPERATION_TRANSLATE:
case TransformOperation::TRANSFORM_OPERATION_SCALE:
continue;
case TransformOperation::TRANSFORM_OPERATION_MATRIX:
- if (!operations_[i].matrix.IsIdentity() &&
- !operations_[i].matrix.IsScaleOrTranslation())
+ if (!operation.matrix.IsIdentity() &&
+ !operation.matrix.IsScaleOrTranslation())
return false;
continue;
case TransformOperation::TRANSFORM_OPERATION_ROTATE:
@@ -123,13 +119,13 @@ bool TransformOperations::PreservesAxisAlignment() const {
}
bool TransformOperations::IsTranslation() const {
- for (size_t i = 0; i < operations_.size(); ++i) {
- switch (operations_[i].type) {
+ for (auto& operation : operations_) {
+ switch (operation.type) {
case TransformOperation::TRANSFORM_OPERATION_IDENTITY:
case TransformOperation::TRANSFORM_OPERATION_TRANSLATE:
continue;
case TransformOperation::TRANSFORM_OPERATION_MATRIX:
- if (!operations_[i].matrix.IsIdentityOrTranslation())
+ if (!operation.matrix.IsIdentityOrTranslation())
return false;
continue;
case TransformOperation::TRANSFORM_OPERATION_ROTATE:
@@ -143,31 +139,29 @@ bool TransformOperations::IsTranslation() const {
}
static SkMScalar TanDegrees(double degrees) {
- double radians = degrees * M_PI / 180;
- return SkDoubleToMScalar(std::tan(radians));
+ return SkDoubleToMScalar(std::tan(gfx::DegToRad(degrees)));
}
bool TransformOperations::ScaleComponent(SkMScalar* scale) const {
SkMScalar operations_scale = 1.f;
- for (size_t i = 0; i < operations_.size(); ++i) {
- switch (operations_[i].type) {
+ for (auto& operation : operations_) {
+ switch (operation.type) {
case TransformOperation::TRANSFORM_OPERATION_IDENTITY:
case TransformOperation::TRANSFORM_OPERATION_TRANSLATE:
case TransformOperation::TRANSFORM_OPERATION_ROTATE:
continue;
case TransformOperation::TRANSFORM_OPERATION_MATRIX: {
- if (operations_[i].matrix.HasPerspective())
+ if (operation.matrix.HasPerspective())
return false;
gfx::Vector2dF scale_components =
- MathUtil::ComputeTransform2dScaleComponents(operations_[i].matrix,
- 1.f);
+ MathUtil::ComputeTransform2dScaleComponents(operation.matrix, 1.f);
operations_scale *=
std::max(scale_components.x(), scale_components.y());
break;
}
case TransformOperation::TRANSFORM_OPERATION_SKEW: {
- SkMScalar x_component = TanDegrees(operations_[i].skew.x);
- SkMScalar y_component = TanDegrees(operations_[i].skew.y);
+ SkMScalar x_component = TanDegrees(operation.skew.x);
+ SkMScalar y_component = TanDegrees(operation.skew.y);
SkMScalar x_scale = std::sqrt(x_component * x_component + 1);
SkMScalar y_scale = std::sqrt(y_component * y_component + 1);
operations_scale *= std::max(x_scale, y_scale);
@@ -176,10 +170,9 @@ bool TransformOperations::ScaleComponent(SkMScalar* scale) const {
case TransformOperation::TRANSFORM_OPERATION_PERSPECTIVE:
return false;
case TransformOperation::TRANSFORM_OPERATION_SCALE:
- operations_scale *=
- std::max(std::abs(operations_[i].scale.x),
- std::max(std::abs(operations_[i].scale.y),
- std::abs(operations_[i].scale.z)));
+ operations_scale *= std::max(
+ std::abs(operation.scale.x),
+ std::max(std::abs(operation.scale.y), std::abs(operation.scale.z)));
}
}
*scale = operations_scale;
@@ -282,8 +275,8 @@ void TransformOperations::Append(const TransformOperation& operation) {
}
bool TransformOperations::IsIdentity() const {
- for (size_t i = 0; i < operations_.size(); ++i) {
- if (!operations_[i].IsIdentity())
+ for (auto& operation : operations_) {
+ if (!operation.IsIdentity())
return false;
}
return true;
diff --git a/chromium/cc/base/delayed_unique_notifier_unittest.cc b/chromium/cc/base/delayed_unique_notifier_unittest.cc
index bbd2db5d275..52aba32a68d 100644
--- a/chromium/cc/base/delayed_unique_notifier_unittest.cc
+++ b/chromium/cc/base/delayed_unique_notifier_unittest.cc
@@ -2,13 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <deque>
-
+#include "cc/base/delayed_unique_notifier.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
+#include "base/containers/circular_deque.h"
#include "base/test/test_pending_task.h"
#include "base/test/test_simple_task_runner.h"
-#include "cc/base/delayed_unique_notifier.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
@@ -37,14 +36,14 @@ class DelayedUniqueNotifierTest : public testing::Test {
void SetUp() override {
notification_count_ = 0;
- task_runner_ = make_scoped_refptr(new base::TestSimpleTaskRunner);
+ task_runner_ = base::MakeRefCounted<base::TestSimpleTaskRunner>();
}
void Notify() { ++notification_count_; }
int NotificationCount() const { return notification_count_; }
- std::deque<base::TestPendingTask> TakePendingTasks() {
+ base::circular_deque<base::TestPendingTask> TakePendingTasks() {
return task_runner_->TakePendingTasks();
}
@@ -69,7 +68,7 @@ TEST_F(DelayedUniqueNotifierTest, ZeroDelay) {
notifier.SetNow(schedule_time);
notifier.Schedule();
- std::deque<base::TestPendingTask> tasks = TakePendingTasks();
+ base::circular_deque<base::TestPendingTask> tasks = TakePendingTasks();
ASSERT_EQ(1u, tasks.size());
EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun());
@@ -104,7 +103,7 @@ TEST_F(DelayedUniqueNotifierTest, SmallDelay) {
notifier.SetNow(schedule_time);
notifier.Schedule();
- std::deque<base::TestPendingTask> tasks = TakePendingTasks();
+ base::circular_deque<base::TestPendingTask> tasks = TakePendingTasks();
ASSERT_EQ(1u, tasks.size());
EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun());
@@ -166,7 +165,7 @@ TEST_F(DelayedUniqueNotifierTest, RescheduleDelay) {
notifier.SetNow(schedule_time);
notifier.Schedule();
- std::deque<base::TestPendingTask> tasks = TakePendingTasks();
+ base::circular_deque<base::TestPendingTask> tasks = TakePendingTasks();
ASSERT_EQ(1u, tasks.size());
EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun());
@@ -180,7 +179,7 @@ TEST_F(DelayedUniqueNotifierTest, RescheduleDelay) {
schedule_time = notifier.Now() + base::TimeDelta::FromMicroseconds(20);
notifier.SetNow(schedule_time);
- std::deque<base::TestPendingTask> tasks = TakePendingTasks();
+ base::circular_deque<base::TestPendingTask> tasks = TakePendingTasks();
ASSERT_EQ(1u, tasks.size());
EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun());
@@ -210,7 +209,7 @@ TEST_F(DelayedUniqueNotifierTest, CancelAndHasPendingNotification) {
notifier.Cancel();
EXPECT_FALSE(notifier.HasPendingNotification());
- std::deque<base::TestPendingTask> tasks = TakePendingTasks();
+ base::circular_deque<base::TestPendingTask> tasks = TakePendingTasks();
ASSERT_EQ(1u, tasks.size());
EXPECT_EQ(base::TimeTicks() + delay, tasks[0].GetTimeToRun());
@@ -280,7 +279,7 @@ TEST_F(DelayedUniqueNotifierTest, ShutdownWithScheduledTask) {
notifier.Shutdown();
// The task is still there, but...
- std::deque<base::TestPendingTask> tasks = TakePendingTasks();
+ base::circular_deque<base::TestPendingTask> tasks = TakePendingTasks();
ASSERT_EQ(1u, tasks.size());
// Running the task after shutdown does nothing since it's cancelled.
@@ -320,7 +319,7 @@ TEST_F(DelayedUniqueNotifierTest, ShutdownPreventsSchedule) {
// Scheduling a task no longer does anything.
notifier.Schedule();
- std::deque<base::TestPendingTask> tasks = TakePendingTasks();
+ base::circular_deque<base::TestPendingTask> tasks = TakePendingTasks();
ASSERT_EQ(0u, tasks.size());
// Verify after the scheduled time happens there is still no task.
diff --git a/chromium/cc/base/filter_operation.cc b/chromium/cc/base/filter_operation.cc
index 19afa9b15c6..74cfb7d43ed 100644
--- a/chromium/cc/base/filter_operation.cc
+++ b/chromium/cc/base/filter_operation.cc
@@ -6,6 +6,7 @@
#include <algorithm>
+#include "base/numerics/ranges.h"
#include "base/trace_event/trace_event_argument.h"
#include "base/values.h"
#include "cc/base/filter_operation.h"
@@ -197,7 +198,7 @@ static float ClampAmountForFilterType(float amount,
case FilterOperation::INVERT:
case FilterOperation::OPACITY:
case FilterOperation::ALPHA_THRESHOLD:
- return MathUtil::ClampToRange(amount, 0.f, 1.f);
+ return base::ClampToRange(amount, 0.f, 1.f);
case FilterOperation::SATURATE:
case FilterOperation::BRIGHTNESS:
case FilterOperation::CONTRAST:
diff --git a/chromium/cc/base/filter_operations.cc b/chromium/cc/base/filter_operations.cc
index b9ccb8d0b31..7594861d7ab 100644
--- a/chromium/cc/base/filter_operations.cc
+++ b/chromium/cc/base/filter_operations.cc
@@ -58,11 +58,6 @@ bool FilterOperations::IsEmpty() const {
return operations_.empty();
}
-static int SpreadForStdDeviation(float std_deviation) {
- // Corresponds to MapStdDeviation in filter_operation.cc.
- return std_deviation * 3;
-}
-
gfx::Rect FilterOperations::MapRect(const gfx::Rect& rect,
const SkMatrix& matrix) const {
auto accumulate_rect = [matrix](const gfx::Rect& rect,
@@ -83,43 +78,6 @@ gfx::Rect FilterOperations::MapRectReverse(const gfx::Rect& rect,
accumulate_rect);
}
-void FilterOperations::GetOutsets(int* top,
- int* right,
- int* bottom,
- int* left) const {
- *top = *right = *bottom = *left = 0;
- for (size_t i = 0; i < operations_.size(); ++i) {
- const FilterOperation& op = operations_[i];
- // TODO(hendrikw): We should refactor some of this. See crbug.com/523534.
- if (op.type() == FilterOperation::REFERENCE) {
- if (!op.image_filter())
- continue;
- SkIRect src = SkIRect::MakeWH(0, 0);
- SkIRect dst = op.image_filter()->filterBounds(src, SkMatrix::I());
- *top += std::max(0, -dst.top());
- *right += std::max(0, dst.right());
- *bottom += std::max(0, dst.bottom());
- *left += std::max(0, -dst.left());
- } else {
- if (op.type() == FilterOperation::BLUR ||
- op.type() == FilterOperation::DROP_SHADOW) {
- int spread = SpreadForStdDeviation(op.amount());
- if (op.type() == FilterOperation::BLUR) {
- *top += spread;
- *right += spread;
- *bottom += spread;
- *left += spread;
- } else {
- *top += std::max(0, spread - op.drop_shadow_offset().y());
- *right += std::max(0, spread + op.drop_shadow_offset().x());
- *bottom += std::max(0, spread + op.drop_shadow_offset().y());
- *left += std::max(0, spread - op.drop_shadow_offset().x());
- }
- }
- }
- }
-}
-
bool FilterOperations::HasFilterThatMovesPixels() const {
for (size_t i = 0; i < operations_.size(); ++i) {
const FilterOperation& op = operations_[i];
diff --git a/chromium/cc/base/filter_operations.h b/chromium/cc/base/filter_operations.h
index a7be88d122b..9cff4172265 100644
--- a/chromium/cc/base/filter_operations.h
+++ b/chromium/cc/base/filter_operations.h
@@ -61,7 +61,6 @@ class CC_BASE_EXPORT FilterOperations {
// in the destination rect.
gfx::Rect MapRectReverse(const gfx::Rect& rect, const SkMatrix& matrix) const;
- void GetOutsets(int* top, int* right, int* bottom, int* left) const;
bool HasFilterThatMovesPixels() const;
bool HasFilterThatAffectsOpacity() const;
bool HasReferenceFilter() const;
diff --git a/chromium/cc/base/filter_operations_unittest.cc b/chromium/cc/base/filter_operations_unittest.cc
index 7094a8ee3fa..1316bbec4ea 100644
--- a/chromium/cc/base/filter_operations_unittest.cc
+++ b/chromium/cc/base/filter_operations_unittest.cc
@@ -16,18 +16,6 @@
namespace cc {
namespace {
-TEST(FilterOperationsTest, GetOutsetsBlur) {
- FilterOperations ops;
- ops.Append(FilterOperation::CreateBlurFilter(20));
- int top, right, bottom, left;
- top = right = bottom = left = 0;
- ops.GetOutsets(&top, &right, &bottom, &left);
- EXPECT_EQ(60, top);
- EXPECT_EQ(60, right);
- EXPECT_EQ(60, bottom);
- EXPECT_EQ(60, left);
-}
-
TEST(FilterOperationsTest, MapRectBlur) {
FilterOperations ops;
ops.Append(FilterOperation::CreateBlurFilter(20));
@@ -60,26 +48,6 @@ TEST(FilterOperationsTest, MapRectReverseBlur) {
SkMatrix::MakeScale(1, -1)));
}
-TEST(FilterOperationsTest, GetOutsetsDropShadowReferenceFilter) {
- // TODO(hendrikw): We need to make outsets for reference filters be in line
- // with non-reference filters. See crbug.com/523534
- FilterOperations ops;
- ops.Append(
- FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make(
- SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4),
- SkIntToScalar(9), SK_ColorBLACK,
- SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
- nullptr)));
-
- int top, right, bottom, left;
- top = right = bottom = left = 0;
- ops.GetOutsets(&top, &right, &bottom, &left);
- EXPECT_EQ(35, top);
- EXPECT_EQ(9, right);
- EXPECT_EQ(19, bottom);
- EXPECT_EQ(15, left);
-}
-
TEST(FilterOperationsTest, MapRectDropShadowReferenceFilter) {
FilterOperations ops;
ops.Append(
@@ -179,19 +147,6 @@ TEST(FilterOperationsTest, MapRectReverseCombineNonCommutative) {
SkMatrix::MakeScale(1, -1)));
}
-TEST(FilterOperationsTest, GetOutsetsNullReferenceFilter) {
- FilterOperations ops;
- ops.Append(FilterOperation::CreateReferenceFilter(nullptr));
-
- int top, right, bottom, left;
- top = right = bottom = left = 0;
- ops.GetOutsets(&top, &right, &bottom, &left);
- EXPECT_EQ(0, top);
- EXPECT_EQ(0, right);
- EXPECT_EQ(0, bottom);
- EXPECT_EQ(0, left);
-}
-
TEST(FilterOperationsTest, MapRectNullReferenceFilter) {
FilterOperations ops;
ops.Append(FilterOperation::CreateReferenceFilter(nullptr));
@@ -216,18 +171,6 @@ TEST(FilterOperationsTest, MapRectReverseNullReferenceFilter) {
SkMatrix::MakeScale(1, -1)));
}
-TEST(FilterOperationsTest, GetOutsetsDropShadow) {
- FilterOperations ops;
- ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0));
- int top, right, bottom, left;
- top = right = bottom = left = 0;
- ops.GetOutsets(&top, &right, &bottom, &left);
- EXPECT_EQ(52, top);
- EXPECT_EQ(63, right);
- EXPECT_EQ(68, bottom);
- EXPECT_EQ(57, left);
-}
-
TEST(FilterOperationsTest, MapRectDropShadow) {
FilterOperations ops;
ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0));
@@ -252,20 +195,6 @@ TEST(FilterOperationsTest, MapRectReverseDropShadow) {
SkMatrix::MakeScale(1, -1)));
}
-TEST(FilterOperationsTest, GetOutsetsDropShadowDoesNotContract) {
- // Even with a drop-shadow, the original content is still drawn. Thus the
- // content bounds are never contracted due to a drop-shadow.
- FilterOperations ops;
- ops.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 0, 0));
- int top, right, bottom, left;
- top = right = bottom = left = 0;
- ops.GetOutsets(&top, &right, &bottom, &left);
- EXPECT_EQ(0, top);
- EXPECT_EQ(3, right);
- EXPECT_EQ(8, bottom);
- EXPECT_EQ(0, left);
-}
-
TEST(FilterOperationsTest, MapRectDropShadowDoesNotContract) {
// Even with a drop-shadow, the original content is still drawn. Thus the
// content bounds are never contracted due to a drop-shadow.
diff --git a/chromium/cc/base/math_util.cc b/chromium/cc/base/math_util.cc
index 5f7544c0510..ede2ef124ed 100644
--- a/chromium/cc/base/math_util.cc
+++ b/chromium/cc/base/math_util.cc
@@ -13,6 +13,7 @@
#include "base/trace_event/trace_event_argument.h"
#include "base/values.h"
+#include "ui/gfx/geometry/angle_conversions.h"
#include "ui/gfx/geometry/quad_f.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
@@ -23,9 +24,6 @@
namespace cc {
-const double MathUtil::kPiDouble = 3.14159265358979323846;
-const float MathUtil::kPiFloat = 3.14159265358979323846f;
-
static HomogeneousCoordinate ProjectHomogeneousPoint(
const gfx::Transform& transform,
const gfx::PointF& p) {
@@ -589,9 +587,9 @@ gfx::Vector2dF MathUtil::ComputeTransform2dScaleComponents(
}
float MathUtil::ComputeApproximateMaxScale(const gfx::Transform& transform) {
- gfx::Vector3dF unit(1, 1, 0);
- transform.TransformVector(&unit);
- return std::max(std::abs(unit.x()), std::abs(unit.y()));
+ gfx::RectF unit(0.f, 0.f, 1.f, 1.f);
+ transform.TransformRect(&unit);
+ return std::max(unit.width(), unit.height());
}
float MathUtil::SmallestAngleBetweenVectors(const gfx::Vector2dF& v1,
@@ -599,7 +597,7 @@ float MathUtil::SmallestAngleBetweenVectors(const gfx::Vector2dF& v1,
double dot_product = gfx::DotProduct(v1, v2) / v1.Length() / v2.Length();
// Clamp to compensate for rounding errors.
dot_product = std::max(-1.0, std::min(1.0, dot_product));
- return static_cast<float>(Rad2Deg(std::acos(dot_product)));
+ return static_cast<float>(gfx::RadToDeg(std::acos(dot_product)));
}
gfx::Vector2dF MathUtil::ProjectVector(const gfx::Vector2dF& source,
diff --git a/chromium/cc/base/math_util.h b/chromium/cc/base/math_util.h
index d455b838b4b..240f1642a8c 100644
--- a/chromium/cc/base/math_util.h
+++ b/chromium/cc/base/math_util.h
@@ -5,8 +5,7 @@
#ifndef CC_BASE_MATH_UTIL_H_
#define CC_BASE_MATH_UTIL_H_
-#include <algorithm>
-#include <cmath>
+#include <limits>
#include <memory>
#include <vector>
@@ -82,22 +81,6 @@ struct HomogeneousCoordinate {
class CC_BASE_EXPORT MathUtil {
public:
- static const double kPiDouble;
- static const float kPiFloat;
-
- static double Deg2Rad(double deg) { return deg * kPiDouble / 180.0; }
- static double Rad2Deg(double rad) { return rad * 180.0 / kPiDouble; }
-
- static float Deg2Rad(float deg) { return deg * kPiFloat / 180.0f; }
- static float Rad2Deg(float rad) { return rad * 180.0f / kPiFloat; }
-
- static float Round(float f) {
- return (f > 0.f) ? std::floor(f + 0.5f) : std::ceil(f - 0.5f);
- }
- static double Round(double d) {
- return (d > 0.0) ? std::floor(d + 0.5) : std::ceil(d - 0.5);
- }
-
// Returns true if rounded up value does not overflow, false otherwise.
template <typename T>
static bool VerifyRoundup(T n, T mul) {
@@ -113,7 +96,6 @@ class CC_BASE_EXPORT MathUtil {
static T UncheckedRoundUp(T n, T mul) {
static_assert(std::numeric_limits<T>::is_integer,
"T must be an integer type");
- DCHECK(VerifyRoundup(n, mul));
return RoundUpInternal(n, mul);
}
@@ -142,7 +124,6 @@ class CC_BASE_EXPORT MathUtil {
static T UncheckedRoundDown(T n, T mul) {
static_assert(std::numeric_limits<T>::is_integer,
"T must be an integer type");
- DCHECK(VerifyRoundDown(n, mul));
return RoundDownInternal(n, mul);
}
@@ -156,16 +137,6 @@ class CC_BASE_EXPORT MathUtil {
return RoundDownInternal(n, mul);
}
- template <typename T> static T ClampToRange(T value, T min, T max) {
- return std::min(std::max(value, min), max);
- }
-
- template <typename T>
- static bool ApproximatelyEqual(T lhs, T rhs, T tolerance) {
- DCHECK_LE(0, tolerance);
- return std::abs(rhs - lhs) <= tolerance;
- }
-
template <typename T>
static bool IsWithinEpsilon(T a, T b) {
return std::abs(a - b) < std::numeric_limits<T>::epsilon();
diff --git a/chromium/cc/base/render_surface_filters.cc b/chromium/cc/base/render_surface_filters.cc
index 9efbc800d41..9d7b66eb756 100644
--- a/chromium/cc/base/render_surface_filters.cc
+++ b/chromium/cc/base/render_surface_filters.cc
@@ -8,6 +8,7 @@
#include <algorithm>
+#include "base/numerics/math_constants.h"
#include "cc/base/filter_operation.h"
#include "cc/base/filter_operations.h"
#include "third_party/skia/include/core/SkImageFilter.h"
@@ -69,10 +70,8 @@ void GetSaturateMatrix(float amount, SkScalar matrix[20]) {
}
void GetHueRotateMatrix(float hue, SkScalar matrix[20]) {
- const float kPi = 3.1415926535897932384626433832795f;
-
- float cos_hue = cosf(hue * kPi / 180.f);
- float sin_hue = sinf(hue * kPi / 180.f);
+ float cos_hue = cosf(hue * base::kPiFloat / 180.f);
+ float sin_hue = sinf(hue * base::kPiFloat / 180.f);
matrix[0] = 0.213f + cos_hue * 0.787f - sin_hue * 0.213f;
matrix[1] = 0.715f - cos_hue * 0.715f - sin_hue * 0.715f;
matrix[2] = 0.072f - cos_hue * 0.072f + sin_hue * 0.928f;
diff --git a/chromium/cc/base/rolling_time_delta_history.h b/chromium/cc/base/rolling_time_delta_history.h
index b45be0e5ec5..ed20073e25f 100644
--- a/chromium/cc/base/rolling_time_delta_history.h
+++ b/chromium/cc/base/rolling_time_delta_history.h
@@ -7,9 +7,9 @@
#include <stddef.h>
-#include <deque>
#include <set>
+#include "base/containers/circular_deque.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "cc/base/base_export.h"
@@ -36,7 +36,7 @@ class CC_BASE_EXPORT RollingTimeDeltaHistory {
typedef std::multiset<base::TimeDelta> TimeDeltaMultiset;
TimeDeltaMultiset sample_set_;
- std::deque<TimeDeltaMultiset::iterator> chronological_sample_deque_;
+ base::circular_deque<TimeDeltaMultiset::iterator> chronological_sample_deque_;
size_t max_size_;
DISALLOW_COPY_AND_ASSIGN(RollingTimeDeltaHistory);
diff --git a/chromium/cc/benchmarks/rasterize_and_record_benchmark_impl.cc b/chromium/cc/benchmarks/rasterize_and_record_benchmark_impl.cc
index 00e3ade3dd5..2fb28ba0964 100644
--- a/chromium/cc/benchmarks/rasterize_and_record_benchmark_impl.cc
+++ b/chromium/cc/benchmarks/rasterize_and_record_benchmark_impl.cc
@@ -58,8 +58,16 @@ void RunBenchmark(RasterSource* raster_source,
content_rect.height()));
SkCanvas canvas(bitmap);
+ // Pass an empty settings to make sure that the decode cache is used to
+ // replace all images.
+ base::Optional<PlaybackImageProvider::Settings> image_settings;
+ image_settings.emplace();
+ image_settings->images_to_skip = {};
+ image_settings->at_raster_images = {};
+ image_settings->image_to_current_frame_index = {};
+
PlaybackImageProvider image_provider(
- false, PaintImageIdFlatSet(), image_decode_cache, gfx::ColorSpace());
+ image_decode_cache, gfx::ColorSpace(), std::move(image_settings));
RasterSource::PlaybackSettings settings;
settings.image_provider = &image_provider;
diff --git a/chromium/cc/blink/web_compositor_support_impl.cc b/chromium/cc/blink/web_compositor_support_impl.cc
index b96dccb6eb3..d6c35fa53f9 100644
--- a/chromium/cc/blink/web_compositor_support_impl.cc
+++ b/chromium/cc/blink/web_compositor_support_impl.cc
@@ -14,8 +14,6 @@
#include "cc/blink/web_layer_impl.h"
#include "cc/blink/web_scrollbar_layer_impl.h"
#include "cc/layers/layer.h"
-#include "cc/output/output_surface.h"
-#include "cc/output/software_output_device.h"
using blink::WebContentLayer;
using blink::WebContentLayerClient;
diff --git a/chromium/cc/blink/web_content_layer_impl.cc b/chromium/cc/blink/web_content_layer_impl.cc
index fe7d016ac89..c72dffe6584 100644
--- a/chromium/cc/blink/web_content_layer_impl.cc
+++ b/chromium/cc/blink/web_content_layer_impl.cc
@@ -76,7 +76,7 @@ gfx::Rect WebContentLayerImpl::PaintableRegion() {
scoped_refptr<cc::DisplayItemList>
WebContentLayerImpl::PaintContentsToDisplayList(
cc::ContentLayerClient::PaintingControlSetting painting_control) {
- auto display_list = make_scoped_refptr(new cc::DisplayItemList);
+ auto display_list = base::MakeRefCounted<cc::DisplayItemList>();
if (client_) {
WebDisplayItemListImpl list(display_list.get());
client_->PaintContents(&list, PaintingControlToWeb(painting_control));
diff --git a/chromium/cc/blink/web_display_item_list_impl.cc b/chromium/cc/blink/web_display_item_list_impl.cc
index 26712cdf416..8fe2708d113 100644
--- a/chromium/cc/blink/web_display_item_list_impl.cc
+++ b/chromium/cc/blink/web_display_item_list_impl.cc
@@ -38,8 +38,7 @@ WebDisplayItemListImpl::~WebDisplayItemListImpl() = default;
void WebDisplayItemListImpl::AppendDrawingItem(
const blink::WebRect& visual_rect,
- sk_sp<const cc::PaintOpBuffer> record,
- const blink::WebRect& record_bounds) {
+ sk_sp<const cc::PaintOpBuffer> record) {
display_item_list_->StartPaint();
display_item_list_->push<cc::DrawRecordOp>(std::move(record));
display_item_list_->EndPaintOfUnpaired(visual_rect);
@@ -202,4 +201,8 @@ void WebDisplayItemListImpl::AppendRestore() {
display_item_list_->EndPaintOfPairedEnd();
}
+cc::DisplayItemList* WebDisplayItemListImpl::GetCcDisplayItemList() {
+ return display_item_list_.get();
+}
+
} // namespace cc_blink
diff --git a/chromium/cc/blink/web_display_item_list_impl.h b/chromium/cc/blink/web_display_item_list_impl.h
index c8da1b5b11f..de666a0dde3 100644
--- a/chromium/cc/blink/web_display_item_list_impl.h
+++ b/chromium/cc/blink/web_display_item_list_impl.h
@@ -41,8 +41,7 @@ class CC_BLINK_EXPORT WebDisplayItemListImpl
// blink::WebDisplayItemList implementation.
void AppendDrawingItem(const blink::WebRect& visual_rect,
- sk_sp<const cc::PaintOpBuffer> record,
- const blink::WebRect& record_bounds) override;
+ sk_sp<const cc::PaintOpBuffer> record) override;
void AppendClipItem(
const blink::WebRect& clip_rect,
const blink::WebVector<SkRRect>& rounded_clip_rects) override;
@@ -65,6 +64,7 @@ class CC_BLINK_EXPORT WebDisplayItemListImpl
void AppendScrollItem(const blink::WebSize& scrollOffset,
ScrollContainerId) override;
void AppendEndScrollItem() override;
+ cc::DisplayItemList* GetCcDisplayItemList() override;
private:
void AppendRestore();
diff --git a/chromium/cc/blink/web_display_item_list_impl_unittest.cc b/chromium/cc/blink/web_display_item_list_impl_unittest.cc
index 1cdabf30307..5d920c13e92 100644
--- a/chromium/cc/blink/web_display_item_list_impl_unittest.cc
+++ b/chromium/cc/blink/web_display_item_list_impl_unittest.cc
@@ -36,7 +36,7 @@ TEST(WebDisplayItemListImpl, ClipWhenCompositing) {
clip_bounds.x, clip_bounds.y, clip_bounds.width, clip_bounds.height);
SkIRect clip_irect = sk_clip_bounds.roundOut();
- auto cc_list = make_scoped_refptr(new cc::DisplayItemList);
+ auto cc_list = base::MakeRefCounted<cc::DisplayItemList>();
cc_blink::WebDisplayItemListImpl web_list(cc_list.get());
// drawColor(background color)
@@ -46,12 +46,12 @@ TEST(WebDisplayItemListImpl, ClipWhenCompositing) {
auto background_record = sk_make_sp<cc::PaintRecord>();
background_record->push<cc::DrawColorOp>(background_color,
SkBlendMode::kSrcOver);
- web_list.AppendDrawingItem(full_bounds, background_record, full_bounds);
+ web_list.AppendDrawingItem(full_bounds, background_record);
web_list.AppendCompositingItem(1.f, blend_modes[i], &sk_clip_bounds,
nullptr);
auto clip_record = sk_make_sp<cc::PaintRecord>();
clip_record->push<cc::DrawColorOp>(clip_color, SkBlendMode::kSrcOver);
- web_list.AppendDrawingItem(full_bounds, clip_record, full_bounds);
+ web_list.AppendDrawingItem(full_bounds, clip_record);
web_list.AppendEndCompositingItem();
cc_list->Finalize();
diff --git a/chromium/cc/blink/web_layer_impl.cc b/chromium/cc/blink/web_layer_impl.cc
index b4ced27db0e..2f2980d2839 100644
--- a/chromium/cc/blink/web_layer_impl.cc
+++ b/chromium/cc/blink/web_layer_impl.cc
@@ -134,12 +134,8 @@ bool WebLayerImpl::IsRootForIsolatedGroup() {
return layer_->is_root_for_isolated_group();
}
-void WebLayerImpl::SetShouldHitTest(bool should_hit_test) {
- layer_->SetShouldHitTest(should_hit_test);
-}
-
-bool WebLayerImpl::ShouldHitTest() {
- return layer_->should_hit_test();
+void WebLayerImpl::SetHitTestableWithoutDrawsContent(bool should_hit_test) {
+ layer_->SetHitTestableWithoutDrawsContent(should_hit_test);
}
void WebLayerImpl::SetOpaque(bool opaque) {
@@ -487,14 +483,6 @@ cc::ElementId WebLayerImpl::GetElementId() const {
return layer_->element_id();
}
-void WebLayerImpl::SetCompositorMutableProperties(uint32_t properties) {
- layer_->SetMutableProperties(properties);
-}
-
-uint32_t WebLayerImpl::CompositorMutableProperties() const {
- return layer_->mutable_properties();
-}
-
void WebLayerImpl::SetScrollParent(blink::WebLayer* parent) {
cc::Layer* scroll_parent = nullptr;
if (parent)
diff --git a/chromium/cc/blink/web_layer_impl.h b/chromium/cc/blink/web_layer_impl.h
index dc419b90639..829939de077 100644
--- a/chromium/cc/blink/web_layer_impl.h
+++ b/chromium/cc/blink/web_layer_impl.h
@@ -43,11 +43,6 @@ class CC_BLINK_EXPORT WebLayerImpl : public blink::WebLayer {
cc::Layer* layer() const;
- // If set to true, content opaqueness cannot be changed using setOpaque.
- // However, it can still be modified using SetContentsOpaque on the
- // cc::Layer.
- void SetContentsOpaqueIsFixed(bool fixed);
-
// WebLayer implementation.
int Id() const override;
void InvalidateRect(const blink::WebRect&) override;
@@ -65,12 +60,13 @@ class CC_BLINK_EXPORT WebLayerImpl : public blink::WebLayer {
void SetMaskLayer(blink::WebLayer* mask) override;
void SetOpacity(float opacity) override;
float Opacity() const override;
+ void SetContentsOpaqueIsFixed(bool fixed) override;
+
void SetBlendMode(blink::WebBlendMode blend_mode) override;
blink::WebBlendMode BlendMode() const override;
void SetIsRootForIsolatedGroup(bool root) override;
bool IsRootForIsolatedGroup() override;
- void SetShouldHitTest(bool should_hit_test) override;
- bool ShouldHitTest() override;
+ void SetHitTestableWithoutDrawsContent(bool should_hit_test) override;
void SetOpaque(bool opaque) override;
bool Opaque() const override;
void SetPosition(const blink::WebFloatPoint& position) override;
@@ -131,8 +127,6 @@ class CC_BLINK_EXPORT WebLayerImpl : public blink::WebLayer {
cc::Layer* CcLayer() override;
void SetElementId(const cc::ElementId&) override;
cc::ElementId GetElementId() const override;
- void SetCompositorMutableProperties(uint32_t properties) override;
- uint32_t CompositorMutableProperties() const override;
void SetHasWillChangeTransformHint(bool has_will_change) override;
void ShowScrollbars() override;
void SetScrollBoundaryBehavior(
diff --git a/chromium/cc/input/layer_selection_bound.h b/chromium/cc/input/layer_selection_bound.h
index f69d1548921..5174341909b 100644
--- a/chromium/cc/input/layer_selection_bound.h
+++ b/chromium/cc/input/layer_selection_bound.h
@@ -6,7 +6,7 @@
#define CC_INPUT_LAYER_SELECTION_BOUND_H_
#include "cc/cc_export.h"
-#include "cc/input/selection.h"
+#include "components/viz/common/quads/selection.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/selection_bound.h"
@@ -30,7 +30,7 @@ struct CC_EXPORT LayerSelectionBound {
bool operator!=(const LayerSelectionBound& other) const;
};
-typedef Selection<LayerSelectionBound> LayerSelection;
+using LayerSelection = viz::Selection<LayerSelectionBound>;
} // namespace cc
diff --git a/chromium/cc/input/scroll_state.h b/chromium/cc/input/scroll_state.h
index cd671909f75..11114c0293b 100644
--- a/chromium/cc/input/scroll_state.h
+++ b/chromium/cc/input/scroll_state.h
@@ -57,8 +57,6 @@ class CC_EXPORT ScrollState {
bool is_ending() const { return data_.is_ending; }
void set_is_ending(bool is_ending) { data_.is_ending = is_ending; }
- // True if this scroll is allowed to bubble upwards.
- bool should_propagate() const { return data_.should_propagate; }
// True if the user interacts directly with the screen, e.g., via touch.
bool is_direct_manipulation() const { return data_.is_direct_manipulation; }
void set_is_direct_manipulation(bool is_direct_manipulation) {
diff --git a/chromium/cc/input/scroll_state_data.cc b/chromium/cc/input/scroll_state_data.cc
index f5bad71cfc9..66ef528c054 100644
--- a/chromium/cc/input/scroll_state_data.cc
+++ b/chromium/cc/input/scroll_state_data.cc
@@ -19,7 +19,6 @@ ScrollStateData::ScrollStateData()
is_beginning(false),
is_in_inertial_phase(false),
is_ending(false),
- should_propagate(false),
from_user_input(false),
delta_consumed_for_scroll_sequence(false),
is_direct_manipulation(false),
diff --git a/chromium/cc/input/scroll_state_data.h b/chromium/cc/input/scroll_state_data.h
index cb5ec626e07..75c3ecea116 100644
--- a/chromium/cc/input/scroll_state_data.h
+++ b/chromium/cc/input/scroll_state_data.h
@@ -38,7 +38,6 @@ class CC_EXPORT ScrollStateData {
bool is_in_inertial_phase;
bool is_ending;
- bool should_propagate;
bool from_user_input;
// Whether the scroll sequence has had any delta consumed, in the
diff --git a/chromium/cc/input/selection.h b/chromium/cc/input/selection.h
deleted file mode 100644
index 1b95ec9b6c6..00000000000
--- a/chromium/cc/input/selection.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_INPUT_SELECTION_H_
-#define CC_INPUT_SELECTION_H_
-
-#include "cc/cc_export.h"
-
-namespace cc {
-
-template <typename BoundType>
-struct CC_EXPORT Selection {
- Selection() {}
- ~Selection() {}
-
- BoundType start, end;
-};
-
-template <typename BoundType>
-inline bool operator==(const Selection<BoundType>& lhs,
- const Selection<BoundType>& rhs) {
- return lhs.start == rhs.start && lhs.end == rhs.end;
-}
-
-template <typename BoundType>
-inline bool operator!=(const Selection<BoundType>& lhs,
- const Selection<BoundType>& rhs) {
- return !(lhs == rhs);
-}
-
-} // namespace cc
-
-#endif // CC_INPUT_SELECTION_H_
diff --git a/chromium/cc/ipc/BUILD.gn b/chromium/cc/ipc/BUILD.gn
index fa26b2c68cc..e59f2652942 100644
--- a/chromium/cc/ipc/BUILD.gn
+++ b/chromium/cc/ipc/BUILD.gn
@@ -36,33 +36,3 @@ cc_component("ipc") {
"//ui/latency/ipc",
]
}
-
-mojom("interfaces") {
- sources = [
- "copy_output_result.mojom",
- "frame_sink_id.mojom",
- "local_surface_id.mojom",
- "texture_mailbox.mojom",
- "texture_mailbox_releaser.mojom",
- ]
-
- public_deps = [
- "//gpu/ipc/common:interfaces",
- "//mojo/common:common_custom_types",
- "//skia/public/interfaces",
- "//ui/gfx/geometry/mojo",
- "//ui/gfx/mojo",
- "//ui/latency/mojo:interfaces",
- ]
-}
-
-mojom("test_interfaces") {
- testonly = true
- sources = [
- "traits_test_service.mojom",
- ]
-
- public_deps = [
- ":interfaces",
- ]
-}
diff --git a/chromium/cc/ipc/cc_param_traits.cc b/chromium/cc/ipc/cc_param_traits.cc
index 2e0d2aabadd..2a80dee31e8 100644
--- a/chromium/cc/ipc/cc_param_traits.cc
+++ b/chromium/cc/ipc/cc_param_traits.cc
@@ -12,16 +12,17 @@
#include "base/trace_event/trace_event.h"
#include "base/unguessable_token.h"
#include "cc/base/filter_operations.h"
-#include "cc/output/compositor_frame.h"
-#include "cc/quads/debug_border_draw_quad.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/largest_draw_quad.h"
-#include "cc/quads/render_pass_draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/surface_draw_quad.h"
-#include "cc/quads/tile_draw_quad.h"
-#include "cc/quads/yuv_video_draw_quad.h"
+#include "components/viz/common/quads/compositor_frame.h"
+#include "components/viz/common/quads/debug_border_draw_quad.h"
+#include "components/viz/common/quads/draw_quad.h"
+#include "components/viz/common/quads/largest_draw_quad.h"
+#include "components/viz/common/quads/render_pass_draw_quad.h"
+#include "components/viz/common/quads/solid_color_draw_quad.h"
+#include "components/viz/common/quads/surface_draw_quad.h"
+#include "components/viz/common/quads/tile_draw_quad.h"
+#include "components/viz/common/quads/yuv_video_draw_quad.h"
#include "components/viz/common/surfaces/surface_id.h"
+#include "skia/ext/skia_utils_base.h"
#include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkFlattenableSerialization.h"
#include "third_party/skia/include/core/SkImageFilter.h"
@@ -32,49 +33,6 @@
namespace IPC {
-void ParamTraits<cc::FilterOperation>::GetSize(base::PickleSizer* s,
- const param_type& p) {
- GetParamSize(s, p.type());
- switch (p.type()) {
- case cc::FilterOperation::GRAYSCALE:
- case cc::FilterOperation::SEPIA:
- case cc::FilterOperation::SATURATE:
- case cc::FilterOperation::HUE_ROTATE:
- case cc::FilterOperation::INVERT:
- case cc::FilterOperation::BRIGHTNESS:
- case cc::FilterOperation::SATURATING_BRIGHTNESS:
- case cc::FilterOperation::CONTRAST:
- case cc::FilterOperation::OPACITY:
- GetParamSize(s, p.amount());
- break;
- case cc::FilterOperation::BLUR:
- GetParamSize(s, p.amount());
- GetParamSize(s, p.blur_tile_mode());
- break;
- case cc::FilterOperation::DROP_SHADOW:
- GetParamSize(s, p.drop_shadow_offset());
- GetParamSize(s, p.amount());
- GetParamSize(s, p.drop_shadow_color());
- break;
- case cc::FilterOperation::COLOR_MATRIX:
- for (int i = 0; i < 20; ++i)
- GetParamSize(s, p.matrix()[i]);
- break;
- case cc::FilterOperation::ZOOM:
- GetParamSize(s, p.amount());
- GetParamSize(s, p.zoom_inset());
- break;
- case cc::FilterOperation::REFERENCE:
- GetParamSize(s, p.image_filter());
- break;
- case cc::FilterOperation::ALPHA_THRESHOLD:
- GetParamSize(s, p.amount());
- GetParamSize(s, p.outer_threshold());
- GetParamSize(s, p.shape());
- break;
- }
-}
-
void ParamTraits<cc::FilterOperation>::Write(base::Pickle* m,
const param_type& p) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.ipc"),
@@ -272,14 +230,6 @@ void ParamTraits<cc::FilterOperation>::Log(const param_type& p,
l->append(")");
}
-void ParamTraits<cc::FilterOperations>::GetSize(base::PickleSizer* s,
- const param_type& p) {
- GetParamSize(s, base::checked_cast<uint32_t>(p.size()));
- for (std::size_t i = 0; i < p.size(); ++i) {
- GetParamSize(s, p.at(i));
- }
-}
-
void ParamTraits<cc::FilterOperations>::Write(base::Pickle* m,
const param_type& p) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.ipc"),
@@ -319,24 +269,13 @@ void ParamTraits<cc::FilterOperations>::Log(const param_type& p,
l->append(")");
}
-void ParamTraits<sk_sp<SkImageFilter>>::GetSize(base::PickleSizer* s,
- const param_type& p) {
- SkImageFilter* filter = p.get();
- if (filter) {
- sk_sp<SkData> data(SkValidatingSerializeFlattenable(filter));
- s->AddData(base::checked_cast<int>(data->size()));
- } else {
- s->AddData(0);
- }
-}
-
void ParamTraits<sk_sp<SkImageFilter>>::Write(base::Pickle* m,
const param_type& p) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.ipc"),
"ParamTraits::SkImageFilter::Write");
SkImageFilter* filter = p.get();
if (filter) {
- sk_sp<SkData> data(SkValidatingSerializeFlattenable(filter));
+ sk_sp<SkData> data(skia::ValidatingSerializeFlattenable(filter));
m->WriteData(static_cast<const char*>(data->data()),
base::checked_cast<int>(data->size()));
} else {
@@ -370,7 +309,7 @@ void ParamTraits<sk_sp<SkImageFilter>>::Log(const param_type& p,
l->append(")");
}
-void ParamTraits<cc::RenderPass>::Write(base::Pickle* m, const param_type& p) {
+void ParamTraits<viz::RenderPass>::Write(base::Pickle* m, const param_type& p) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.ipc"),
"ParamTraits::RenderPass::Write");
WriteParam(m, p.id);
@@ -383,46 +322,45 @@ void ParamTraits<cc::RenderPass>::Write(base::Pickle* m, const param_type& p) {
WriteParam(m, p.has_transparent_background);
WriteParam(m, p.cache_render_pass);
WriteParam(m, p.has_damage_from_contributing_content);
+ WriteParam(m, p.generate_mipmap);
WriteParam(m, base::checked_cast<uint32_t>(p.quad_list.size()));
- cc::SharedQuadStateList::ConstIterator shared_quad_state_iter =
- p.shared_quad_state_list.begin();
- cc::SharedQuadStateList::ConstIterator last_shared_quad_state_iter =
- p.shared_quad_state_list.end();
+ auto shared_quad_state_iter = p.shared_quad_state_list.cbegin();
+ auto last_shared_quad_state_iter = p.shared_quad_state_list.cend();
for (auto* quad : p.quad_list) {
DCHECK(quad->rect.Contains(quad->visible_rect))
<< quad->material << " rect: " << quad->rect.ToString()
<< " visible_rect: " << quad->visible_rect.ToString();
switch (quad->material) {
- case cc::DrawQuad::DEBUG_BORDER:
- WriteParam(m, *cc::DebugBorderDrawQuad::MaterialCast(quad));
+ case viz::DrawQuad::DEBUG_BORDER:
+ WriteParam(m, *viz::DebugBorderDrawQuad::MaterialCast(quad));
break;
- case cc::DrawQuad::PICTURE_CONTENT:
+ case viz::DrawQuad::PICTURE_CONTENT:
NOTREACHED();
break;
- case cc::DrawQuad::TEXTURE_CONTENT:
- WriteParam(m, *cc::TextureDrawQuad::MaterialCast(quad));
+ case viz::DrawQuad::TEXTURE_CONTENT:
+ WriteParam(m, *viz::TextureDrawQuad::MaterialCast(quad));
break;
- case cc::DrawQuad::RENDER_PASS:
- WriteParam(m, *cc::RenderPassDrawQuad::MaterialCast(quad));
+ case viz::DrawQuad::RENDER_PASS:
+ WriteParam(m, *viz::RenderPassDrawQuad::MaterialCast(quad));
break;
- case cc::DrawQuad::SOLID_COLOR:
- WriteParam(m, *cc::SolidColorDrawQuad::MaterialCast(quad));
+ case viz::DrawQuad::SOLID_COLOR:
+ WriteParam(m, *viz::SolidColorDrawQuad::MaterialCast(quad));
break;
- case cc::DrawQuad::SURFACE_CONTENT:
- WriteParam(m, *cc::SurfaceDrawQuad::MaterialCast(quad));
+ case viz::DrawQuad::SURFACE_CONTENT:
+ WriteParam(m, *viz::SurfaceDrawQuad::MaterialCast(quad));
break;
- case cc::DrawQuad::TILED_CONTENT:
- WriteParam(m, *cc::TileDrawQuad::MaterialCast(quad));
+ case viz::DrawQuad::TILED_CONTENT:
+ WriteParam(m, *viz::TileDrawQuad::MaterialCast(quad));
break;
- case cc::DrawQuad::STREAM_VIDEO_CONTENT:
- WriteParam(m, *cc::StreamVideoDrawQuad::MaterialCast(quad));
+ case viz::DrawQuad::STREAM_VIDEO_CONTENT:
+ WriteParam(m, *viz::StreamVideoDrawQuad::MaterialCast(quad));
break;
- case cc::DrawQuad::YUV_VIDEO_CONTENT:
- WriteParam(m, *cc::YUVVideoDrawQuad::MaterialCast(quad));
+ case viz::DrawQuad::YUV_VIDEO_CONTENT:
+ WriteParam(m, *viz::YUVVideoDrawQuad::MaterialCast(quad));
break;
- case cc::DrawQuad::INVALID:
+ case viz::DrawQuad::INVALID:
break;
}
@@ -448,8 +386,8 @@ void ParamTraits<cc::RenderPass>::Write(base::Pickle* m, const param_type& p) {
}
}
-static size_t ReserveSizeForRenderPassWrite(const cc::RenderPass& p) {
- size_t to_reserve = sizeof(cc::RenderPass);
+static size_t ReserveSizeForRenderPassWrite(const viz::RenderPass& p) {
+ size_t to_reserve = sizeof(viz::RenderPass);
// Whether the quad points to a new shared quad state for each quad.
to_reserve += p.quad_list.size() * sizeof(bool);
@@ -459,20 +397,20 @@ static size_t ReserveSizeForRenderPassWrite(const cc::RenderPass& p) {
to_reserve += p.shared_quad_state_list.size() * sizeof(viz::SharedQuadState);
// The largest quad type, verified by a unit test.
- to_reserve += p.quad_list.size() * cc::LargestDrawQuadSize();
+ to_reserve += p.quad_list.size() * viz::LargestDrawQuadSize();
- base::PickleSizer sizer;
- GetParamSize(&sizer, p.filters);
- GetParamSize(&sizer, p.background_filters);
- to_reserve += sizer.payload_size();
+ to_reserve +=
+ sizeof(uint32_t) + p.filters.size() * sizeof(cc::FilterOperation);
+ to_reserve += sizeof(uint32_t) +
+ p.background_filters.size() * sizeof(cc::FilterOperation);
return to_reserve;
}
template <typename QuadType>
-static cc::DrawQuad* ReadDrawQuad(const base::Pickle* m,
- base::PickleIterator* iter,
- cc::RenderPass* render_pass) {
+static viz::DrawQuad* ReadDrawQuad(const base::Pickle* m,
+ base::PickleIterator* iter,
+ viz::RenderPass* render_pass) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.ipc"),
"ParamTraits::ReadDrawQuad");
QuadType* quad = render_pass->CreateAndAppendDrawQuad<QuadType>();
@@ -481,9 +419,9 @@ static cc::DrawQuad* ReadDrawQuad(const base::Pickle* m,
return quad;
}
-bool ParamTraits<cc::RenderPass>::Read(const base::Pickle* m,
- base::PickleIterator* iter,
- param_type* p) {
+bool ParamTraits<viz::RenderPass>::Read(const base::Pickle* m,
+ base::PickleIterator* iter,
+ param_type* p) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.ipc"),
"ParamTraits::RenderPass::Read");
uint64_t id;
@@ -496,6 +434,7 @@ bool ParamTraits<cc::RenderPass>::Read(const base::Pickle* m,
bool has_transparent_background;
bool cache_render_pass;
bool has_damage_from_contributing_content;
+ bool generate_mipmap;
uint32_t quad_list_size;
@@ -508,50 +447,52 @@ bool ParamTraits<cc::RenderPass>::Read(const base::Pickle* m,
!ReadParam(m, iter, &has_transparent_background) ||
!ReadParam(m, iter, &cache_render_pass) ||
!ReadParam(m, iter, &has_damage_from_contributing_content) ||
+ !ReadParam(m, iter, &generate_mipmap) ||
!ReadParam(m, iter, &quad_list_size))
return false;
p->SetAll(id, output_rect, damage_rect, transform_to_root_target, filters,
background_filters, color_space, has_transparent_background,
- cache_render_pass, has_damage_from_contributing_content);
+ cache_render_pass, has_damage_from_contributing_content,
+ generate_mipmap);
- cc::DrawQuad* last_draw_quad = nullptr;
+ viz::DrawQuad* last_draw_quad = nullptr;
for (uint32_t i = 0; i < quad_list_size; ++i) {
- cc::DrawQuad::Material material;
+ viz::DrawQuad::Material material;
base::PickleIterator temp_iter = *iter;
if (!ReadParam(m, &temp_iter, &material))
return false;
- cc::DrawQuad* draw_quad = nullptr;
+ viz::DrawQuad* draw_quad = nullptr;
switch (material) {
- case cc::DrawQuad::DEBUG_BORDER:
- draw_quad = ReadDrawQuad<cc::DebugBorderDrawQuad>(m, iter, p);
+ case viz::DrawQuad::DEBUG_BORDER:
+ draw_quad = ReadDrawQuad<viz::DebugBorderDrawQuad>(m, iter, p);
break;
- case cc::DrawQuad::PICTURE_CONTENT:
+ case viz::DrawQuad::PICTURE_CONTENT:
NOTREACHED();
return false;
- case cc::DrawQuad::SURFACE_CONTENT:
- draw_quad = ReadDrawQuad<cc::SurfaceDrawQuad>(m, iter, p);
+ case viz::DrawQuad::SURFACE_CONTENT:
+ draw_quad = ReadDrawQuad<viz::SurfaceDrawQuad>(m, iter, p);
break;
- case cc::DrawQuad::TEXTURE_CONTENT:
- draw_quad = ReadDrawQuad<cc::TextureDrawQuad>(m, iter, p);
+ case viz::DrawQuad::TEXTURE_CONTENT:
+ draw_quad = ReadDrawQuad<viz::TextureDrawQuad>(m, iter, p);
break;
- case cc::DrawQuad::RENDER_PASS:
- draw_quad = ReadDrawQuad<cc::RenderPassDrawQuad>(m, iter, p);
+ case viz::DrawQuad::RENDER_PASS:
+ draw_quad = ReadDrawQuad<viz::RenderPassDrawQuad>(m, iter, p);
break;
- case cc::DrawQuad::SOLID_COLOR:
- draw_quad = ReadDrawQuad<cc::SolidColorDrawQuad>(m, iter, p);
+ case viz::DrawQuad::SOLID_COLOR:
+ draw_quad = ReadDrawQuad<viz::SolidColorDrawQuad>(m, iter, p);
break;
- case cc::DrawQuad::TILED_CONTENT:
- draw_quad = ReadDrawQuad<cc::TileDrawQuad>(m, iter, p);
+ case viz::DrawQuad::TILED_CONTENT:
+ draw_quad = ReadDrawQuad<viz::TileDrawQuad>(m, iter, p);
break;
- case cc::DrawQuad::STREAM_VIDEO_CONTENT:
- draw_quad = ReadDrawQuad<cc::StreamVideoDrawQuad>(m, iter, p);
+ case viz::DrawQuad::STREAM_VIDEO_CONTENT:
+ draw_quad = ReadDrawQuad<viz::StreamVideoDrawQuad>(m, iter, p);
break;
- case cc::DrawQuad::YUV_VIDEO_CONTENT:
- draw_quad = ReadDrawQuad<cc::YUVVideoDrawQuad>(m, iter, p);
+ case viz::DrawQuad::YUV_VIDEO_CONTENT:
+ draw_quad = ReadDrawQuad<viz::YUVVideoDrawQuad>(m, iter, p);
break;
- case cc::DrawQuad::INVALID:
+ case viz::DrawQuad::INVALID:
break;
}
if (!draw_quad)
@@ -575,23 +516,24 @@ bool ParamTraits<cc::RenderPass>::Read(const base::Pickle* m,
}
draw_quad->shared_quad_state = p->shared_quad_state_list.back();
- // If this quad is a fallback SurfaceDrawQuad then update the previous
- // primary SurfaceDrawQuad to point to this quad.
- if (draw_quad->material == cc::DrawQuad::SURFACE_CONTENT) {
- const cc::SurfaceDrawQuad* surface_draw_quad =
- cc::SurfaceDrawQuad::MaterialCast(draw_quad);
+ // If this quad is a fallback viz::SurfaceDrawQuad then update the previous
+ // primary viz::SurfaceDrawQuad to point to this quad.
+ if (draw_quad->material == viz::DrawQuad::SURFACE_CONTENT) {
+ const viz::SurfaceDrawQuad* surface_draw_quad =
+ viz::SurfaceDrawQuad::MaterialCast(draw_quad);
if (surface_draw_quad->surface_draw_quad_type ==
- cc::SurfaceDrawQuadType::FALLBACK) {
- // A fallback quad must immediately follow a primary SurfaceDrawQuad.
+ viz::SurfaceDrawQuadType::FALLBACK) {
+ // A fallback quad must immediately follow a primary
+ // viz::SurfaceDrawQuad.
if (!last_draw_quad ||
- last_draw_quad->material != cc::DrawQuad::SURFACE_CONTENT) {
+ last_draw_quad->material != viz::DrawQuad::SURFACE_CONTENT) {
return false;
}
- cc::SurfaceDrawQuad* last_surface_draw_quad =
- static_cast<cc::SurfaceDrawQuad*>(last_draw_quad);
+ viz::SurfaceDrawQuad* last_surface_draw_quad =
+ static_cast<viz::SurfaceDrawQuad*>(last_draw_quad);
// Only one fallback quad is currently supported.
if (last_surface_draw_quad->surface_draw_quad_type !=
- cc::SurfaceDrawQuadType::PRIMARY) {
+ viz::SurfaceDrawQuadType::PRIMARY) {
return false;
}
last_surface_draw_quad->fallback_quad = surface_draw_quad;
@@ -603,7 +545,7 @@ bool ParamTraits<cc::RenderPass>::Read(const base::Pickle* m,
return true;
}
-void ParamTraits<cc::RenderPass>::Log(const param_type& p, std::string* l) {
+void ParamTraits<viz::RenderPass>::Log(const param_type& p, std::string* l) {
l->append("RenderPass((");
LogParam(p.id, l);
l->append("), ");
@@ -637,46 +579,40 @@ void ParamTraits<cc::RenderPass>::Log(const param_type& p, std::string* l) {
if (quad != p.quad_list.front())
l->append(", ");
switch (quad->material) {
- case cc::DrawQuad::DEBUG_BORDER:
- LogParam(*cc::DebugBorderDrawQuad::MaterialCast(quad), l);
+ case viz::DrawQuad::DEBUG_BORDER:
+ LogParam(*viz::DebugBorderDrawQuad::MaterialCast(quad), l);
break;
- case cc::DrawQuad::PICTURE_CONTENT:
+ case viz::DrawQuad::PICTURE_CONTENT:
NOTREACHED();
break;
- case cc::DrawQuad::TEXTURE_CONTENT:
- LogParam(*cc::TextureDrawQuad::MaterialCast(quad), l);
+ case viz::DrawQuad::TEXTURE_CONTENT:
+ LogParam(*viz::TextureDrawQuad::MaterialCast(quad), l);
break;
- case cc::DrawQuad::RENDER_PASS:
- LogParam(*cc::RenderPassDrawQuad::MaterialCast(quad), l);
+ case viz::DrawQuad::RENDER_PASS:
+ LogParam(*viz::RenderPassDrawQuad::MaterialCast(quad), l);
break;
- case cc::DrawQuad::SOLID_COLOR:
- LogParam(*cc::SolidColorDrawQuad::MaterialCast(quad), l);
+ case viz::DrawQuad::SOLID_COLOR:
+ LogParam(*viz::SolidColorDrawQuad::MaterialCast(quad), l);
break;
- case cc::DrawQuad::SURFACE_CONTENT:
- LogParam(*cc::SurfaceDrawQuad::MaterialCast(quad), l);
+ case viz::DrawQuad::SURFACE_CONTENT:
+ LogParam(*viz::SurfaceDrawQuad::MaterialCast(quad), l);
break;
- case cc::DrawQuad::TILED_CONTENT:
- LogParam(*cc::TileDrawQuad::MaterialCast(quad), l);
+ case viz::DrawQuad::TILED_CONTENT:
+ LogParam(*viz::TileDrawQuad::MaterialCast(quad), l);
break;
- case cc::DrawQuad::STREAM_VIDEO_CONTENT:
- LogParam(*cc::StreamVideoDrawQuad::MaterialCast(quad), l);
+ case viz::DrawQuad::STREAM_VIDEO_CONTENT:
+ LogParam(*viz::StreamVideoDrawQuad::MaterialCast(quad), l);
break;
- case cc::DrawQuad::YUV_VIDEO_CONTENT:
- LogParam(*cc::YUVVideoDrawQuad::MaterialCast(quad), l);
+ case viz::DrawQuad::YUV_VIDEO_CONTENT:
+ LogParam(*viz::YUVVideoDrawQuad::MaterialCast(quad), l);
break;
- case cc::DrawQuad::INVALID:
+ case viz::DrawQuad::INVALID:
break;
}
}
l->append("])");
}
-void ParamTraits<viz::FrameSinkId>::GetSize(base::PickleSizer* s,
- const param_type& p) {
- GetParamSize(s, p.client_id());
- GetParamSize(s, p.sink_id());
-}
-
void ParamTraits<viz::FrameSinkId>::Write(base::Pickle* m,
const param_type& p) {
WriteParam(m, p.client_id());
@@ -706,12 +642,6 @@ void ParamTraits<viz::FrameSinkId>::Log(const param_type& p, std::string* l) {
l->append(")");
}
-void ParamTraits<viz::LocalSurfaceId>::GetSize(base::PickleSizer* s,
- const param_type& p) {
- GetParamSize(s, p.local_id());
- GetParamSize(s, p.nonce());
-}
-
void ParamTraits<viz::LocalSurfaceId>::Write(base::Pickle* m,
const param_type& p) {
WriteParam(m, p.local_id());
@@ -742,12 +672,6 @@ void ParamTraits<viz::LocalSurfaceId>::Log(const param_type& p,
l->append(")");
}
-void ParamTraits<viz::SurfaceId>::GetSize(base::PickleSizer* s,
- const param_type& p) {
- GetParamSize(s, p.frame_sink_id());
- GetParamSize(s, p.local_surface_id());
-}
-
void ParamTraits<viz::SurfaceId>::Write(base::Pickle* m, const param_type& p) {
WriteParam(m, p.frame_sink_id());
WriteParam(m, p.local_surface_id());
@@ -776,13 +700,6 @@ void ParamTraits<viz::SurfaceId>::Log(const param_type& p, std::string* l) {
l->append(")");
}
-void ParamTraits<viz::SurfaceInfo>::GetSize(base::PickleSizer* s,
- const param_type& p) {
- GetParamSize(s, p.id());
- GetParamSize(s, p.device_scale_factor());
- GetParamSize(s, p.size_in_pixels());
-}
-
void ParamTraits<viz::SurfaceInfo>::Write(base::Pickle* m,
const param_type& p) {
WriteParam(m, p.id());
@@ -819,8 +736,8 @@ void ParamTraits<viz::SurfaceInfo>::Log(const param_type& p, std::string* l) {
l->append(")");
}
-void ParamTraits<cc::CompositorFrame>::Write(base::Pickle* m,
- const param_type& p) {
+void ParamTraits<viz::CompositorFrame>::Write(base::Pickle* m,
+ const param_type& p) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.ipc"),
"ParamTraits::CompositorFrame::Write");
WriteParam(m, p.metadata);
@@ -842,9 +759,9 @@ void ParamTraits<cc::CompositorFrame>::Write(base::Pickle* m,
}
}
-bool ParamTraits<cc::CompositorFrame>::Read(const base::Pickle* m,
- base::PickleIterator* iter,
- param_type* p) {
+bool ParamTraits<viz::CompositorFrame>::Read(const base::Pickle* m,
+ base::PickleIterator* iter,
+ param_type* p) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.ipc"),
"ParamTraits::CompositorFrame::Read");
if (!ReadParam(m, iter, &p->metadata))
@@ -854,7 +771,7 @@ bool ParamTraits<cc::CompositorFrame>::Read(const base::Pickle* m,
const size_t kMaxSharedQuadStateListSize = 100000;
const size_t kMaxQuadListSize = 1000000;
- std::set<cc::RenderPassId> pass_id_set;
+ std::set<viz::RenderPassId> pass_id_set;
uint32_t num_render_passes;
if (!ReadParam(m, iter, &p->resource_list) ||
@@ -869,18 +786,18 @@ bool ParamTraits<cc::CompositorFrame>::Read(const base::Pickle* m,
quad_list_size > kMaxQuadListSize ||
shared_quad_state_list_size > kMaxSharedQuadStateListSize)
return false;
- std::unique_ptr<cc::RenderPass> render_pass =
- cc::RenderPass::Create(static_cast<size_t>(shared_quad_state_list_size),
- static_cast<size_t>(quad_list_size));
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create(
+ static_cast<size_t>(shared_quad_state_list_size),
+ static_cast<size_t>(quad_list_size));
if (!ReadParam(m, iter, render_pass.get()))
return false;
- // Validate that each RenderPassDrawQuad points at a valid RenderPass
+ // Validate that each viz::RenderPassDrawQuad points at a valid RenderPass
// earlier in the frame.
for (const auto* quad : render_pass->quad_list) {
- if (quad->material != cc::DrawQuad::RENDER_PASS)
+ if (quad->material != viz::DrawQuad::RENDER_PASS)
continue;
- const cc::RenderPassDrawQuad* rpdq =
- cc::RenderPassDrawQuad::MaterialCast(quad);
+ const viz::RenderPassDrawQuad* rpdq =
+ viz::RenderPassDrawQuad::MaterialCast(quad);
if (!pass_id_set.count(rpdq->render_pass_id))
return false;
}
@@ -891,8 +808,8 @@ bool ParamTraits<cc::CompositorFrame>::Read(const base::Pickle* m,
return true;
}
-void ParamTraits<cc::CompositorFrame>::Log(const param_type& p,
- std::string* l) {
+void ParamTraits<viz::CompositorFrame>::Log(const param_type& p,
+ std::string* l) {
l->append("CompositorFrame(");
LogParam(p.metadata, l);
l->append(", ");
@@ -906,31 +823,24 @@ void ParamTraits<cc::CompositorFrame>::Log(const param_type& p,
l->append("])");
}
-void ParamTraits<cc::DrawQuad::Resources>::GetSize(base::PickleSizer* s,
- const param_type& p) {
- GetParamSize(s, p.count);
- for (size_t i = 0; i < p.count; ++i)
- GetParamSize(s, p.ids[i]);
-}
-
-void ParamTraits<cc::DrawQuad::Resources>::Write(base::Pickle* m,
- const param_type& p) {
+void ParamTraits<viz::DrawQuad::Resources>::Write(base::Pickle* m,
+ const param_type& p) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.ipc"),
"ParamTraits::DrawQuad::Resources::Write");
- DCHECK_LE(p.count, cc::DrawQuad::Resources::kMaxResourceIdCount);
+ DCHECK_LE(p.count, viz::DrawQuad::Resources::kMaxResourceIdCount);
WriteParam(m, p.count);
for (size_t i = 0; i < p.count; ++i)
WriteParam(m, p.ids[i]);
}
-bool ParamTraits<cc::DrawQuad::Resources>::Read(const base::Pickle* m,
- base::PickleIterator* iter,
- param_type* p) {
+bool ParamTraits<viz::DrawQuad::Resources>::Read(const base::Pickle* m,
+ base::PickleIterator* iter,
+ param_type* p) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.ipc"),
"ParamTraits::DrawQuad::Resources::Read");
if (!ReadParam(m, iter, &p->count))
return false;
- if (p->count > cc::DrawQuad::Resources::kMaxResourceIdCount)
+ if (p->count > viz::DrawQuad::Resources::kMaxResourceIdCount)
return false;
for (size_t i = 0; i < p->count; ++i) {
if (!ReadParam(m, iter, &p->ids[i]))
@@ -939,12 +849,12 @@ bool ParamTraits<cc::DrawQuad::Resources>::Read(const base::Pickle* m,
return true;
}
-void ParamTraits<cc::DrawQuad::Resources>::Log(const param_type& p,
- std::string* l) {
+void ParamTraits<viz::DrawQuad::Resources>::Log(const param_type& p,
+ std::string* l) {
l->append("DrawQuad::Resources(");
LogParam(p.count, l);
l->append(", [");
- if (p.count > cc::DrawQuad::Resources::kMaxResourceIdCount) {
+ if (p.count > viz::DrawQuad::Resources::kMaxResourceIdCount) {
l->append("])");
return;
}
@@ -957,23 +867,9 @@ void ParamTraits<cc::DrawQuad::Resources>::Log(const param_type& p,
l->append("])");
}
-void ParamTraits<cc::YUVVideoDrawQuad>::GetSize(base::PickleSizer* s,
- const param_type& p) {
- ParamTraits<cc::DrawQuad>::GetSize(s, p);
- GetParamSize(s, p.ya_tex_coord_rect);
- GetParamSize(s, p.uv_tex_coord_rect);
- GetParamSize(s, p.ya_tex_size);
- GetParamSize(s, p.uv_tex_size);
- GetParamSize(s, p.color_space);
- GetParamSize(s, p.video_color_space);
- GetParamSize(s, p.resource_offset);
- GetParamSize(s, p.resource_multiplier);
- GetParamSize(s, p.bits_per_channel);
-}
-
-void ParamTraits<cc::YUVVideoDrawQuad>::Write(base::Pickle* m,
- const param_type& p) {
- ParamTraits<cc::DrawQuad>::Write(m, p);
+void ParamTraits<viz::YUVVideoDrawQuad>::Write(base::Pickle* m,
+ const param_type& p) {
+ ParamTraits<viz::DrawQuad>::Write(m, p);
WriteParam(m, p.ya_tex_coord_rect);
WriteParam(m, p.uv_tex_coord_rect);
WriteParam(m, p.ya_tex_size);
@@ -985,10 +881,10 @@ void ParamTraits<cc::YUVVideoDrawQuad>::Write(base::Pickle* m,
WriteParam(m, p.bits_per_channel);
}
-bool ParamTraits<cc::YUVVideoDrawQuad>::Read(const base::Pickle* m,
- base::PickleIterator* iter,
- param_type* p) {
- return ParamTraits<cc::DrawQuad>::Read(m, iter, p) &&
+bool ParamTraits<viz::YUVVideoDrawQuad>::Read(const base::Pickle* m,
+ base::PickleIterator* iter,
+ param_type* p) {
+ return ParamTraits<viz::DrawQuad>::Read(m, iter, p) &&
ReadParam(m, iter, &p->ya_tex_coord_rect) &&
ReadParam(m, iter, &p->uv_tex_coord_rect) &&
ReadParam(m, iter, &p->ya_tex_size) &&
@@ -998,14 +894,14 @@ bool ParamTraits<cc::YUVVideoDrawQuad>::Read(const base::Pickle* m,
ReadParam(m, iter, &p->resource_offset) &&
ReadParam(m, iter, &p->resource_multiplier) &&
ReadParam(m, iter, &p->bits_per_channel) &&
- p->bits_per_channel >= cc::YUVVideoDrawQuad::kMinBitsPerChannel &&
- p->bits_per_channel <= cc::YUVVideoDrawQuad::kMaxBitsPerChannel;
+ p->bits_per_channel >= viz::YUVVideoDrawQuad::kMinBitsPerChannel &&
+ p->bits_per_channel <= viz::YUVVideoDrawQuad::kMaxBitsPerChannel;
}
-void ParamTraits<cc::YUVVideoDrawQuad>::Log(const param_type& p,
- std::string* l) {
+void ParamTraits<viz::YUVVideoDrawQuad>::Log(const param_type& p,
+ std::string* l) {
l->append("(");
- ParamTraits<cc::DrawQuad>::Log(p, l);
+ ParamTraits<viz::DrawQuad>::Log(p, l);
l->append(", ");
LogParam(p.ya_tex_coord_rect, l);
l->append(", ");
@@ -1027,12 +923,6 @@ void ParamTraits<cc::YUVVideoDrawQuad>::Log(const param_type& p,
l->append("])");
}
-void ParamTraits<viz::BeginFrameAck>::GetSize(base::PickleSizer* s,
- const param_type& p) {
- GetParamSize(s, p.sequence_number);
- GetParamSize(s, p.source_id);
-}
-
void ParamTraits<viz::BeginFrameAck>::Write(base::Pickle* m,
const param_type& p) {
m->WriteUInt64(p.sequence_number);
@@ -1058,13 +948,6 @@ void ParamTraits<viz::BeginFrameAck>::Log(const param_type& p, std::string* l) {
} // namespace IPC
-// Generate param traits size methods.
-#include "ipc/param_traits_size_macros.h"
-namespace IPC {
-#undef CC_IPC_CC_PARAM_TRAITS_MACROS_H_
-#include "cc/ipc/cc_param_traits_macros.h"
-}
-
// Generate param traits write methods.
#include "ipc/param_traits_write_macros.h"
namespace IPC {
diff --git a/chromium/cc/ipc/cc_param_traits.h b/chromium/cc/ipc/cc_param_traits.h
index a8ce4fa62e9..0adce4c8ad5 100644
--- a/chromium/cc/ipc/cc_param_traits.h
+++ b/chromium/cc/ipc/cc_param_traits.h
@@ -10,10 +10,10 @@
#include "cc/base/filter_operation.h"
#include "cc/ipc/cc_ipc_export.h"
#include "cc/ipc/cc_param_traits_macros.h"
-#include "cc/output/compositor_frame.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/stream_video_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
+#include "components/viz/common/quads/compositor_frame.h"
+#include "components/viz/common/quads/draw_quad.h"
+#include "components/viz/common/quads/stream_video_draw_quad.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
#include "gpu/ipc/common/gpu_command_buffer_traits.h"
#include "ipc/ipc_message_macros.h"
@@ -26,7 +26,6 @@ namespace IPC {
template <>
struct ParamTraits<cc::FilterOperation> {
typedef cc::FilterOperation param_type;
- static void GetSize(base::PickleSizer* s, const param_type& p);
static void Write(base::Pickle* m, const param_type& p);
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
@@ -37,7 +36,6 @@ struct ParamTraits<cc::FilterOperation> {
template <>
struct ParamTraits<cc::FilterOperations> {
typedef cc::FilterOperations param_type;
- static void GetSize(base::PickleSizer* s, const param_type& p);
static void Write(base::Pickle* m, const param_type& p);
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
@@ -46,9 +44,8 @@ struct ParamTraits<cc::FilterOperations> {
};
template <>
-struct ParamTraits<sk_sp<SkImageFilter>> {
+struct CC_IPC_EXPORT ParamTraits<sk_sp<SkImageFilter>> {
typedef sk_sp<SkImageFilter> param_type;
- static void GetSize(base::PickleSizer* s, const param_type& p);
static void Write(base::Pickle* m, const param_type& p);
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
@@ -57,8 +54,8 @@ struct ParamTraits<sk_sp<SkImageFilter>> {
};
template <>
-struct CC_IPC_EXPORT ParamTraits<cc::RenderPass> {
- typedef cc::RenderPass param_type;
+struct CC_IPC_EXPORT ParamTraits<viz::RenderPass> {
+ typedef viz::RenderPass param_type;
static void Write(base::Pickle* m, const param_type& p);
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
@@ -69,7 +66,6 @@ struct CC_IPC_EXPORT ParamTraits<cc::RenderPass> {
template <>
struct CC_IPC_EXPORT ParamTraits<viz::FrameSinkId> {
typedef viz::FrameSinkId param_type;
- static void GetSize(base::PickleSizer* s, const param_type& p);
static void Write(base::Pickle* m, const param_type& p);
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
@@ -80,7 +76,6 @@ struct CC_IPC_EXPORT ParamTraits<viz::FrameSinkId> {
template <>
struct CC_IPC_EXPORT ParamTraits<viz::LocalSurfaceId> {
typedef viz::LocalSurfaceId param_type;
- static void GetSize(base::PickleSizer* s, const param_type& p);
static void Write(base::Pickle* m, const param_type& p);
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
@@ -91,7 +86,6 @@ struct CC_IPC_EXPORT ParamTraits<viz::LocalSurfaceId> {
template <>
struct CC_IPC_EXPORT ParamTraits<viz::SurfaceId> {
typedef viz::SurfaceId param_type;
- static void GetSize(base::PickleSizer* s, const param_type& p);
static void Write(base::Pickle* m, const param_type& p);
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
@@ -102,7 +96,6 @@ struct CC_IPC_EXPORT ParamTraits<viz::SurfaceId> {
template <>
struct CC_IPC_EXPORT ParamTraits<viz::SurfaceInfo> {
typedef viz::SurfaceInfo param_type;
- static void GetSize(base::PickleSizer* s, const param_type& p);
static void Write(base::Pickle* m, const param_type& p);
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
@@ -111,8 +104,8 @@ struct CC_IPC_EXPORT ParamTraits<viz::SurfaceInfo> {
};
template <>
-struct CC_IPC_EXPORT ParamTraits<cc::CompositorFrame> {
- typedef cc::CompositorFrame param_type;
+struct CC_IPC_EXPORT ParamTraits<viz::CompositorFrame> {
+ typedef viz::CompositorFrame param_type;
static void Write(base::Pickle* m, const param_type& p);
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
@@ -121,9 +114,8 @@ struct CC_IPC_EXPORT ParamTraits<cc::CompositorFrame> {
};
template <>
-struct CC_IPC_EXPORT ParamTraits<cc::DrawQuad::Resources> {
- typedef cc::DrawQuad::Resources param_type;
- static void GetSize(base::PickleSizer* s, const param_type& p);
+struct CC_IPC_EXPORT ParamTraits<viz::DrawQuad::Resources> {
+ typedef viz::DrawQuad::Resources param_type;
static void Write(base::Pickle* m, const param_type& p);
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
@@ -132,9 +124,8 @@ struct CC_IPC_EXPORT ParamTraits<cc::DrawQuad::Resources> {
};
template <>
-struct CC_IPC_EXPORT ParamTraits<cc::YUVVideoDrawQuad> {
- typedef cc::YUVVideoDrawQuad param_type;
- static void GetSize(base::PickleSizer* s, const param_type& p);
+struct CC_IPC_EXPORT ParamTraits<viz::YUVVideoDrawQuad> {
+ typedef viz::YUVVideoDrawQuad param_type;
static void Write(base::Pickle* m, const param_type& p);
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
@@ -145,7 +136,6 @@ struct CC_IPC_EXPORT ParamTraits<cc::YUVVideoDrawQuad> {
template <>
struct CC_IPC_EXPORT ParamTraits<viz::BeginFrameAck> {
typedef viz::BeginFrameAck param_type;
- static void GetSize(base::PickleSizer* s, const param_type& p);
static void Write(base::Pickle* m, const param_type& p);
static bool Read(const base::Pickle* m,
base::PickleIterator* iter,
diff --git a/chromium/cc/ipc/cc_param_traits_macros.h b/chromium/cc/ipc/cc_param_traits_macros.h
index 4192e3c2e58..0496ee6ed45 100644
--- a/chromium/cc/ipc/cc_param_traits_macros.h
+++ b/chromium/cc/ipc/cc_param_traits_macros.h
@@ -6,17 +6,18 @@
#define CC_IPC_CC_PARAM_TRAITS_MACROS_H_
#include "cc/base/filter_operation.h"
-#include "cc/output/compositor_frame.h"
-#include "cc/quads/debug_border_draw_quad.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/render_pass.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/stream_video_draw_quad.h"
-#include "cc/quads/surface_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
-#include "cc/quads/tile_draw_quad.h"
-#include "cc/quads/yuv_video_draw_quad.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"
+#include "components/viz/common/quads/compositor_frame.h"
+#include "components/viz/common/quads/debug_border_draw_quad.h"
+#include "components/viz/common/quads/draw_quad.h"
+#include "components/viz/common/quads/render_pass.h"
+#include "components/viz/common/quads/render_pass_draw_quad.h"
+#include "components/viz/common/quads/solid_color_draw_quad.h"
+#include "components/viz/common/quads/stream_video_draw_quad.h"
+#include "components/viz/common/quads/surface_draw_quad.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
+#include "components/viz/common/quads/tile_draw_quad.h"
+#include "components/viz/common/quads/yuv_video_draw_quad.h"
#include "components/viz/common/resources/resource_format.h"
#include "components/viz/common/resources/returned_resource.h"
#include "components/viz/common/resources/transferable_resource.h"
@@ -31,7 +32,7 @@
#undef IPC_MESSAGE_EXPORT
#define IPC_MESSAGE_EXPORT CC_IPC_EXPORT
-IPC_ENUM_TRAITS_MAX_VALUE(cc::DrawQuad::Material, cc::DrawQuad::MATERIAL_LAST)
+IPC_ENUM_TRAITS_MAX_VALUE(viz::DrawQuad::Material, viz::DrawQuad::MATERIAL_LAST)
IPC_ENUM_TRAITS_MAX_VALUE(cc::FilterOperation::FilterType,
cc::FilterOperation::FILTER_TYPE_LAST)
// TODO(wutao): This trait belongs with skia code.
@@ -41,17 +42,17 @@ IPC_ENUM_TRAITS_MAX_VALUE(viz::ResourceFormat, viz::RESOURCE_FORMAT_MAX)
// TODO(fsamuel): This trait belongs with skia code.
IPC_ENUM_TRAITS_MAX_VALUE(SkBlendMode, SkBlendMode::kLastMode)
-IPC_ENUM_TRAITS_MAX_VALUE(cc::YUVVideoDrawQuad::ColorSpace,
- cc::YUVVideoDrawQuad::COLOR_SPACE_LAST)
-IPC_ENUM_TRAITS_MAX_VALUE(cc::SurfaceDrawQuadType,
- cc::SurfaceDrawQuadType::LAST)
+IPC_ENUM_TRAITS_MAX_VALUE(viz::YUVVideoDrawQuad::ColorSpace,
+ viz::YUVVideoDrawQuad::COLOR_SPACE_LAST)
+IPC_ENUM_TRAITS_MAX_VALUE(viz::SurfaceDrawQuadType,
+ viz::SurfaceDrawQuadType::LAST)
IPC_STRUCT_TRAITS_BEGIN(viz::SurfaceSequence)
IPC_STRUCT_TRAITS_MEMBER(frame_sink_id)
IPC_STRUCT_TRAITS_MEMBER(sequence)
IPC_STRUCT_TRAITS_END()
-IPC_STRUCT_TRAITS_BEGIN(cc::DrawQuad)
+IPC_STRUCT_TRAITS_BEGIN(viz::DrawQuad)
IPC_STRUCT_TRAITS_MEMBER(material)
IPC_STRUCT_TRAITS_MEMBER(rect)
IPC_STRUCT_TRAITS_MEMBER(visible_rect)
@@ -59,46 +60,48 @@ IPC_STRUCT_TRAITS_BEGIN(cc::DrawQuad)
IPC_STRUCT_TRAITS_MEMBER(resources)
IPC_STRUCT_TRAITS_END()
-IPC_STRUCT_TRAITS_BEGIN(cc::DebugBorderDrawQuad)
- IPC_STRUCT_TRAITS_PARENT(cc::DrawQuad)
+IPC_STRUCT_TRAITS_BEGIN(viz::DebugBorderDrawQuad)
+ IPC_STRUCT_TRAITS_PARENT(viz::DrawQuad)
IPC_STRUCT_TRAITS_MEMBER(color)
IPC_STRUCT_TRAITS_MEMBER(width)
IPC_STRUCT_TRAITS_END()
-IPC_STRUCT_TRAITS_BEGIN(cc::RenderPassDrawQuad)
- IPC_STRUCT_TRAITS_PARENT(cc::DrawQuad)
+IPC_STRUCT_TRAITS_BEGIN(viz::RenderPassDrawQuad)
+ IPC_STRUCT_TRAITS_PARENT(viz::DrawQuad)
IPC_STRUCT_TRAITS_MEMBER(render_pass_id)
IPC_STRUCT_TRAITS_MEMBER(mask_uv_rect)
IPC_STRUCT_TRAITS_MEMBER(mask_texture_size)
IPC_STRUCT_TRAITS_MEMBER(filters_scale)
IPC_STRUCT_TRAITS_MEMBER(filters_origin)
IPC_STRUCT_TRAITS_MEMBER(tex_coord_rect)
+ IPC_STRUCT_TRAITS_MEMBER(force_anti_aliasing_off)
IPC_STRUCT_TRAITS_END()
-IPC_STRUCT_TRAITS_BEGIN(cc::SolidColorDrawQuad)
- IPC_STRUCT_TRAITS_PARENT(cc::DrawQuad)
+IPC_STRUCT_TRAITS_BEGIN(viz::SolidColorDrawQuad)
+ IPC_STRUCT_TRAITS_PARENT(viz::DrawQuad)
IPC_STRUCT_TRAITS_MEMBER(color)
IPC_STRUCT_TRAITS_MEMBER(force_anti_aliasing_off)
IPC_STRUCT_TRAITS_END()
-IPC_STRUCT_TRAITS_BEGIN(cc::StreamVideoDrawQuad)
- IPC_STRUCT_TRAITS_PARENT(cc::DrawQuad)
+IPC_STRUCT_TRAITS_BEGIN(viz::StreamVideoDrawQuad)
+ IPC_STRUCT_TRAITS_PARENT(viz::DrawQuad)
IPC_STRUCT_TRAITS_MEMBER(overlay_resources)
IPC_STRUCT_TRAITS_MEMBER(matrix)
IPC_STRUCT_TRAITS_END()
-IPC_STRUCT_TRAITS_BEGIN(cc::StreamVideoDrawQuad::OverlayResources)
+IPC_STRUCT_TRAITS_BEGIN(viz::StreamVideoDrawQuad::OverlayResources)
IPC_STRUCT_TRAITS_MEMBER(size_in_pixels)
IPC_STRUCT_TRAITS_END()
-IPC_STRUCT_TRAITS_BEGIN(cc::SurfaceDrawQuad)
- IPC_STRUCT_TRAITS_PARENT(cc::DrawQuad)
+IPC_STRUCT_TRAITS_BEGIN(viz::SurfaceDrawQuad)
+ IPC_STRUCT_TRAITS_PARENT(viz::DrawQuad)
IPC_STRUCT_TRAITS_MEMBER(surface_id)
IPC_STRUCT_TRAITS_MEMBER(surface_draw_quad_type)
+ IPC_STRUCT_TRAITS_MEMBER(default_background_color)
IPC_STRUCT_TRAITS_END()
-IPC_STRUCT_TRAITS_BEGIN(cc::TextureDrawQuad)
- IPC_STRUCT_TRAITS_PARENT(cc::DrawQuad)
+IPC_STRUCT_TRAITS_BEGIN(viz::TextureDrawQuad)
+ IPC_STRUCT_TRAITS_PARENT(viz::DrawQuad)
IPC_STRUCT_TRAITS_MEMBER(overlay_resources)
IPC_STRUCT_TRAITS_MEMBER(premultiplied_alpha)
IPC_STRUCT_TRAITS_MEMBER(uv_top_left)
@@ -113,16 +116,17 @@ IPC_STRUCT_TRAITS_BEGIN(cc::TextureDrawQuad)
IPC_STRUCT_TRAITS_MEMBER(secure_output_only)
IPC_STRUCT_TRAITS_END()
-IPC_STRUCT_TRAITS_BEGIN(cc::TextureDrawQuad::OverlayResources)
+IPC_STRUCT_TRAITS_BEGIN(viz::TextureDrawQuad::OverlayResources)
IPC_STRUCT_TRAITS_MEMBER(size_in_pixels)
IPC_STRUCT_TRAITS_END()
-IPC_STRUCT_TRAITS_BEGIN(cc::TileDrawQuad)
- IPC_STRUCT_TRAITS_PARENT(cc::DrawQuad)
+IPC_STRUCT_TRAITS_BEGIN(viz::TileDrawQuad)
+ IPC_STRUCT_TRAITS_PARENT(viz::DrawQuad)
IPC_STRUCT_TRAITS_MEMBER(tex_coord_rect)
IPC_STRUCT_TRAITS_MEMBER(texture_size)
IPC_STRUCT_TRAITS_MEMBER(swizzle_contents)
IPC_STRUCT_TRAITS_MEMBER(nearest_neighbor)
+ IPC_STRUCT_TRAITS_MEMBER(force_anti_aliasing_off)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(viz::SharedQuadState)
@@ -161,7 +165,7 @@ IPC_STRUCT_TRAITS_BEGIN(viz::ReturnedResource)
IPC_STRUCT_TRAITS_MEMBER(lost)
IPC_STRUCT_TRAITS_END()
-IPC_STRUCT_TRAITS_BEGIN(cc::Selection<gfx::SelectionBound>)
+IPC_STRUCT_TRAITS_BEGIN(viz::Selection<gfx::SelectionBound>)
IPC_STRUCT_TRAITS_MEMBER(start)
IPC_STRUCT_TRAITS_MEMBER(end)
IPC_STRUCT_TRAITS_END()
@@ -178,7 +182,7 @@ IPC_STRUCT_TRAITS_BEGIN(viz::BeginFrameArgs)
IPC_STRUCT_TRAITS_MEMBER(type)
IPC_STRUCT_TRAITS_END()
-IPC_STRUCT_TRAITS_BEGIN(cc::CompositorFrameMetadata)
+IPC_STRUCT_TRAITS_BEGIN(viz::CompositorFrameMetadata)
IPC_STRUCT_TRAITS_MEMBER(device_scale_factor)
IPC_STRUCT_TRAITS_MEMBER(root_scroll_offset)
IPC_STRUCT_TRAITS_MEMBER(page_scale_factor)
diff --git a/chromium/cc/ipc/cc_param_traits_unittest.cc b/chromium/cc/ipc/cc_param_traits_unittest.cc
index 05c3f5df2ba..2d83b1d3ffa 100644
--- a/chromium/cc/ipc/cc_param_traits_unittest.cc
+++ b/chromium/cc/ipc/cc_param_traits_unittest.cc
@@ -10,9 +10,10 @@
#include "base/macros.h"
#include "build/build_config.h"
#include "cc/ipc/cc_param_traits.h"
-#include "cc/output/compositor_frame.h"
-#include "cc/quads/picture_draw_quad.h"
-#include "cc/quads/render_pass_draw_quad.h"
+#include "cc/resources/resource_provider.h"
+#include "components/viz/common/quads/compositor_frame.h"
+#include "components/viz/common/quads/picture_draw_quad.h"
+#include "components/viz/common/quads/render_pass_draw_quad.h"
#include "ipc/ipc_message.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/effects/SkBlurImageFilter.h"
@@ -21,25 +22,25 @@
#include "base/file_descriptor_posix.h"
#endif
-using cc::CompositorFrame;
-using cc::DebugBorderDrawQuad;
-using cc::DrawQuad;
+using viz::CompositorFrame;
using cc::FilterOperation;
using cc::FilterOperations;
-using cc::PictureDrawQuad;
-using cc::RenderPass;
-using cc::RenderPassDrawQuad;
using cc::ResourceProvider;
-using cc::SolidColorDrawQuad;
-using cc::SurfaceDrawQuad;
-using cc::TextureDrawQuad;
-using cc::TileDrawQuad;
-using cc::StreamVideoDrawQuad;
-using cc::YUVVideoDrawQuad;
using gfx::Transform;
+using viz::DebugBorderDrawQuad;
+using viz::DrawQuad;
+using viz::PictureDrawQuad;
+using viz::RenderPass;
+using viz::RenderPassDrawQuad;
using viz::ResourceId;
using viz::SharedQuadState;
+using viz::SolidColorDrawQuad;
+using viz::StreamVideoDrawQuad;
+using viz::SurfaceDrawQuad;
+using viz::TextureDrawQuad;
+using viz::TileDrawQuad;
using viz::TransferableResource;
+using viz::YUVVideoDrawQuad;
namespace content {
namespace {
@@ -153,6 +154,7 @@ class CCParamTraitsTest : public testing::Test {
EXPECT_EQ(a->filters_scale, b->filters_scale);
EXPECT_EQ(a->filters_origin, b->filters_origin);
EXPECT_EQ(a->tex_coord_rect, b->tex_coord_rect);
+ EXPECT_EQ(a->force_anti_aliasing_off, b->force_anti_aliasing_off);
}
void Compare(const SolidColorDrawQuad* a, const SolidColorDrawQuad* b) {
@@ -168,6 +170,9 @@ class CCParamTraitsTest : public testing::Test {
void Compare(const SurfaceDrawQuad* a, const SurfaceDrawQuad* b) {
EXPECT_EQ(a->surface_id, b->surface_id);
+ EXPECT_EQ(a->surface_draw_quad_type, b->surface_draw_quad_type);
+ EXPECT_EQ(a->fallback_quad, b->fallback_quad);
+ EXPECT_EQ(a->default_background_color, b->default_background_color);
}
void Compare(const TextureDrawQuad* a, const TextureDrawQuad* b) {
@@ -192,6 +197,7 @@ class CCParamTraitsTest : public testing::Test {
EXPECT_EQ(a->texture_size, b->texture_size);
EXPECT_EQ(a->swizzle_contents, b->swizzle_contents);
EXPECT_EQ(a->nearest_neighbor, b->nearest_neighbor);
+ EXPECT_EQ(a->force_anti_aliasing_off, b->force_anti_aliasing_off);
}
void Compare(const YUVVideoDrawQuad* a, const YUVVideoDrawQuad* b) {
@@ -300,32 +306,34 @@ TEST_F(CCParamTraitsTest, AllQuads) {
FilterOperation::CreateBrightnessFilter(arbitrary_float2));
std::unique_ptr<RenderPass> child_pass_in = RenderPass::Create();
- child_pass_in->SetAll(child_id, arbitrary_rect2, arbitrary_rect3,
- arbitrary_matrix2, arbitrary_filters1,
- arbitrary_filters2, arbitrary_color_space,
- arbitrary_bool2, arbitrary_bool3, arbitrary_bool4);
+ child_pass_in->SetAll(
+ child_id, arbitrary_rect2, arbitrary_rect3, arbitrary_matrix2,
+ arbitrary_filters1, arbitrary_filters2, arbitrary_color_space,
+ arbitrary_bool2, arbitrary_bool3, arbitrary_bool4, arbitrary_bool5);
std::unique_ptr<RenderPass> child_pass_cmp = RenderPass::Create();
- child_pass_cmp->SetAll(child_id, arbitrary_rect2, arbitrary_rect3,
- arbitrary_matrix2, arbitrary_filters1,
- arbitrary_filters2, arbitrary_color_space,
- arbitrary_bool2, arbitrary_bool3, arbitrary_bool4);
+ child_pass_cmp->SetAll(
+ child_id, arbitrary_rect2, arbitrary_rect3, arbitrary_matrix2,
+ arbitrary_filters1, arbitrary_filters2, arbitrary_color_space,
+ arbitrary_bool2, arbitrary_bool3, arbitrary_bool4, arbitrary_bool5);
std::unique_ptr<RenderPass> pass_in = RenderPass::Create();
pass_in->SetAll(root_id, arbitrary_rect1, arbitrary_rect2, arbitrary_matrix1,
arbitrary_filters2, arbitrary_filters1, arbitrary_color_space,
- arbitrary_bool1, arbitrary_bool2, arbitrary_bool3);
+ arbitrary_bool1, arbitrary_bool2, arbitrary_bool3,
+ arbitrary_bool4);
SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
shared_state1_in->SetAll(arbitrary_matrix1, arbitrary_rect1, arbitrary_rect1,
- arbitrary_rect2, arbitrary_bool1, arbitrary_float1,
- arbitrary_blend_mode1, arbitrary_context_id1);
+ arbitrary_rect2, arbitrary_bool1, arbitrary_bool2,
+ arbitrary_float1, arbitrary_blend_mode1,
+ arbitrary_context_id1);
std::unique_ptr<RenderPass> pass_cmp = RenderPass::Create();
pass_cmp->SetAll(root_id, arbitrary_rect1, arbitrary_rect2, arbitrary_matrix1,
arbitrary_filters2, arbitrary_filters1,
arbitrary_color_space, arbitrary_bool1, arbitrary_bool2,
- arbitrary_bool3);
+ arbitrary_bool3, arbitrary_bool4);
SharedQuadState* shared_state1_cmp =
pass_cmp->CreateAndAppendSharedQuadState();
@@ -340,8 +348,9 @@ TEST_F(CCParamTraitsTest, AllQuads) {
SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
shared_state2_in->SetAll(arbitrary_matrix2, arbitrary_rect2, arbitrary_rect2,
- arbitrary_rect3, arbitrary_bool1, arbitrary_float2,
- arbitrary_blend_mode2, arbitrary_context_id2);
+ arbitrary_rect3, arbitrary_bool1, arbitrary_bool1,
+ arbitrary_float2, arbitrary_blend_mode2,
+ arbitrary_context_id2);
SharedQuadState* shared_state2_cmp =
pass_cmp->CreateAndAppendSharedQuadState();
*shared_state2_cmp = *shared_state2_in;
@@ -352,20 +361,20 @@ TEST_F(CCParamTraitsTest, AllQuads) {
arbitrary_rect1_inside_rect1, arbitrary_bool1, child_id,
arbitrary_resourceid2, arbitrary_rectf1,
arbitrary_size1, arbitrary_vector2df2,
- arbitrary_pointf2, arbitrary_rectf1);
+ arbitrary_pointf2, arbitrary_rectf1, arbitrary_bool2);
pass_cmp->CopyFromAndAppendRenderPassDrawQuad(renderpass_in,
renderpass_in->render_pass_id);
SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
shared_state3_in->SetAll(arbitrary_matrix1, arbitrary_rect3, arbitrary_rect3,
- arbitrary_rect1, arbitrary_bool1, arbitrary_float3,
- arbitrary_blend_mode3, arbitrary_context_id3);
+ arbitrary_rect1, arbitrary_bool1, arbitrary_bool2,
+ arbitrary_float3, arbitrary_blend_mode3,
+ arbitrary_context_id3);
SharedQuadState* shared_state3_cmp =
pass_cmp->CreateAndAppendSharedQuadState();
*shared_state3_cmp = *shared_state3_in;
- SolidColorDrawQuad* solidcolor_in =
- pass_in->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ auto* solidcolor_in = pass_in->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
solidcolor_in->SetAll(shared_state3_in, arbitrary_rect3,
arbitrary_rect2_inside_rect3, arbitrary_bool1,
arbitrary_color, arbitrary_bool2);
@@ -386,8 +395,8 @@ TEST_F(CCParamTraitsTest, AllQuads) {
pass_in->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
surface_in->SetAll(shared_state3_in, arbitrary_rect2,
arbitrary_rect1_inside_rect2, arbitrary_bool1,
- arbitrary_surface_id, cc::SurfaceDrawQuadType::PRIMARY,
- nullptr);
+ arbitrary_surface_id, viz::SurfaceDrawQuadType::PRIMARY,
+ SK_ColorWHITE, nullptr);
pass_cmp->CopyFromAndAppendDrawQuad(surface_in);
TextureDrawQuad* texture_in =
@@ -403,7 +412,7 @@ TEST_F(CCParamTraitsTest, AllQuads) {
tile_in->SetAll(shared_state3_in, arbitrary_rect2,
arbitrary_rect1_inside_rect2, arbitrary_bool1,
arbitrary_resourceid3, arbitrary_rectf1, arbitrary_size1,
- arbitrary_bool2, arbitrary_bool3);
+ arbitrary_bool2, arbitrary_bool3, arbitrary_bool4);
pass_cmp->CopyFromAndAppendDrawQuad(tile_in);
YUVVideoDrawQuad* yuvvideo_in =
@@ -424,10 +433,9 @@ TEST_F(CCParamTraitsTest, AllQuads) {
Compare(pass_cmp.get(), pass_in.get());
ASSERT_EQ(3u, pass_in->shared_quad_state_list.size());
ASSERT_EQ(8u, pass_in->quad_list.size());
- for (cc::SharedQuadStateList::ConstIterator
- cmp_iterator = pass_cmp->shared_quad_state_list.begin(),
- in_iterator = pass_in->shared_quad_state_list.begin();
- in_iterator != pass_in->shared_quad_state_list.end();
+ for (auto cmp_iterator = pass_cmp->shared_quad_state_list.cbegin(),
+ in_iterator = pass_in->shared_quad_state_list.cbegin();
+ in_iterator != pass_in->shared_quad_state_list.cend();
++cmp_iterator, ++in_iterator) {
Compare(*cmp_iterator, *in_iterator);
}
@@ -469,10 +477,9 @@ TEST_F(CCParamTraitsTest, AllQuads) {
Compare(pass_cmp.get(), pass_out.get());
ASSERT_EQ(3u, pass_out->shared_quad_state_list.size());
ASSERT_EQ(8u, pass_out->quad_list.size());
- for (cc::SharedQuadStateList::ConstIterator
- cmp_iterator = pass_cmp->shared_quad_state_list.begin(),
- out_iterator = pass_out->shared_quad_state_list.begin();
- out_iterator != pass_out->shared_quad_state_list.end();
+ for (auto cmp_iterator = pass_cmp->shared_quad_state_list.cbegin(),
+ out_iterator = pass_out->shared_quad_state_list.cbegin();
+ out_iterator != pass_out->shared_quad_state_list.cend();
++cmp_iterator, ++out_iterator) {
Compare(*cmp_iterator, *out_iterator);
}
@@ -496,41 +503,44 @@ TEST_F(CCParamTraitsTest, UnusedSharedQuadStates) {
std::unique_ptr<RenderPass> pass_in = RenderPass::Create();
pass_in->SetAll(1, gfx::Rect(100, 100), gfx::Rect(), gfx::Transform(),
FilterOperations(), FilterOperations(),
- gfx::ColorSpace::CreateSRGB(), false, false, false);
+ gfx::ColorSpace::CreateSRGB(), false, false, false, false);
// The first SharedQuadState is used.
SharedQuadState* shared_state1_in = pass_in->CreateAndAppendSharedQuadState();
shared_state1_in->SetAll(gfx::Transform(), gfx::Rect(1, 1), gfx::Rect(),
- gfx::Rect(), false, 1.f, SkBlendMode::kSrcOver, 0);
+ gfx::Rect(), false, true, 1.f, SkBlendMode::kSrcOver,
+ 0);
- SolidColorDrawQuad* quad1 =
- pass_in->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ auto* quad1 = pass_in->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
quad1->SetAll(shared_state1_in, gfx::Rect(10, 10), gfx::Rect(10, 10), false,
SK_ColorRED, false);
// The second and third SharedQuadStates are not used.
SharedQuadState* shared_state2_in = pass_in->CreateAndAppendSharedQuadState();
shared_state2_in->SetAll(gfx::Transform(), gfx::Rect(2, 2), gfx::Rect(),
- gfx::Rect(), false, 1.f, SkBlendMode::kSrcOver, 0);
+ gfx::Rect(), false, true, 1.f, SkBlendMode::kSrcOver,
+ 0);
SharedQuadState* shared_state3_in = pass_in->CreateAndAppendSharedQuadState();
shared_state3_in->SetAll(gfx::Transform(), gfx::Rect(3, 3), gfx::Rect(),
- gfx::Rect(), false, 1.f, SkBlendMode::kSrcOver, 0);
+ gfx::Rect(), false, true, 1.f, SkBlendMode::kSrcOver,
+ 0);
// The fourth SharedQuadState is used.
SharedQuadState* shared_state4_in = pass_in->CreateAndAppendSharedQuadState();
shared_state4_in->SetAll(gfx::Transform(), gfx::Rect(4, 4), gfx::Rect(),
- gfx::Rect(), false, 1.f, SkBlendMode::kSrcOver, 0);
+ gfx::Rect(), false, true, 1.f, SkBlendMode::kSrcOver,
+ 0);
- SolidColorDrawQuad* quad2 =
- pass_in->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ auto* quad2 = pass_in->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
quad2->SetAll(shared_state4_in, gfx::Rect(10, 10), gfx::Rect(10, 10), false,
SK_ColorRED, false);
// The fifth is not used again.
SharedQuadState* shared_state5_in = pass_in->CreateAndAppendSharedQuadState();
shared_state5_in->SetAll(gfx::Transform(), gfx::Rect(5, 5), gfx::Rect(),
- gfx::Rect(), false, 1.f, SkBlendMode::kSrcOver, 0);
+ gfx::Rect(), false, true, 1.f, SkBlendMode::kSrcOver,
+ 0);
// 5 SharedQuadStates go in.
ASSERT_EQ(5u, pass_in->shared_quad_state_list.size());
diff --git a/chromium/cc/ipc/cc_serialization_perftest.cc b/chromium/cc/ipc/cc_serialization_perftest.cc
index 9a92b59e40a..3f4c149c440 100644
--- a/chromium/cc/ipc/cc_serialization_perftest.cc
+++ b/chromium/cc/ipc/cc_serialization_perftest.cc
@@ -7,8 +7,8 @@
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/test_suite.h"
#include "cc/ipc/cc_param_traits.h"
-#include "cc/output/compositor_frame.h"
-#include "cc/quads/picture_draw_quad.h"
+#include "components/viz/common/quads/compositor_frame.h"
+#include "components/viz/common/quads/picture_draw_quad.h"
#include "gpu/ipc/common/mailbox_holder_struct_traits.h"
#include "gpu/ipc/common/mailbox_struct_traits.h"
#include "gpu/ipc/common/sync_token_struct_traits.h"
@@ -40,19 +40,22 @@ enum class UseSingleSharedQuadState { YES, NO };
class CCSerializationPerfTest : public testing::Test {
protected:
- static bool ReadMessage(const IPC::Message* msg, CompositorFrame* frame) {
+ static void ReadMessage(const IPC::Message* msg,
+ viz::CompositorFrame* frame) {
base::PickleIterator iter(*msg);
- return IPC::ParamTraits<CompositorFrame>::Read(msg, &iter, frame);
+ bool success =
+ IPC::ParamTraits<viz::CompositorFrame>::Read(msg, &iter, frame);
+ CHECK(success);
}
static void RunDeserializationTestParamTraits(
const std::string& test_name,
- const CompositorFrame& frame,
+ const viz::CompositorFrame& frame,
UseSingleSharedQuadState single_sqs) {
IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
- IPC::ParamTraits<CompositorFrame>::Write(&msg, frame);
+ IPC::ParamTraits<viz::CompositorFrame>::Write(&msg, frame);
for (int i = 0; i < kNumWarmupRuns; ++i) {
- CompositorFrame compositor_frame;
+ viz::CompositorFrame compositor_frame;
ReadMessage(&msg, &compositor_frame);
}
@@ -64,7 +67,7 @@ class CCSerializationPerfTest : public testing::Test {
size_t count = 0;
while (start < end) {
for (int i = 0; i < kTimeCheckInterval; ++i) {
- CompositorFrame compositor_frame;
+ viz::CompositorFrame compositor_frame;
ReadMessage(&msg, &compositor_frame);
now = base::TimeTicks::Now();
// We don't count iterations after the end time.
@@ -93,11 +96,11 @@ class CCSerializationPerfTest : public testing::Test {
static void RunSerializationTestParamTraits(
const std::string& test_name,
- const CompositorFrame& frame,
+ const viz::CompositorFrame& frame,
UseSingleSharedQuadState single_sqs) {
for (int i = 0; i < kNumWarmupRuns; ++i) {
IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
- IPC::ParamTraits<CompositorFrame>::Write(&msg, frame);
+ IPC::ParamTraits<viz::CompositorFrame>::Write(&msg, frame);
}
base::TimeTicks start = base::TimeTicks::Now();
@@ -109,7 +112,7 @@ class CCSerializationPerfTest : public testing::Test {
while (start < end) {
for (int i = 0; i < kTimeCheckInterval; ++i) {
IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL);
- IPC::ParamTraits<CompositorFrame>::Write(&msg, frame);
+ IPC::ParamTraits<viz::CompositorFrame>::Write(&msg, frame);
now = base::TimeTicks::Now();
// We don't count iterations after the end time.
if (now < end)
@@ -137,12 +140,12 @@ class CCSerializationPerfTest : public testing::Test {
static void RunDeserializationTestStructTraits(
const std::string& test_name,
- const CompositorFrame& frame,
+ const viz::CompositorFrame& frame,
UseSingleSharedQuadState single_sqs) {
mojo::Message message =
viz::mojom::CompositorFrame::SerializeAsMessage(&frame);
for (int i = 0; i < kNumWarmupRuns; ++i) {
- CompositorFrame compositor_frame;
+ viz::CompositorFrame compositor_frame;
viz::mojom::CompositorFrame::Deserialize(
message.payload(), message.payload_num_bytes(), &compositor_frame);
}
@@ -155,7 +158,7 @@ class CCSerializationPerfTest : public testing::Test {
size_t count = 0;
while (start < end) {
for (int i = 0; i < kTimeCheckInterval; ++i) {
- CompositorFrame compositor_frame;
+ viz::CompositorFrame compositor_frame;
viz::mojom::CompositorFrame::Deserialize(
message.payload(), message.payload_num_bytes(), &compositor_frame);
now = base::TimeTicks::Now();
@@ -186,7 +189,7 @@ class CCSerializationPerfTest : public testing::Test {
static void RunSerializationTestStructTraits(
const std::string& test_name,
- const CompositorFrame& frame,
+ const viz::CompositorFrame& frame,
UseSingleSharedQuadState single_sqs) {
for (int i = 0; i < kNumWarmupRuns; ++i) {
mojo::Message message =
@@ -229,7 +232,8 @@ class CCSerializationPerfTest : public testing::Test {
}
static void RunComplexCompositorFrameTest(const std::string& test_name) {
- CompositorFrame frame;
+ viz::CompositorFrame frame;
+ frame.metadata.begin_frame_ack = viz::BeginFrameAck(0, 1, true);
std::vector<viz::TransferableResource>& resource_list = frame.resource_list;
for (uint32_t i = 0; i < 80; ++i) {
@@ -237,7 +241,7 @@ class CCSerializationPerfTest : public testing::Test {
resource_list.push_back(arbitrary_resource);
}
- RenderPassList& render_pass_list = frame.render_pass_list;
+ auto& render_pass_list = frame.render_pass_list;
gfx::Transform arbitrary_matrix1;
arbitrary_matrix1.Scale(3, 3);
@@ -301,23 +305,23 @@ class CCSerializationPerfTest : public testing::Test {
arbitrary_filters2.Append(
FilterOperation::CreateBrightnessFilter(arbitrary_float2));
- std::unique_ptr<RenderPass> pass_in = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> pass_in = viz::RenderPass::Create();
pass_in->SetAll(root_id, arbitrary_rect1, arbitrary_rect2,
arbitrary_matrix1, arbitrary_filters2, arbitrary_filters1,
arbitrary_color_space, arbitrary_bool1, arbitrary_bool1,
- arbitrary_bool1);
+ arbitrary_bool1, arbitrary_bool1);
// Texture quads
for (uint32_t i = 0; i < 10; ++i) {
viz::SharedQuadState* shared_state1_in =
pass_in->CreateAndAppendSharedQuadState();
- shared_state1_in->SetAll(arbitrary_matrix1, arbitrary_rect1,
- arbitrary_rect1, arbitrary_rect2,
- arbitrary_bool1, arbitrary_float1,
- arbitrary_blend_mode1, arbitrary_context_id1);
+ shared_state1_in->SetAll(
+ arbitrary_matrix1, arbitrary_rect1, arbitrary_rect1, arbitrary_rect2,
+ arbitrary_bool1, arbitrary_bool1, arbitrary_float1,
+ arbitrary_blend_mode1, arbitrary_context_id1);
- TextureDrawQuad* texture_in =
- pass_in->CreateAndAppendDrawQuad<TextureDrawQuad>();
+ auto* texture_in =
+ pass_in->CreateAndAppendDrawQuad<viz::TextureDrawQuad>();
texture_in->SetAll(shared_state1_in, arbitrary_rect2,
arbitrary_rect1_inside_rect2, arbitrary_bool1,
arbitrary_resourceid1, arbitrary_size1,
@@ -325,8 +329,8 @@ class CCSerializationPerfTest : public testing::Test {
arbitrary_color, arbitrary_float_array,
arbitrary_bool4, arbitrary_bool5, arbitrary_bool6);
- TextureDrawQuad* texture_in2 =
- pass_in->CreateAndAppendDrawQuad<TextureDrawQuad>();
+ auto* texture_in2 =
+ pass_in->CreateAndAppendDrawQuad<viz::TextureDrawQuad>();
texture_in2->SetAll(shared_state1_in, arbitrary_rect2,
arbitrary_rect1_inside_rect2, arbitrary_bool1,
arbitrary_resourceid2, arbitrary_size1,
@@ -334,8 +338,8 @@ class CCSerializationPerfTest : public testing::Test {
arbitrary_color, arbitrary_float_array,
arbitrary_bool4, arbitrary_bool5, arbitrary_bool6);
- TextureDrawQuad* texture_in3 =
- pass_in->CreateAndAppendDrawQuad<TextureDrawQuad>();
+ auto* texture_in3 =
+ pass_in->CreateAndAppendDrawQuad<viz::TextureDrawQuad>();
texture_in3->SetAll(shared_state1_in, arbitrary_rect2,
arbitrary_rect1_inside_rect2, arbitrary_bool1,
arbitrary_resourceid3, arbitrary_size1,
@@ -343,8 +347,8 @@ class CCSerializationPerfTest : public testing::Test {
arbitrary_color, arbitrary_float_array,
arbitrary_bool4, arbitrary_bool6, arbitrary_bool6);
- TextureDrawQuad* texture_in4 =
- pass_in->CreateAndAppendDrawQuad<TextureDrawQuad>();
+ auto* texture_in4 =
+ pass_in->CreateAndAppendDrawQuad<viz::TextureDrawQuad>();
texture_in4->SetAll(shared_state1_in, arbitrary_rect2,
arbitrary_rect1_inside_rect2, arbitrary_bool1,
arbitrary_resourceid4, arbitrary_size2,
@@ -357,17 +361,16 @@ class CCSerializationPerfTest : public testing::Test {
for (uint32_t i = 0; i < 10; ++i) {
viz::SharedQuadState* shared_state2_in =
pass_in->CreateAndAppendSharedQuadState();
- shared_state2_in->SetAll(arbitrary_matrix2, arbitrary_rect2,
- arbitrary_rect2, arbitrary_rect3,
- arbitrary_bool1, arbitrary_float2,
- arbitrary_blend_mode2, arbitrary_context_id2);
+ shared_state2_in->SetAll(
+ arbitrary_matrix2, arbitrary_rect2, arbitrary_rect2, arbitrary_rect3,
+ arbitrary_bool1, arbitrary_bool1, arbitrary_float2,
+ arbitrary_blend_mode2, arbitrary_context_id2);
for (uint32_t j = 0; j < 6; ++j) {
- TileDrawQuad* tile_in =
- pass_in->CreateAndAppendDrawQuad<TileDrawQuad>();
- tile_in->SetAll(shared_state2_in, arbitrary_rect2,
- arbitrary_rect1_inside_rect2, arbitrary_bool1,
- arbitrary_resourceid3, arbitrary_rectf1,
- arbitrary_size1, arbitrary_bool2, arbitrary_bool3);
+ auto* tile_in = pass_in->CreateAndAppendDrawQuad<viz::TileDrawQuad>();
+ tile_in->SetAll(
+ shared_state2_in, arbitrary_rect2, arbitrary_rect1_inside_rect2,
+ arbitrary_bool1, arbitrary_resourceid3, arbitrary_rectf1,
+ arbitrary_size1, arbitrary_bool2, arbitrary_bool3, arbitrary_bool4);
}
}
@@ -375,13 +378,13 @@ class CCSerializationPerfTest : public testing::Test {
for (uint32_t i = 0; i < 5; ++i) {
viz::SharedQuadState* shared_state3_in =
pass_in->CreateAndAppendSharedQuadState();
- shared_state3_in->SetAll(arbitrary_matrix1, arbitrary_rect3,
- arbitrary_rect3, arbitrary_rect1,
- arbitrary_bool1, arbitrary_float3,
- arbitrary_blend_mode3, arbitrary_context_id3);
+ shared_state3_in->SetAll(
+ arbitrary_matrix1, arbitrary_rect3, arbitrary_rect3, arbitrary_rect1,
+ arbitrary_bool1, arbitrary_bool1, arbitrary_float3,
+ arbitrary_blend_mode3, arbitrary_context_id3);
for (uint32_t j = 0; j < 5; ++j) {
- SolidColorDrawQuad* solidcolor_in =
- pass_in->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ auto* solidcolor_in =
+ pass_in->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
solidcolor_in->SetAll(shared_state3_in, arbitrary_rect3,
arbitrary_rect2_inside_rect3, arbitrary_bool1,
arbitrary_color, arbitrary_bool2);
@@ -396,18 +399,19 @@ class CCSerializationPerfTest : public testing::Test {
uint32_t num_quads,
uint32_t num_passes,
UseSingleSharedQuadState single_sqs) {
- CompositorFrame frame;
+ viz::CompositorFrame frame;
+ frame.metadata.begin_frame_ack = viz::BeginFrameAck(0, 1, true);
for (uint32_t i = 0; i < num_passes; ++i) {
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
render_pass->SetNew(1, gfx::Rect(), gfx::Rect(), gfx::Transform());
for (uint32_t j = 0; j < num_quads; ++j) {
if (j == 0 || single_sqs == UseSingleSharedQuadState::NO)
render_pass->CreateAndAppendSharedQuadState();
const gfx::Rect bounds(100, 100, 100, 100);
const bool kForceAntiAliasingOff = true;
- SolidColorDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ auto* quad =
+ render_pass->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
quad->SetNew(render_pass->shared_quad_state_list.back(), bounds, bounds,
SK_ColorRED, kForceAntiAliasingOff);
}
@@ -417,7 +421,7 @@ class CCSerializationPerfTest : public testing::Test {
}
static void RunTest(const std::string& test_name,
- CompositorFrame frame,
+ viz::CompositorFrame frame,
UseSingleSharedQuadState single_sqs) {
RunSerializationTestStructTraits(test_name, frame, single_sqs);
RunDeserializationTestStructTraits(test_name, frame, single_sqs);
diff --git a/chromium/cc/ipc/copy_output_result.mojom b/chromium/cc/ipc/copy_output_result.mojom
deleted file mode 100644
index 082cfc9aaf2..00000000000
--- a/chromium/cc/ipc/copy_output_result.mojom
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-module cc.mojom;
-
-import "cc/ipc/texture_mailbox.mojom";
-import "cc/ipc/texture_mailbox_releaser.mojom";
-import "skia/public/interfaces/bitmap.mojom";
-import "ui/gfx/geometry/mojo/geometry.mojom";
-
-// See cc/output/copy_output_result.h.
-struct CopyOutputResult {
- gfx.mojom.Size size;
- skia.mojom.Bitmap? bitmap;
- TextureMailbox texture_mailbox;
- TextureMailboxReleaser? releaser;
-};
diff --git a/chromium/cc/ipc/copy_output_result.typemap b/chromium/cc/ipc/copy_output_result.typemap
deleted file mode 100644
index 39aa8408ad1..00000000000
--- a/chromium/cc/ipc/copy_output_result.typemap
+++ /dev/null
@@ -1,16 +0,0 @@
-# Copyright 2017 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-mojom = "//cc/ipc/copy_output_result.mojom"
-public_headers = [ "//components/viz/common/quads/copy_output_result.h" ]
-traits_headers = [ "//cc/ipc/copy_output_result_struct_traits.h" ]
-public_deps = [
- "//cc",
- "//components/viz/common",
- "//skia/public/interfaces:struct_traits",
-]
-sources = [
- "copy_output_result_struct_traits.cc",
-]
-type_mappings = [ "cc.mojom.CopyOutputResult=std::unique_ptr<viz::CopyOutputResult>[move_only]" ]
diff --git a/chromium/cc/ipc/copy_output_result_struct_traits.cc b/chromium/cc/ipc/copy_output_result_struct_traits.cc
deleted file mode 100644
index a5e5629f91b..00000000000
--- a/chromium/cc/ipc/copy_output_result_struct_traits.cc
+++ /dev/null
@@ -1,134 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/ipc/copy_output_result_struct_traits.h"
-
-#include "mojo/public/cpp/bindings/strong_binding.h"
-
-namespace {
-
-// This class retains the release_callback_ of the CopyOutputResult that is
-// being sent over mojo. A TextureMailboxReleaserPtr that talks to this impl
-// object will be sent over mojo instead of the release_callback_ (which is not
-// serializable). Once the client calls Release, the release_callback_ will be
-// called. An object of this class will remain alive until the MessagePipe
-// attached to it goes away (i.e. StrongBinding is used).
-class TextureMailboxReleaserImpl : public cc::mojom::TextureMailboxReleaser {
- public:
- TextureMailboxReleaserImpl(
- std::unique_ptr<viz::SingleReleaseCallback> release_callback)
- : release_callback_(std::move(release_callback)) {
- DCHECK(release_callback_);
- }
-
- ~TextureMailboxReleaserImpl() override {
- // If the client fails to call Release, we should do it ourselves because
- // release_callback_ will fail if it's never called.
- if (release_callback_)
- release_callback_->Run(gpu::SyncToken(), true);
- }
-
- // mojom::TextureMailboxReleaser implementation:
- void Release(const gpu::SyncToken& sync_token, bool is_lost) override {
- if (!release_callback_)
- return;
- release_callback_->Run(sync_token, is_lost);
- release_callback_.reset();
- }
-
- private:
- std::unique_ptr<viz::SingleReleaseCallback> release_callback_;
-};
-
-void Release(cc::mojom::TextureMailboxReleaserPtr ptr,
- const gpu::SyncToken& sync_token,
- bool is_lost) {
- ptr->Release(sync_token, is_lost);
-}
-
-} // namespace
-
-namespace mojo {
-
-// static
-const SkBitmap& StructTraits<cc::mojom::CopyOutputResultDataView,
- std::unique_ptr<viz::CopyOutputResult>>::
- bitmap(const std::unique_ptr<viz::CopyOutputResult>& result) {
- static SkBitmap* null_bitmap = new SkBitmap();
- if (!result->bitmap_)
- return *null_bitmap;
- return *result->bitmap_;
-}
-
-// static
-cc::mojom::TextureMailboxReleaserPtr
-StructTraits<cc::mojom::CopyOutputResultDataView,
- std::unique_ptr<viz::CopyOutputResult>>::
- releaser(const std::unique_ptr<viz::CopyOutputResult>& result) {
- if (!result->release_callback_)
- return {};
- cc::mojom::TextureMailboxReleaserPtr releaser;
- auto impl = std::make_unique<TextureMailboxReleaserImpl>(
- std::move(result->release_callback_));
- MakeStrongBinding(std::move(impl), MakeRequest(&releaser));
- return releaser;
-}
-
-// static
-bool StructTraits<cc::mojom::CopyOutputResultDataView,
- std::unique_ptr<viz::CopyOutputResult>>::
- Read(cc::mojom::CopyOutputResultDataView data,
- std::unique_ptr<viz::CopyOutputResult>* out_p) {
- // We first read into local variables and then call the appropriate
- // constructor of viz::CopyOutputResult.
- gfx::Size size;
- auto bitmap = std::make_unique<SkBitmap>();
- viz::TextureMailbox texture_mailbox;
- std::unique_ptr<viz::SingleReleaseCallback> release_callback;
-
- if (!data.ReadSize(&size))
- return false;
-
- if (!data.ReadBitmap(bitmap.get()))
- return false;
-
- if (!data.ReadTextureMailbox(&texture_mailbox))
- return false;
-
- auto releaser = data.TakeReleaser<cc::mojom::TextureMailboxReleaserPtr>();
- if (releaser) {
- // CopyOutputResult does not have a TextureMailboxReleaserPtr member.
- // We use base::Bind to turn TextureMailboxReleaser::Release into a
- // viz::ReleaseCallback.
- release_callback = viz::SingleReleaseCallback::Create(
- base::Bind(Release, base::Passed(&releaser)));
- }
-
- // Empty result.
- if (bitmap->isNull() && !texture_mailbox.IsTexture()) {
- *out_p = viz::CopyOutputResult::CreateEmptyResult();
- return true;
- }
-
- // Bitmap result.
- if (!bitmap->isNull()) {
- // We can't have both a bitmap and a texture.
- if (texture_mailbox.IsTexture())
- return false;
- *out_p = viz::CopyOutputResult::CreateBitmapResult(std::move(bitmap));
- return true;
- }
-
- // Texture result.
- DCHECK(texture_mailbox.IsTexture());
- if (size.IsEmpty())
- return false;
- if (!release_callback)
- return false;
- *out_p = viz::CopyOutputResult::CreateTextureResult(
- size, texture_mailbox, std::move(release_callback));
- return true;
-}
-
-} // namespace mojo
diff --git a/chromium/cc/ipc/copy_output_result_struct_traits.h b/chromium/cc/ipc/copy_output_result_struct_traits.h
deleted file mode 100644
index 8ada87c3881..00000000000
--- a/chromium/cc/ipc/copy_output_result_struct_traits.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_IPC_COPY_OUTPUT_RESULT_STRUCT_TRAITS_H_
-#define CC_IPC_COPY_OUTPUT_RESULT_STRUCT_TRAITS_H_
-
-#include "cc/ipc/copy_output_result.mojom-shared.h"
-#include "cc/ipc/texture_mailbox_releaser.mojom.h"
-#include "cc/ipc/texture_mailbox_struct_traits.h"
-#include "components/viz/common/quads/copy_output_result.h"
-#include "skia/public/interfaces/bitmap_skbitmap_struct_traits.h"
-#include "ui/gfx/geometry/mojo/geometry_struct_traits.h"
-
-namespace mojo {
-
-template <>
-struct StructTraits<cc::mojom::CopyOutputResultDataView,
- std::unique_ptr<viz::CopyOutputResult>> {
- static const gfx::Size& size(
- const std::unique_ptr<viz::CopyOutputResult>& result) {
- return result->size_;
- }
-
- static const SkBitmap& bitmap(
- const std::unique_ptr<viz::CopyOutputResult>& result);
-
- static const viz::TextureMailbox& texture_mailbox(
- const std::unique_ptr<viz::CopyOutputResult>& result) {
- return result->texture_mailbox_;
- }
-
- static cc::mojom::TextureMailboxReleaserPtr releaser(
- const std::unique_ptr<viz::CopyOutputResult>& result);
-
- static bool Read(cc::mojom::CopyOutputResultDataView data,
- std::unique_ptr<viz::CopyOutputResult>* out_p);
-};
-
-} // namespace mojo
-
-#endif // CC_IPC_COPY_OUTPUT_RESULT_STRUCT_TRAITS_H_
diff --git a/chromium/cc/ipc/frame_sink_id.mojom b/chromium/cc/ipc/frame_sink_id.mojom
deleted file mode 100644
index b8fb286fe88..00000000000
--- a/chromium/cc/ipc/frame_sink_id.mojom
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-module cc.mojom;
-
-struct FrameSinkId {
- uint32 client_id;
- uint32 sink_id;
-};
diff --git a/chromium/cc/ipc/frame_sink_id.typemap b/chromium/cc/ipc/frame_sink_id.typemap
deleted file mode 100644
index c7e3c5db92e..00000000000
--- a/chromium/cc/ipc/frame_sink_id.typemap
+++ /dev/null
@@ -1,11 +0,0 @@
-# Copyright 2016 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-mojom = "//cc/ipc/frame_sink_id.mojom"
-public_headers = [ "//components/viz/common/surfaces/frame_sink_id.h" ]
-deps = [
- "//components/viz/common",
-]
-traits_headers = [ "//cc/ipc/frame_sink_id_struct_traits.h" ]
-type_mappings = [ "cc.mojom.FrameSinkId=viz::FrameSinkId" ]
diff --git a/chromium/cc/ipc/frame_sink_id_struct_traits.h b/chromium/cc/ipc/frame_sink_id_struct_traits.h
deleted file mode 100644
index 1acacf03a8f..00000000000
--- a/chromium/cc/ipc/frame_sink_id_struct_traits.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_IPC_FRAME_SINK_ID_STRUCT_TRAITS_H_
-#define CC_IPC_FRAME_SINK_ID_STRUCT_TRAITS_H_
-
-#include "cc/ipc/frame_sink_id.mojom-shared.h"
-#include "components/viz/common/surfaces/frame_sink_id.h"
-
-namespace mojo {
-
-template <>
-struct StructTraits<cc::mojom::FrameSinkIdDataView, viz::FrameSinkId> {
- static uint32_t client_id(const viz::FrameSinkId& frame_sink_id) {
- return frame_sink_id.client_id();
- }
-
- static uint32_t sink_id(const viz::FrameSinkId& frame_sink_id) {
- return frame_sink_id.sink_id();
- }
-
- static bool Read(cc::mojom::FrameSinkIdDataView data, viz::FrameSinkId* out) {
- *out = viz::FrameSinkId(data.client_id(), data.sink_id());
- return true;
- }
-};
-
-} // namespace mojo
-
-#endif // CC_IPC_FRAME_SINK_ID_STRUCT_TRAITS_H_
diff --git a/chromium/cc/ipc/local_surface_id.mojom b/chromium/cc/ipc/local_surface_id.mojom
deleted file mode 100644
index 2c5612a4eaa..00000000000
--- a/chromium/cc/ipc/local_surface_id.mojom
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-module cc.mojom;
-import "mojo/common/unguessable_token.mojom";
-
-struct LocalSurfaceId {
- // An identifier allocated by the client uniquely identifying a surface within
- // a client process.
- uint32 local_id;
-
- mojo.common.mojom.UnguessableToken nonce;
-};
-
diff --git a/chromium/cc/ipc/local_surface_id.typemap b/chromium/cc/ipc/local_surface_id.typemap
deleted file mode 100644
index b81f7837fe0..00000000000
--- a/chromium/cc/ipc/local_surface_id.typemap
+++ /dev/null
@@ -1,11 +0,0 @@
-# Copyright 2017 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-mojom = "//cc/ipc/local_surface_id.mojom"
-public_headers = [ "//components/viz/common/surfaces/local_surface_id.h" ]
-deps = [
- "//components/viz/common",
-]
-traits_headers = [ "//cc/ipc/local_surface_id_struct_traits.h" ]
-type_mappings = [ "cc.mojom.LocalSurfaceId=viz::LocalSurfaceId" ]
diff --git a/chromium/cc/ipc/local_surface_id_struct_traits.h b/chromium/cc/ipc/local_surface_id_struct_traits.h
deleted file mode 100644
index 68c892f01ae..00000000000
--- a/chromium/cc/ipc/local_surface_id_struct_traits.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_IPC_LOCAL_SURFACE_ID_STRUCT_TRAITS_H_
-#define CC_IPC_LOCAL_SURFACE_ID_STRUCT_TRAITS_H_
-
-#include "cc/ipc/local_surface_id.mojom-shared.h"
-#include "components/viz/common/surfaces/local_surface_id.h"
-#include "mojo/common/common_custom_types_struct_traits.h"
-
-namespace mojo {
-
-template <>
-struct StructTraits<cc::mojom::LocalSurfaceIdDataView, viz::LocalSurfaceId> {
- static uint32_t local_id(const viz::LocalSurfaceId& local_surface_id) {
- return local_surface_id.local_id();
- }
-
- static const base::UnguessableToken& nonce(
- const viz::LocalSurfaceId& local_surface_id) {
- return local_surface_id.nonce();
- }
-
- static bool Read(cc::mojom::LocalSurfaceIdDataView data,
- viz::LocalSurfaceId* out) {
- out->local_id_ = data.local_id();
- return data.ReadNonce(&out->nonce_);
- }
-};
-
-} // namespace mojo
-
-#endif // CC_IPC_LOCAL_SURFACE_ID_STRUCT_TRAITS_H_
diff --git a/chromium/cc/ipc/struct_traits_unittest.cc b/chromium/cc/ipc/struct_traits_unittest.cc
deleted file mode 100644
index 046cb1265bc..00000000000
--- a/chromium/cc/ipc/struct_traits_unittest.cc
+++ /dev/null
@@ -1,185 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <utility>
-
-#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
-#include "cc/input/selection.h"
-#include "cc/ipc/traits_test_service.mojom.h"
-#include "cc/quads/debug_border_draw_quad.h"
-#include "cc/quads/render_pass.h"
-#include "cc/quads/render_pass_draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/stream_video_draw_quad.h"
-#include "cc/quads/surface_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
-#include "cc/quads/yuv_video_draw_quad.h"
-#include "components/viz/common/quads/copy_output_result.h"
-#include "components/viz/test/begin_frame_args_test.h"
-#include "mojo/public/cpp/bindings/binding_set.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/skia/include/core/SkString.h"
-#include "third_party/skia/include/effects/SkDropShadowImageFilter.h"
-
-namespace cc {
-
-namespace {
-
-class StructTraitsTest : public testing::Test, public mojom::TraitsTestService {
- public:
- StructTraitsTest() {}
-
- protected:
- mojom::TraitsTestServicePtr GetTraitsTestProxy() {
- mojom::TraitsTestServicePtr proxy;
- traits_test_bindings_.AddBinding(this, mojo::MakeRequest(&proxy));
- return proxy;
- }
-
- private:
- // TraitsTestService:
- void EchoCopyOutputResult(std::unique_ptr<viz::CopyOutputResult> c,
- EchoCopyOutputResultCallback callback) override {
- std::move(callback).Run(std::move(c));
- }
-
- void EchoTextureMailbox(const viz::TextureMailbox& t,
- EchoTextureMailboxCallback callback) override {
- std::move(callback).Run(t);
- }
-
- mojo::BindingSet<TraitsTestService> traits_test_bindings_;
- DISALLOW_COPY_AND_ASSIGN(StructTraitsTest);
-};
-
-void CopyOutputResultCallback(base::Closure quit_closure,
- const gpu::SyncToken& expected_sync_token,
- bool expected_is_lost,
- const gpu::SyncToken& sync_token,
- bool is_lost) {
- EXPECT_EQ(expected_sync_token, sync_token);
- EXPECT_EQ(expected_is_lost, is_lost);
- quit_closure.Run();
-}
-
-} // namespace
-
-TEST_F(StructTraitsTest, CopyOutputResult_Bitmap) {
- auto bitmap = std::make_unique<SkBitmap>();
- bitmap->allocN32Pixels(7, 8);
- bitmap->eraseARGB(123, 213, 77, 33);
- auto in_bitmap = std::make_unique<SkBitmap>();
- in_bitmap->allocN32Pixels(7, 8);
- in_bitmap->eraseARGB(123, 213, 77, 33);
- auto input = viz::CopyOutputResult::CreateBitmapResult(std::move(bitmap));
- auto size = input->size();
-
- mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
- std::unique_ptr<viz::CopyOutputResult> output;
- proxy->EchoCopyOutputResult(std::move(input), &output);
-
- EXPECT_TRUE(output->HasBitmap());
- EXPECT_FALSE(output->HasTexture());
- EXPECT_EQ(size, output->size());
-
- std::unique_ptr<SkBitmap> out_bitmap = output->TakeBitmap();
- EXPECT_EQ(in_bitmap->getSize(), out_bitmap->getSize());
- EXPECT_EQ(0, std::memcmp(in_bitmap->getPixels(), out_bitmap->getPixels(),
- in_bitmap->getSize()));
-}
-
-TEST_F(StructTraitsTest, CopyOutputResult_Texture) {
- const gfx::Size size(1234, 5678);
- const int8_t mailbox_name[GL_MAILBOX_SIZE_CHROMIUM] = {
- 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 3};
- const uint32_t target = 3;
- gpu::SyncToken sync_token(gpu::CommandBufferNamespace::GPU_IO, 0,
- gpu::CommandBufferId::FromUnsafeValue(0x123),
- 71234838);
- bool is_lost = true;
- base::RunLoop run_loop;
- auto callback = viz::SingleReleaseCallback::Create(base::Bind(
- CopyOutputResultCallback, run_loop.QuitClosure(), sync_token, is_lost));
- gpu::Mailbox mailbox;
- mailbox.SetName(mailbox_name);
- viz::TextureMailbox texture_mailbox(mailbox, gpu::SyncToken(), target);
-
- auto input = viz::CopyOutputResult::CreateTextureResult(size, texture_mailbox,
- std::move(callback));
-
- mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
- std::unique_ptr<viz::CopyOutputResult> output;
- proxy->EchoCopyOutputResult(std::move(input), &output);
-
- EXPECT_FALSE(output->HasBitmap());
- EXPECT_TRUE(output->HasTexture());
- EXPECT_EQ(size, output->size());
-
- viz::TextureMailbox out_mailbox;
- std::unique_ptr<viz::SingleReleaseCallback> out_callback;
- output->TakeTexture(&out_mailbox, &out_callback);
- EXPECT_EQ(mailbox, out_mailbox.mailbox());
- out_callback->Run(sync_token, is_lost);
- // If CopyOutputResultCallback is called (which is the intended behaviour),
- // this will exit. Otherwise, this test will time out and fail.
- // In CopyOutputResultCallback we verify that the given sync_token and is_lost
- // have their intended values.
- run_loop.Run();
-}
-
-TEST_F(StructTraitsTest, TextureMailbox) {
- const int8_t mailbox_name[GL_MAILBOX_SIZE_CHROMIUM] = {
- 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2};
- const gpu::CommandBufferNamespace command_buffer_namespace = gpu::IN_PROCESS;
- const int32_t extra_data_field = 0xbeefbeef;
- const gpu::CommandBufferId command_buffer_id(
- gpu::CommandBufferId::FromUnsafeValue(0xdeadbeef));
- const uint64_t release_count = 0xdeadbeefdeadL;
- const gpu::SyncToken sync_token(command_buffer_namespace, extra_data_field,
- command_buffer_id, release_count);
- const uint32_t texture_target = 1337;
- const gfx::Size size_in_pixels(93, 24);
- const bool is_overlay_candidate = true;
- const bool secure_output_only = true;
- const bool nearest_neighbor = true;
- const gfx::ColorSpace color_space = gfx::ColorSpace(
- gfx::ColorSpace::PrimaryID::BT470M, gfx::ColorSpace::TransferID::GAMMA28,
- gfx::ColorSpace::MatrixID::BT2020_NCL, gfx::ColorSpace::RangeID::LIMITED);
-#if defined(OS_ANDROID)
- const bool is_backed_by_surface_texture = true;
- const bool wants_promotion_hint = true;
-#endif
-
- gpu::Mailbox mailbox;
- mailbox.SetName(mailbox_name);
- viz::TextureMailbox input(mailbox, sync_token, texture_target, size_in_pixels,
- is_overlay_candidate, secure_output_only);
- input.set_nearest_neighbor(nearest_neighbor);
- input.set_color_space(color_space);
-#if defined(OS_ANDROID)
- input.set_is_backed_by_surface_texture(is_backed_by_surface_texture);
- input.set_wants_promotion_hint(wants_promotion_hint);
-#endif
-
- mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
- viz::TextureMailbox output;
- proxy->EchoTextureMailbox(input, &output);
-
- EXPECT_EQ(mailbox, output.mailbox());
- EXPECT_EQ(sync_token, output.sync_token());
- EXPECT_EQ(texture_target, output.target());
- EXPECT_EQ(size_in_pixels, output.size_in_pixels());
- EXPECT_EQ(is_overlay_candidate, output.is_overlay_candidate());
- EXPECT_EQ(secure_output_only, output.secure_output_only());
- EXPECT_EQ(nearest_neighbor, output.nearest_neighbor());
- EXPECT_EQ(color_space, output.color_space());
-#if defined(OS_ANDROID)
- EXPECT_EQ(is_backed_by_surface_texture,
- output.is_backed_by_surface_texture());
- EXPECT_EQ(wants_promotion_hint, output.wants_promotion_hint());
-#endif
-}
-
-} // namespace cc
diff --git a/chromium/cc/ipc/texture_mailbox.mojom b/chromium/cc/ipc/texture_mailbox.mojom
deleted file mode 100644
index 90a92b727c0..00000000000
--- a/chromium/cc/ipc/texture_mailbox.mojom
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-module cc.mojom;
-
-import "gpu/ipc/common/mailbox_holder.mojom";
-import "ui/gfx/geometry/mojo/geometry.mojom";
-import "ui/gfx/mojo/color_space.mojom";
-
-// TODO(samans): Add shared_bitmap. See crbug.com/686221.
-// See cc/resources/texture_mailbox.h.
-struct TextureMailbox {
- gpu.mojom.MailboxHolder mailbox_holder;
- gfx.mojom.Size size_in_pixels;
- bool is_overlay_candidate;
- bool is_backed_by_surface_texture;
- bool wants_promotion_hint;
- bool secure_output_only;
- bool nearest_neighbor;
- gfx.mojom.ColorSpace color_space;
-};
diff --git a/chromium/cc/ipc/texture_mailbox.typemap b/chromium/cc/ipc/texture_mailbox.typemap
deleted file mode 100644
index be37c00b112..00000000000
--- a/chromium/cc/ipc/texture_mailbox.typemap
+++ /dev/null
@@ -1,11 +0,0 @@
-# Copyright 2017 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-mojom = "//cc/ipc/texture_mailbox.mojom"
-public_headers = [ "//components/viz/common/quads/texture_mailbox.h" ]
-traits_headers = [ "//cc/ipc/texture_mailbox_struct_traits.h" ]
-deps = [
- "//components/viz/common",
-]
-type_mappings = [ "cc.mojom.TextureMailbox=viz::TextureMailbox" ]
diff --git a/chromium/cc/ipc/texture_mailbox_releaser.mojom b/chromium/cc/ipc/texture_mailbox_releaser.mojom
deleted file mode 100644
index 3b9ec3c275f..00000000000
--- a/chromium/cc/ipc/texture_mailbox_releaser.mojom
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-module cc.mojom;
-
-import "gpu/ipc/common/sync_token.mojom";
-
-// This interface behaves similar to viz::ReleaseCallback but works across process
-// boundaries. Once Release is called, it releases the TextureMailbox that it
-// is associated with.
-interface TextureMailboxReleaser {
- Release(gpu.mojom.SyncToken sync_token, bool is_lost);
-};
diff --git a/chromium/cc/ipc/texture_mailbox_struct_traits.h b/chromium/cc/ipc/texture_mailbox_struct_traits.h
deleted file mode 100644
index 9f1032238a6..00000000000
--- a/chromium/cc/ipc/texture_mailbox_struct_traits.h
+++ /dev/null
@@ -1,77 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_IPC_TEXTURE_MAILBOX_STRUCT_TRAITS_H_
-#define CC_IPC_TEXTURE_MAILBOX_STRUCT_TRAITS_H_
-
-#include "cc/ipc/texture_mailbox.mojom-shared.h"
-#include "components/viz/common/quads/texture_mailbox.h"
-#include "gpu/ipc/common/mailbox_holder_struct_traits.h"
-#include "ui/gfx/geometry/mojo/geometry_struct_traits.h"
-#include "ui/gfx/ipc/color/gfx_param_traits.h"
-
-namespace mojo {
-
-template <>
-struct StructTraits<cc::mojom::TextureMailboxDataView, viz::TextureMailbox> {
- static const gpu::MailboxHolder& mailbox_holder(
- const viz::TextureMailbox& input) {
- return input.mailbox_holder_;
- }
-
- static const gfx::Size& size_in_pixels(const viz::TextureMailbox& input) {
- return input.size_in_pixels_;
- }
-
- static bool is_overlay_candidate(const viz::TextureMailbox& input) {
- return input.is_overlay_candidate_;
- }
-
- static bool is_backed_by_surface_texture(const viz::TextureMailbox& input) {
-#if defined(OS_ANDROID)
- return input.is_backed_by_surface_texture_;
-#else
- return false;
-#endif
- }
-
- static bool wants_promotion_hint(const viz::TextureMailbox& input) {
-#if defined(OS_ANDROID)
- return input.wants_promotion_hint_;
-#else
- return false;
-#endif
- }
-
- static bool secure_output_only(const viz::TextureMailbox& input) {
- return input.secure_output_only_;
- }
-
- static bool nearest_neighbor(const viz::TextureMailbox& input) {
- return input.nearest_neighbor_;
- }
-
- static const gfx::ColorSpace& color_space(const viz::TextureMailbox& input) {
- return input.color_space_;
- }
-
- static bool Read(cc::mojom::TextureMailboxDataView data,
- viz::TextureMailbox* out) {
-#if defined(OS_ANDROID)
- out->is_backed_by_surface_texture_ = data.is_backed_by_surface_texture();
- out->wants_promotion_hint_ = data.wants_promotion_hint();
-#endif
- out->is_overlay_candidate_ = data.is_overlay_candidate();
- out->secure_output_only_ = data.secure_output_only();
- out->nearest_neighbor_ = data.nearest_neighbor();
-
- return data.ReadMailboxHolder(&out->mailbox_holder_) &&
- data.ReadSizeInPixels(&out->size_in_pixels_) &&
- data.ReadColorSpace(&out->color_space_);
- }
-};
-
-} // namespace mojo
-
-#endif // CC_IPC_TEXTURE_MAILBOX_STRUCT_TRAITS_H_
diff --git a/chromium/cc/ipc/traits_test_service.mojom b/chromium/cc/ipc/traits_test_service.mojom
deleted file mode 100644
index a04dfe659fc..00000000000
--- a/chromium/cc/ipc/traits_test_service.mojom
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-module cc.mojom;
-
-import "cc/ipc/copy_output_result.mojom";
-import "cc/ipc/texture_mailbox.mojom";
-
-// All functions on this interface echo their arguments to test StructTraits
-// serialization and deserialization.
-interface TraitsTestService {
- [Sync]
- EchoCopyOutputResult(CopyOutputResult c) => (CopyOutputResult pass);
-
- [Sync]
- EchoTextureMailbox(TextureMailbox t) =>
- (TextureMailbox pass);
-};
diff --git a/chromium/cc/ipc/typemaps.gni b/chromium/cc/ipc/typemaps.gni
deleted file mode 100644
index 7833d2554d0..00000000000
--- a/chromium/cc/ipc/typemaps.gni
+++ /dev/null
@@ -1,10 +0,0 @@
-# Copyright 2016 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-typemaps = [
- "//cc/ipc/copy_output_result.typemap",
- "//cc/ipc/frame_sink_id.typemap",
- "//cc/ipc/local_surface_id.typemap",
- "//cc/ipc/texture_mailbox.typemap",
-]
diff --git a/chromium/cc/layers/heads_up_display_layer.cc b/chromium/cc/layers/heads_up_display_layer.cc
index 0f8ba193cf1..de216cf7d37 100644
--- a/chromium/cc/layers/heads_up_display_layer.cc
+++ b/chromium/cc/layers/heads_up_display_layer.cc
@@ -14,7 +14,7 @@
namespace cc {
scoped_refptr<HeadsUpDisplayLayer> HeadsUpDisplayLayer::Create() {
- return make_scoped_refptr(new HeadsUpDisplayLayer());
+ return base::WrapRefCounted(new HeadsUpDisplayLayer());
}
HeadsUpDisplayLayer::HeadsUpDisplayLayer()
diff --git a/chromium/cc/layers/heads_up_display_layer_impl.cc b/chromium/cc/layers/heads_up_display_layer_impl.cc
index 6a3787054dc..3d5f5dd5404 100644
--- a/chromium/cc/layers/heads_up_display_layer_impl.cc
+++ b/chromium/cc/layers/heads_up_display_layer_impl.cc
@@ -16,13 +16,13 @@
#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_event_argument.h"
#include "cc/debug/debug_colors.h"
-#include "cc/quads/texture_draw_quad.h"
#include "cc/raster/scoped_gpu_raster.h"
#include "cc/resources/memory_history.h"
#include "cc/trees/frame_rate_counter.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/layer_tree_impl.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/skia/include/core/SkCanvas.h"
@@ -96,10 +96,9 @@ void HeadsUpDisplayLayerImpl::AcquireResource(
}
auto resource = std::make_unique<ScopedResource>(resource_provider);
- resource->Allocate(internal_content_bounds_,
- ResourceProvider::TEXTURE_HINT_IMMUTABLE_FRAMEBUFFER,
- resource_provider->best_render_buffer_format(),
- gfx::ColorSpace());
+ resource->Allocate(
+ internal_content_bounds_, ResourceProvider::TEXTURE_HINT_FRAMEBUFFER,
+ resource_provider->best_render_buffer_format(), gfx::ColorSpace());
resources_.push_back(std::move(resource));
}
@@ -111,8 +110,9 @@ void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources(
});
}
-bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode,
- ResourceProvider* resource_provider) {
+bool HeadsUpDisplayLayerImpl::WillDraw(
+ DrawMode draw_mode,
+ LayerTreeResourceProvider* resource_provider) {
if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE)
return false;
@@ -128,16 +128,15 @@ bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode,
return LayerImpl::WillDraw(draw_mode, resource_provider);
}
-void HeadsUpDisplayLayerImpl::AppendQuads(
- RenderPass* render_pass,
- AppendQuadsData* append_quads_data) {
+void HeadsUpDisplayLayerImpl::AppendQuads(viz::RenderPass* render_pass,
+ AppendQuadsData* append_quads_data) {
if (!resources_.back()->id())
return;
viz::SharedQuadState* shared_quad_state =
render_pass->CreateAndAppendSharedQuadState();
PopulateScaledSharedQuadState(shared_quad_state, internal_contents_scale_,
- internal_contents_scale_);
+ internal_contents_scale_, contents_opaque());
gfx::Rect quad_rect(internal_content_bounds_);
bool needs_blending = contents_opaque() ? false : true;
@@ -148,8 +147,7 @@ void HeadsUpDisplayLayerImpl::AppendQuads(
const float vertex_opacity[] = { 1.f, 1.f, 1.f, 1.f };
bool flipped = false;
bool nearest_neighbor = false;
- TextureDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
+ auto* quad = render_pass->CreateAndAppendDrawQuad<viz::TextureDrawQuad>();
quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, needs_blending,
resources_.back()->id(), premultiplied_alpha, uv_top_left,
uv_bottom_right, SK_ColorTRANSPARENT, vertex_opacity, flipped,
@@ -161,7 +159,7 @@ void HeadsUpDisplayLayerImpl::UpdateHudTexture(
DrawMode draw_mode,
ResourceProvider* resource_provider,
viz::ContextProvider* context_provider,
- const RenderPassList& list) {
+ const viz::RenderPassList& list) {
if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !resources_.back()->id())
return;
@@ -811,7 +809,7 @@ void HeadsUpDisplayLayerImpl::DrawDebugRects(
}
}
-void HeadsUpDisplayLayerImpl::EvictHudQuad(const RenderPassList& list) {
+void HeadsUpDisplayLayerImpl::EvictHudQuad(const viz::RenderPassList& list) {
viz::ResourceId evict_resource_id = resources_.back()->id();
// This iterates over the render pass list of quads to evict the hud quad
// appended during render pass preparation. We need this eviction when we
diff --git a/chromium/cc/layers/heads_up_display_layer_impl.h b/chromium/cc/layers/heads_up_display_layer_impl.h
index 923864b0161..f32753c1332 100644
--- a/chromium/cc/layers/heads_up_display_layer_impl.h
+++ b/chromium/cc/layers/heads_up_display_layer_impl.h
@@ -40,13 +40,13 @@ class CC_EXPORT HeadsUpDisplayLayerImpl : public LayerImpl {
std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
bool WillDraw(DrawMode draw_mode,
- ResourceProvider* resource_provider) override;
- void AppendQuads(RenderPass* render_pass,
+ LayerTreeResourceProvider* resource_provider) override;
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override;
void UpdateHudTexture(DrawMode draw_mode,
ResourceProvider* resource_provider,
viz::ContextProvider* context_provider,
- const RenderPassList& list);
+ const viz::RenderPassList& list);
void ReleaseResources() override;
@@ -57,7 +57,7 @@ class CC_EXPORT HeadsUpDisplayLayerImpl : public LayerImpl {
void SetHUDTypeface(sk_sp<SkTypeface> typeface);
// This evicts hud quad appended during render pass preparation.
- void EvictHudQuad(const RenderPassList& list);
+ void EvictHudQuad(const viz::RenderPassList& list);
// LayerImpl overrides.
void PushPropertiesTo(LayerImpl* layer) override;
diff --git a/chromium/cc/layers/heads_up_display_layer_impl_unittest.cc b/chromium/cc/layers/heads_up_display_layer_impl_unittest.cc
index d12fd542143..85aa4b63c9d 100644
--- a/chromium/cc/layers/heads_up_display_layer_impl_unittest.cc
+++ b/chromium/cc/layers/heads_up_display_layer_impl_unittest.cc
@@ -17,15 +17,15 @@ namespace cc {
namespace {
void CheckDrawLayer(HeadsUpDisplayLayerImpl* layer,
- ResourceProvider* resource_provider,
+ LayerTreeResourceProvider* resource_provider,
viz::ContextProvider* context_provider,
DrawMode draw_mode) {
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
bool will_draw = layer->WillDraw(draw_mode, resource_provider);
if (will_draw)
layer->AppendQuads(render_pass.get(), &data);
- RenderPassList pass_list;
+ viz::RenderPassList pass_list;
pass_list.push_back(std::move(render_pass));
layer->UpdateHudTexture(draw_mode, resource_provider, context_provider,
pass_list);
diff --git a/chromium/cc/layers/heads_up_display_unittest.cc b/chromium/cc/layers/heads_up_display_unittest.cc
index 18010215855..ee17f7199d4 100644
--- a/chromium/cc/layers/heads_up_display_unittest.cc
+++ b/chromium/cc/layers/heads_up_display_unittest.cc
@@ -21,7 +21,7 @@ class HeadsUpDisplayTest : public LayerTreeTest {
class DrawsContentLayer : public Layer {
public:
static scoped_refptr<DrawsContentLayer> Create() {
- return make_scoped_refptr(new DrawsContentLayer());
+ return base::WrapRefCounted(new DrawsContentLayer());
}
bool DrawsContent() const override { return true; }
diff --git a/chromium/cc/layers/layer.cc b/chromium/cc/layers/layer.cc
index 850fe8cf84c..97eaf1787e4 100644
--- a/chromium/cc/layers/layer.cc
+++ b/chromium/cc/layers/layer.cc
@@ -25,12 +25,11 @@
#include "cc/trees/effect_node.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_impl.h"
-#include "cc/trees/mutable_properties.h"
#include "cc/trees/mutator_host.h"
#include "cc/trees/scroll_node.h"
#include "cc/trees/transform_node.h"
-#include "components/viz/common/quads/copy_output_request.h"
-#include "components/viz/common/quads/copy_output_result.h"
+#include "components/viz/common/frame_sinks/copy_output_request.h"
+#include "components/viz/common/frame_sinks/copy_output_result.h"
#include "third_party/skia/include/core/SkImageFilter.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/vector2d_conversions.h"
@@ -46,7 +45,7 @@ Layer::Inputs::Inputs(int layer_id)
opacity(1.f),
blend_mode(SkBlendMode::kSrcOver),
is_root_for_isolated_group(false),
- should_hit_test(false),
+ hit_testable_without_draws_content(false),
contents_opaque(false),
is_drawable(false),
double_sided(true),
@@ -61,10 +60,10 @@ Layer::Inputs::Inputs(int layer_id)
MainThreadScrollingReason::kNotScrollingOnMain),
is_resized_by_browser_controls(false),
is_container_for_fixed_position_layers(false),
- mutable_properties(MutableProperty::kNone),
scroll_parent(nullptr),
clip_parent(nullptr),
has_will_change_transform_hint(false),
+ trilinear_filtering(false),
hide_layer_and_subtree(false),
client(nullptr),
scroll_boundary_behavior(
@@ -73,7 +72,7 @@ Layer::Inputs::Inputs(int layer_id)
Layer::Inputs::~Inputs() {}
scoped_refptr<Layer> Layer::Create() {
- return make_scoped_refptr(new Layer());
+ return base::WrapRefCounted(new Layer());
}
Layer::Layer()
@@ -201,6 +200,13 @@ bool Layer::IsPropertyChangeAllowed() const {
return !layer_tree_host_->in_paint_layer_contents();
}
+void Layer::SetOpacityInternal(float new_opacity) {
+ float old_opacity = inputs_.opacity;
+ inputs_.opacity = new_opacity;
+ if (new_opacity != old_opacity && inputs_.client)
+ inputs_.client->DidChangeLayerOpacity(old_opacity, new_opacity);
+}
+
sk_sp<SkPicture> Layer::GetPicture() const {
return nullptr;
}
@@ -374,8 +380,6 @@ void Layer::RequestCopyOfOutput(
if (it != inputs_.copy_requests.end())
inputs_.copy_requests.erase(it);
}
- if (request->IsEmpty())
- return;
inputs_.copy_requests.push_back(std::move(request));
SetSubtreePropertyChanged();
SetPropertyTreesNeedRebuild();
@@ -448,7 +452,7 @@ void Layer::SetMaskLayer(Layer* mask_layer) {
inputs_.mask_layer->RemoveFromParent();
DCHECK(!inputs_.mask_layer->parent());
inputs_.mask_layer->SetParent(this);
- if (inputs_.filters.IsEmpty() &&
+ if (inputs_.filters.IsEmpty() && inputs_.background_filters.IsEmpty() &&
(!layer_tree_host_ ||
layer_tree_host_->GetSettings().enable_mask_tiling)) {
inputs_.mask_layer->SetLayerMaskType(
@@ -467,9 +471,10 @@ void Layer::SetFilters(const FilterOperations& filters) {
if (inputs_.filters == filters)
return;
inputs_.filters = filters;
- if (inputs_.mask_layer)
+ if (inputs_.mask_layer && !filters.IsEmpty()) {
inputs_.mask_layer->SetLayerMaskType(
Layer::LayerMaskType::SINGLE_TEXTURE_MASK);
+ }
SetSubtreePropertyChanged();
SetPropertyTreesNeedRebuild();
SetNeedsCommit();
@@ -480,6 +485,14 @@ void Layer::SetBackgroundFilters(const FilterOperations& filters) {
if (inputs_.background_filters == filters)
return;
inputs_.background_filters = filters;
+
+ // We will not set the mask type to MULTI_TEXTURE_MASK if the mask layer's
+ // filters are removed, because we do not want to reraster if the filters are
+ // being animated.
+ if (inputs_.mask_layer && !filters.IsEmpty()) {
+ inputs_.mask_layer->SetLayerMaskType(
+ Layer::LayerMaskType::SINGLE_TEXTURE_MASK);
+ }
SetSubtreePropertyChanged();
SetPropertyTreesNeedRebuild();
SetNeedsCommit();
@@ -505,7 +518,7 @@ void Layer::SetOpacity(float opacity) {
// We need to force a property tree rebuild when opacity changes from 1 to a
// non-1 value or vice-versa as render surfaces can change.
bool force_rebuild = opacity == 1.f || inputs_.opacity == 1.f;
- inputs_.opacity = opacity;
+ SetOpacityInternal(opacity);
SetSubtreePropertyChanged();
if (layer_tree_host_ && !force_rebuild) {
PropertyTrees* property_trees = layer_tree_host_->property_trees();
@@ -590,11 +603,11 @@ void Layer::SetIsRootForIsolatedGroup(bool root) {
SetNeedsCommit();
}
-void Layer::SetShouldHitTest(bool should_hit_test) {
+void Layer::SetHitTestableWithoutDrawsContent(bool should_hit_test) {
DCHECK(IsPropertyChangeAllowed());
- if (inputs_.should_hit_test == should_hit_test)
+ if (inputs_.hit_testable_without_draws_content == should_hit_test)
return;
- inputs_.should_hit_test = should_hit_test;
+ inputs_.hit_testable_without_draws_content = should_hit_test;
SetPropertyTreesNeedRebuild();
SetNeedsCommit();
}
@@ -1167,7 +1180,8 @@ void Layer::PushPropertiesTo(LayerImpl* layer) {
layer->SetScrollTreeIndex(scroll_tree_index());
layer->set_offset_to_transform_parent(offset_to_transform_parent_);
layer->SetDrawsContent(DrawsContent());
- layer->SetShouldHitTest(should_hit_test());
+ layer->SetHitTestableWithoutDrawsContent(
+ hit_testable_without_draws_content());
// subtree_property_changed_ is propagated to all descendants while building
// property trees. So, it is enough to check it only for the current layer.
if (subtree_property_changed_)
@@ -1187,7 +1201,6 @@ void Layer::PushPropertiesTo(LayerImpl* layer) {
if (scrollable())
layer->SetScrollable(inputs_.scroll_container_bounds);
- layer->SetMutableProperties(inputs_.mutable_properties);
// The property trees must be safe to access because they will be used below
// to call |SetScrollOffsetClobberActiveValue|.
@@ -1215,6 +1228,8 @@ void Layer::PushPropertiesTo(LayerImpl* layer) {
layer->SetHasWillChangeTransformHint(has_will_change_transform_hint());
layer->SetNeedsPushProperties();
+ layer->SetTrilinearFiltering(trilinear_filtering());
+
// Reset any state that should be cleared for the next update.
needs_show_scrollbars_ = false;
subtree_property_changed_ = false;
@@ -1319,10 +1334,6 @@ void Layer::SetScrollbarsHiddenFromImplSide(bool hidden) {
inputs_.client->didChangeScrollbarsHidden(hidden);
}
-gfx::ScrollOffset Layer::ScrollOffsetForAnimation() const {
- return CurrentScrollOffset();
-}
-
// On<Property>Animated is called due to an ongoing accelerated animation.
// Since this animation is also being run on the compositor thread, there
// is no need to request a commit to push this value over, so the value is
@@ -1332,7 +1343,7 @@ void Layer::OnFilterAnimated(const FilterOperations& filters) {
}
void Layer::OnOpacityAnimated(float opacity) {
- inputs_.opacity = opacity;
+ SetOpacityInternal(opacity);
}
TransformNode* Layer::GetTransformNode() const {
@@ -1359,6 +1370,13 @@ void Layer::SetHasWillChangeTransformHint(bool has_will_change) {
SetNeedsCommit();
}
+void Layer::SetTrilinearFiltering(bool trilinear_filtering) {
+ if (inputs_.trilinear_filtering == trilinear_filtering)
+ return;
+ inputs_.trilinear_filtering = trilinear_filtering;
+ SetNeedsCommit();
+}
+
MutatorHost* Layer::GetMutatorHost() const {
return layer_tree_host_ ? layer_tree_host_->mutator_host() : nullptr;
}
@@ -1402,8 +1420,8 @@ void Layer::SetElementId(ElementId id) {
if ((layer_tree_host_ && layer_tree_host_->IsUsingLayerLists()) ||
inputs_.element_id == id)
return;
- TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"),
- "Layer::SetElementId", "element", id.AsValue().release());
+ TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug"), "Layer::SetElementId",
+ "element", id.AsValue().release());
if (inputs_.element_id && layer_tree_host()) {
layer_tree_host_->UnregisterElement(inputs_.element_id,
ElementListType::ACTIVE);
@@ -1419,16 +1437,6 @@ void Layer::SetElementId(ElementId id) {
SetNeedsCommit();
}
-void Layer::SetMutableProperties(uint32_t properties) {
- DCHECK(IsPropertyChangeAllowed());
- if (inputs_.mutable_properties == properties)
- return;
- TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"),
- "Layer::SetMutableProperties", "properties", properties);
- inputs_.mutable_properties = properties;
- SetNeedsCommit();
-}
-
bool Layer::has_copy_requests_in_target_subtree() {
return layer_tree_host_->property_trees()
->effect_tree.Node(effect_tree_index())
diff --git a/chromium/cc/layers/layer.h b/chromium/cc/layers/layer.h
index 2e61192d0af..766c860d4b2 100644
--- a/chromium/cc/layers/layer.h
+++ b/chromium/cc/layers/layer.h
@@ -150,8 +150,11 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
return inputs_.is_root_for_isolated_group;
}
- void SetShouldHitTest(bool should_hit_test);
- bool should_hit_test() const { return inputs_.should_hit_test; }
+ // Make the layer hit testable even if |draws_content_| is false.
+ void SetHitTestableWithoutDrawsContent(bool should_hit_test);
+ bool hit_testable_without_draws_content() const {
+ return inputs_.hit_testable_without_draws_content;
+ }
void SetFilters(const FilterOperations& filters);
const FilterOperations& filters() const { return inputs_.filters; }
@@ -415,9 +418,6 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
void SetElementId(ElementId id);
ElementId element_id() const { return inputs_.element_id; }
- void SetMutableProperties(uint32_t properties);
- uint32_t mutable_properties() const { return inputs_.mutable_properties; }
-
bool HasTickingAnimationForTesting() const;
void SetHasWillChangeTransformHint(bool has_will_change);
@@ -425,6 +425,9 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
return inputs_.has_will_change_transform_hint;
}
+ void SetTrilinearFiltering(bool trilinear_filtering);
+ bool trilinear_filtering() const { return inputs_.trilinear_filtering; }
+
MutatorHost* GetMutatorHost() const;
ElementListType GetElementTypeForAnimation() const;
@@ -474,6 +477,10 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
bool IsPropertyChangeAllowed() const;
+ // Sets |inputs_.opacity| to |new_opacity| and notifies |inputs_.client| if
+ // the opacity has changed.
+ void SetOpacityInternal(float new_opacity);
+
// When true, the layer is about to perform an update. Any commit requests
// will be handled implicitly after the update completes.
bool ignore_set_needs_commit_;
@@ -484,7 +491,6 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
friend class LayerTreeHost;
// Interactions with attached animations.
- gfx::ScrollOffset ScrollOffsetForAnimation() const;
void OnFilterAnimated(const FilterOperations& filters);
void OnOpacityAnimated(float opacity);
void OnTransformAnimated(const gfx::Transform& transform);
@@ -547,7 +553,10 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
bool is_root_for_isolated_group : 1;
- bool should_hit_test : 1;
+ // Hit testing depends on draws_content (see: |LayerImpl::should_hit_test|)
+ // and this bit can be set to cause the LayerImpl to be hit testable without
+ // draws_content.
+ bool hit_testable_without_draws_content : 1;
bool contents_opaque : 1;
@@ -606,13 +615,13 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> {
ElementId element_id;
- uint32_t mutable_properties;
-
Layer* scroll_parent;
Layer* clip_parent;
bool has_will_change_transform_hint : 1;
+ bool trilinear_filtering : 1;
+
bool hide_layer_and_subtree : 1;
// The following elements can not and are not serialized.
diff --git a/chromium/cc/layers/layer_client.h b/chromium/cc/layers/layer_client.h
index 85c97722c0d..59fe5b91012 100644
--- a/chromium/cc/layers/layer_client.h
+++ b/chromium/cc/layers/layer_client.h
@@ -33,6 +33,9 @@ class CC_EXPORT LayerClient {
virtual void didUpdateMainThreadScrollingReasons() = 0;
virtual void didChangeScrollbarsHidden(bool) = 0;
+ // Invoked when the layer's opacity has changed.
+ virtual void DidChangeLayerOpacity(float old_opacity, float new_opacity) = 0;
+
protected:
virtual ~LayerClient() {}
};
diff --git a/chromium/cc/layers/layer_impl.cc b/chromium/cc/layers/layer_impl.cc
index 2cc148058f7..bb194e04261 100644
--- a/chromium/cc/layers/layer_impl.cc
+++ b/chromium/cc/layers/layer_impl.cc
@@ -24,23 +24,21 @@
#include "cc/input/main_thread_scrolling_reason.h"
#include "cc/input/scroll_state.h"
#include "cc/layers/layer.h"
-#include "cc/layers/layer_utils.h"
-#include "cc/quads/debug_border_draw_quad.h"
-#include "cc/quads/render_pass.h"
+#include "cc/resources/layer_tree_resource_provider.h"
#include "cc/trees/clip_node.h"
#include "cc/trees/draw_property_utils.h"
#include "cc/trees/effect_node.h"
#include "cc/trees/layer_tree_host_common.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/layer_tree_settings.h"
-#include "cc/trees/mutable_properties.h"
#include "cc/trees/mutator_host.h"
#include "cc/trees/proxy.h"
#include "cc/trees/scroll_node.h"
#include "cc/trees/transform_node.h"
-#include "components/viz/common/quads/copy_output_request.h"
+#include "components/viz/common/frame_sinks/copy_output_request.h"
+#include "components/viz/common/quads/debug_border_draw_quad.h"
+#include "components/viz/common/quads/render_pass.h"
#include "components/viz/common/traced_value.h"
-#include "ui/gfx/geometry/box_f.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/quad_f.h"
#include "ui/gfx/geometry/rect_conversions.h"
@@ -65,7 +63,7 @@ LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id)
should_check_backface_visibility_(false),
draws_content_(false),
contributes_to_drawn_render_surface_(false),
- should_hit_test_(false),
+ hit_testable_without_draws_content_(false),
is_resized_by_browser_controls_(false),
viewport_layer_type_(NOT_VIEWPORT_LAYER),
background_color_(0),
@@ -75,9 +73,9 @@ LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id)
clip_tree_index_(ClipTree::kInvalidNodeId),
scroll_tree_index_(ScrollTree::kInvalidNodeId),
current_draw_mode_(DRAW_MODE_NONE),
- mutable_properties_(MutableProperty::kNone),
debug_info_(nullptr),
has_will_change_transform_hint_(false),
+ trilinear_filtering_(false),
needs_push_properties_(false),
scrollbars_hidden_(false),
needs_show_scrollbars_(false),
@@ -104,6 +102,9 @@ void LayerImpl::SetHasWillChangeTransformHint(bool has_will_change) {
has_will_change_transform_hint_ = has_will_change;
}
+void LayerImpl::SetTrilinearFiltering(bool trilinear_filtering) {
+ trilinear_filtering_ = trilinear_filtering;
+}
MutatorHost* LayerImpl::GetMutatorHost() const {
return layer_tree_impl_ ? layer_tree_impl_->mutator_host() : nullptr;
@@ -144,17 +145,19 @@ void LayerImpl::SetScrollTreeIndex(int index) {
scroll_tree_index_ = index;
}
-void LayerImpl::PopulateSharedQuadState(viz::SharedQuadState* state) const {
+void LayerImpl::PopulateSharedQuadState(viz::SharedQuadState* state,
+ bool contents_opaque) const {
state->SetAll(draw_properties_.target_space_transform, gfx::Rect(bounds()),
draw_properties_.visible_layer_rect, draw_properties_.clip_rect,
- draw_properties_.is_clipped, draw_properties_.opacity,
- SkBlendMode::kSrcOver, GetSortingContextId());
+ draw_properties_.is_clipped, contents_opaque,
+ draw_properties_.opacity, SkBlendMode::kSrcOver,
+ GetSortingContextId());
}
-void LayerImpl::PopulateScaledSharedQuadState(
- viz::SharedQuadState* state,
- float layer_to_content_scale_x,
- float layer_to_content_scale_y) const {
+void LayerImpl::PopulateScaledSharedQuadState(viz::SharedQuadState* state,
+ float layer_to_content_scale_x,
+ float layer_to_content_scale_y,
+ bool contents_opaque) const {
gfx::Transform scaled_draw_transform =
draw_properties_.target_space_transform;
scaled_draw_transform.Scale(SK_MScalar1 / layer_to_content_scale_x,
@@ -167,12 +170,13 @@ void LayerImpl::PopulateScaledSharedQuadState(
state->SetAll(scaled_draw_transform, gfx::Rect(scaled_bounds),
scaled_visible_layer_rect, draw_properties().clip_rect,
- draw_properties().is_clipped, draw_properties().opacity,
- SkBlendMode::kSrcOver, GetSortingContextId());
+ draw_properties().is_clipped, contents_opaque,
+ draw_properties().opacity, SkBlendMode::kSrcOver,
+ GetSortingContextId());
}
bool LayerImpl::WillDraw(DrawMode draw_mode,
- ResourceProvider* resource_provider) {
+ LayerTreeResourceProvider* resource_provider) {
// WillDraw/DidDraw must be matched.
DCHECK_NE(DRAW_MODE_NONE, draw_mode);
DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_);
@@ -180,7 +184,7 @@ bool LayerImpl::WillDraw(DrawMode draw_mode,
return true;
}
-void LayerImpl::DidDraw(ResourceProvider* resource_provider) {
+void LayerImpl::DidDraw(LayerTreeResourceProvider* resource_provider) {
DCHECK_NE(DRAW_MODE_NONE, current_draw_mode_);
current_draw_mode_ = DRAW_MODE_NONE;
}
@@ -210,20 +214,20 @@ void LayerImpl::GetDebugBorderProperties(SkColor* color, float* width) const {
}
void LayerImpl::AppendDebugBorderQuad(
- RenderPass* render_pass,
- const gfx::Size& bounds,
+ viz::RenderPass* render_pass,
+ const gfx::Rect& quad_rect,
const viz::SharedQuadState* shared_quad_state,
AppendQuadsData* append_quads_data) const {
SkColor color;
float width;
GetDebugBorderProperties(&color, &width);
- AppendDebugBorderQuad(render_pass, bounds, shared_quad_state,
+ AppendDebugBorderQuad(render_pass, quad_rect, shared_quad_state,
append_quads_data, color, width);
}
void LayerImpl::AppendDebugBorderQuad(
- RenderPass* render_pass,
- const gfx::Size& bounds,
+ viz::RenderPass* render_pass,
+ const gfx::Rect& quad_rect,
const viz::SharedQuadState* shared_quad_state,
AppendQuadsData* append_quads_data,
SkColor color,
@@ -231,10 +235,9 @@ void LayerImpl::AppendDebugBorderQuad(
if (!ShowDebugBorders(DebugBorderType::LAYER))
return;
- gfx::Rect quad_rect(bounds);
gfx::Rect visible_quad_rect(quad_rect);
- DebugBorderDrawQuad* debug_border_quad =
- render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
+ auto* debug_border_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::DebugBorderDrawQuad>();
debug_border_quad->SetNew(
shared_quad_state, quad_rect, visible_quad_rect, color, width);
if (contents_opaque()) {
@@ -250,8 +253,8 @@ void LayerImpl::AppendDebugBorderQuad(
return;
gfx::Rect visible_fill_rect =
gfx::IntersectRects(visible_quad_rect, fill_rect);
- DebugBorderDrawQuad* fill_quad =
- render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
+ auto* fill_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::DebugBorderDrawQuad>();
fill_quad->SetNew(shared_quad_state, fill_rect, visible_fill_rect,
fill_color, fill_width);
}
@@ -315,7 +318,8 @@ void LayerImpl::PushPropertiesTo(LayerImpl* layer) {
layer->use_parent_backface_visibility_ = use_parent_backface_visibility_;
layer->should_check_backface_visibility_ = should_check_backface_visibility_;
layer->draws_content_ = draws_content_;
- layer->should_hit_test_ = should_hit_test_;
+ layer->hit_testable_without_draws_content_ =
+ hit_testable_without_draws_content_;
layer->non_fast_scrollable_region_ = non_fast_scrollable_region_;
layer->touch_action_region_ = touch_action_region_;
layer->background_color_ = background_color_;
@@ -326,6 +330,7 @@ void LayerImpl::PushPropertiesTo(LayerImpl* layer) {
layer->clip_tree_index_ = clip_tree_index_;
layer->scroll_tree_index_ = scroll_tree_index_;
layer->has_will_change_transform_hint_ = has_will_change_transform_hint_;
+ layer->trilinear_filtering_ = trilinear_filtering_;
layer->scrollbars_hidden_ = scrollbars_hidden_;
if (needs_show_scrollbars_)
layer->needs_show_scrollbars_ = needs_show_scrollbars_;
@@ -341,7 +346,6 @@ void LayerImpl::PushPropertiesTo(LayerImpl* layer) {
layer->SetBounds(bounds_);
if (scrollable_)
layer->SetScrollable(scroll_container_bounds_);
- layer->SetMutableProperties(mutable_properties_);
// If the main thread commits multiple times before the impl thread actually
// draws, then damage tracking will become incorrect if we simply clobber the
@@ -376,7 +380,7 @@ void LayerImpl::SetIsResizedByBrowserControls(bool resized) {
is_resized_by_browser_controls_ = resized;
}
-std::unique_ptr<base::DictionaryValue> LayerImpl::LayerTreeAsJson() {
+std::unique_ptr<base::DictionaryValue> LayerImpl::LayerAsJson() {
std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue);
result->SetInteger("LayerId", id());
result->SetString("LayerType", LayerTypeAsString());
@@ -400,6 +404,8 @@ std::unique_ptr<base::DictionaryValue> LayerImpl::LayerTreeAsJson() {
result->Set("Transform", std::move(list));
result->SetBoolean("DrawsContent", draws_content_);
+ result->SetBoolean("HitTestableWithoutDrawsContent",
+ hit_testable_without_draws_content_);
result->SetBoolean("Is3dSorted", Is3dSorted());
result->SetDouble("OPACITY", Opacity());
result->SetBoolean("ContentsOpaque", contents_opaque_);
@@ -413,7 +419,13 @@ std::unique_ptr<base::DictionaryValue> LayerImpl::LayerTreeAsJson() {
result->Set("TouchRegion", std::move(region));
}
- list = std::make_unique<base::ListValue>();
+ return result;
+}
+
+std::unique_ptr<base::DictionaryValue> LayerImpl::LayerTreeAsJson() {
+ std::unique_ptr<base::DictionaryValue> result = LayerAsJson();
+
+ auto list = std::make_unique<base::ListValue>();
for (size_t i = 0; i < test_properties()->children.size(); ++i)
list->Append(test_properties()->children[i]->LayerTreeAsJson());
result->Set("Children", std::move(list));
@@ -460,7 +472,7 @@ void LayerImpl::NoteLayerPropertyChangedFromPropertyTrees() {
SetNeedsPushProperties();
}
-void LayerImpl::ValidateQuadResourcesInternal(DrawQuad* quad) const {
+void LayerImpl::ValidateQuadResourcesInternal(viz::DrawQuad* quad) const {
#if DCHECK_IS_ON()
const ResourceProvider* resource_provider =
layer_tree_impl_->resource_provider();
@@ -486,10 +498,6 @@ bool LayerImpl::has_copy_requests_in_target_subtree() {
return GetEffectTree().Node(effect_tree_index())->subtree_has_copy_request;
}
-gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const {
- return CurrentScrollOffset();
-}
-
bool LayerImpl::IsActive() const {
return layer_tree_impl_->IsActiveTree();
}
@@ -583,16 +591,14 @@ void LayerImpl::SetDrawsContent(bool draws_content) {
return;
draws_content_ = draws_content;
- if (draws_content)
- SetShouldHitTest(true);
NoteLayerPropertyChanged();
}
-void LayerImpl::SetShouldHitTest(bool should_hit_test) {
- if (should_hit_test_ == should_hit_test)
+void LayerImpl::SetHitTestableWithoutDrawsContent(bool should_hit_test) {
+ if (hit_testable_without_draws_content_ == should_hit_test)
return;
- should_hit_test_ = should_hit_test;
+ hit_testable_without_draws_content_ = should_hit_test;
NoteLayerPropertyChanged();
}
@@ -640,9 +646,8 @@ void LayerImpl::SetElementId(ElementId element_id) {
if (element_id == element_id_)
return;
- TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"),
- "LayerImpl::SetElementId", "element",
- element_id.AsValue().release());
+ TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug"), "LayerImpl::SetElementId",
+ "element", element_id.AsValue().release());
layer_tree_impl_->RemoveFromElementMap(this);
element_id_ = element_id;
@@ -651,18 +656,6 @@ void LayerImpl::SetElementId(ElementId element_id) {
SetNeedsPushProperties();
}
-void LayerImpl::SetMutableProperties(uint32_t properties) {
- if (mutable_properties_ == properties)
- return;
-
- TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"),
- "LayerImpl::SetMutableProperties", "properties", properties);
-
- mutable_properties_ = properties;
- // If this layer is already in the element map, update its properties.
- layer_tree_impl_->AddToElementMap(this);
-}
-
void LayerImpl::SetPosition(const gfx::PointF& position) {
position_ = position;
}
@@ -750,9 +743,6 @@ void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const {
if (element_id_)
element_id_.AddToTracedValue(state);
- if (mutable_properties_ != MutableProperty::kNone)
- state->SetInteger("mutable_properties", mutable_properties_);
-
MathUtil::AddToTracedValue("scroll_offset", CurrentScrollOffset(), state);
if (!ScreenSpaceTransform().IsIdentity())
@@ -781,9 +771,7 @@ void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const {
state->SetBoolean("has_will_change_transform_hint",
has_will_change_transform_hint());
- gfx::BoxF box;
- if (LayerUtils::GetAnimationBounds(*this, &box))
- MathUtil::AddToTracedValue("animation_bounds", box, state);
+ state->SetBoolean("trilinear_filtering", trilinear_filtering());
if (debug_info_) {
std::string str;
diff --git a/chromium/cc/layers/layer_impl.h b/chromium/cc/layers/layer_impl.h
index 5e207c6dab3..01032faf6e0 100644
--- a/chromium/cc/layers/layer_impl.h
+++ b/chromium/cc/layers/layer_impl.h
@@ -31,7 +31,6 @@
#include "cc/layers/performance_properties.h"
#include "cc/layers/render_surface_impl.h"
#include "cc/layers/touch_action_region.h"
-#include "cc/resources/resource_provider.h"
#include "cc/tiles/tile_priority.h"
#include "cc/trees/element_id.h"
#include "cc/trees/mutator_host_client.h"
@@ -52,14 +51,18 @@ class TracedValue;
class DictionaryValue;
}
+namespace viz {
+class RenderPass;
+}
+
namespace cc {
class AppendQuadsData;
class LayerTreeImpl;
+class LayerTreeResourceProvider;
class MicroBenchmarkImpl;
class MutatorHost;
class PrioritizedTile;
-class RenderPass;
class ScrollbarLayerImplBase;
class SimpleEnclosedRegion;
class Tile;
@@ -84,7 +87,6 @@ class CC_EXPORT LayerImpl {
int id() const { return layer_id_; }
// Interactions with attached animations.
- gfx::ScrollOffset ScrollOffsetForAnimation() const;
bool IsActive() const;
void SetHasTransformNode(bool val) { has_transform_node_ = val; }
@@ -125,10 +127,12 @@ class CC_EXPORT LayerImpl {
LayerTreeImpl* layer_tree_impl() const { return layer_tree_impl_; }
- void PopulateSharedQuadState(viz::SharedQuadState* state) const;
+ void PopulateSharedQuadState(viz::SharedQuadState* state,
+ bool contents_opaque) const;
void PopulateScaledSharedQuadState(viz::SharedQuadState* state,
float layer_to_content_scale_x,
- float layer_to_content_scale_y) const;
+ float layer_to_content_scale_y,
+ bool contents_opaque) const;
// WillDraw must be called before AppendQuads. If WillDraw returns false,
// AppendQuads and DidDraw will not be called. If WillDraw returns true,
// DidDraw is guaranteed to be called before another WillDraw or before
@@ -136,13 +140,13 @@ class CC_EXPORT LayerImpl {
// WillDraw/DidDraw must call the base class version only if WillDraw
// returns true.
virtual bool WillDraw(DrawMode draw_mode,
- ResourceProvider* resource_provider);
- virtual void AppendQuads(RenderPass* render_pass,
+ LayerTreeResourceProvider* resource_provider);
+ virtual void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) {}
- virtual void DidDraw(ResourceProvider* resource_provider);
+ virtual void DidDraw(LayerTreeResourceProvider* resource_provider);
// Verify that the resource ids in the quad are valid.
- void ValidateQuadResources(DrawQuad* quad) const {
+ void ValidateQuadResources(viz::DrawQuad* quad) const {
#if DCHECK_IS_ON()
ValidateQuadResourcesInternal(quad);
#endif
@@ -160,8 +164,17 @@ class CC_EXPORT LayerImpl {
void SetDrawsContent(bool draws_content);
bool DrawsContent() const { return draws_content_; }
- void SetShouldHitTest(bool should_hit_test);
- bool should_hit_test() const { return should_hit_test_; }
+ // Make the layer hit test (see: |should_hit_test|) even if !draws_content_.
+ void SetHitTestableWithoutDrawsContent(bool should_hit_test);
+ bool hit_testable_without_draws_content() const {
+ return hit_testable_without_draws_content_;
+ }
+
+ // True if either the layer draws content or has been marked as hit testable
+ // without draws_content.
+ bool should_hit_test() const {
+ return draws_content_ || hit_testable_without_draws_content_;
+ }
LayerImplTestProperties* test_properties() {
if (!test_properties_)
@@ -189,9 +202,6 @@ class CC_EXPORT LayerImpl {
void SetElementId(ElementId element_id);
ElementId element_id() const { return element_id_; }
- void SetMutableProperties(uint32_t properties);
- uint32_t mutable_properties() const { return mutable_properties_; }
-
void SetPosition(const gfx::PointF& position);
gfx::PointF position() const { return position_; }
@@ -332,7 +342,10 @@ class CC_EXPORT LayerImpl {
void AddDamageRect(const gfx::Rect& damage_rect);
const gfx::Rect& damage_rect() const { return damage_rect_; }
- virtual std::unique_ptr<base::DictionaryValue> LayerTreeAsJson();
+ virtual std::unique_ptr<base::DictionaryValue> LayerAsJson();
+ // TODO(pdr): This should be removed because there is no longer a tree
+ // of layers, only a list.
+ std::unique_ptr<base::DictionaryValue> LayerTreeAsJson();
// This includes |layer_property_changed_not_from_property_trees_| and
// property_trees changes.
@@ -420,6 +433,9 @@ class CC_EXPORT LayerImpl {
return has_will_change_transform_hint_;
}
+ void SetTrilinearFiltering(bool trilinear_filtering);
+ bool trilinear_filtering() const { return trilinear_filtering_; }
+
MutatorHost* GetMutatorHost() const;
ElementListType GetElementTypeForAnimation() const;
@@ -443,12 +459,12 @@ class CC_EXPORT LayerImpl {
// Get the color and size of the layer's debug border.
virtual void GetDebugBorderProperties(SkColor* color, float* width) const;
- void AppendDebugBorderQuad(RenderPass* render_pass,
- const gfx::Size& bounds,
+ void AppendDebugBorderQuad(viz::RenderPass* render_pass,
+ const gfx::Rect& quad_rect,
const viz::SharedQuadState* shared_quad_state,
AppendQuadsData* append_quads_data) const;
- void AppendDebugBorderQuad(RenderPass* render_pass,
- const gfx::Size& bounds,
+ void AppendDebugBorderQuad(viz::RenderPass* render_pass,
+ const gfx::Rect& quad_rect,
const viz::SharedQuadState* shared_quad_state,
AppendQuadsData* append_quads_data,
SkColor color,
@@ -457,7 +473,7 @@ class CC_EXPORT LayerImpl {
gfx::Rect GetScaledEnclosingRectInTargetSpace(float scale) const;
private:
- void ValidateQuadResourcesInternal(DrawQuad* quad) const;
+ void ValidateQuadResourcesInternal(viz::DrawQuad* quad) const;
virtual const char* LayerTypeAsString() const;
@@ -499,7 +515,11 @@ class CC_EXPORT LayerImpl {
bool should_check_backface_visibility_ : 1;
bool draws_content_ : 1;
bool contributes_to_drawn_render_surface_ : 1;
- bool should_hit_test_ : 1;
+
+ // Hit testing depends on draws_content (see: |LayerImpl::should_hit_test|)
+ // and this bit can be set to cause the layer to be hit testable without
+ // draws_content.
+ bool hit_testable_without_draws_content_ : 1;
bool is_resized_by_browser_controls_ : 1;
static_assert(LAST_VIEWPORT_LAYER_TYPE < (1u << 3),
@@ -532,7 +552,6 @@ class CC_EXPORT LayerImpl {
TransformTree& GetTransformTree() const;
ElementId element_id_;
- uint32_t mutable_properties_;
// Rect indicating what was repainted/updated during update.
// Note that plugin layers bypass this and leave it empty.
// This is in the layer's space.
@@ -552,6 +571,7 @@ class CC_EXPORT LayerImpl {
base::trace_event::ConvertableToTraceFormat* debug_info_;
bool has_will_change_transform_hint_ : 1;
+ bool trilinear_filtering_ : 1;
bool needs_push_properties_ : 1;
bool scrollbars_hidden_ : 1;
diff --git a/chromium/cc/layers/layer_impl_test_properties.cc b/chromium/cc/layers/layer_impl_test_properties.cc
index bb6ee3cb704..76f868fb6bc 100644
--- a/chromium/cc/layers/layer_impl_test_properties.cc
+++ b/chromium/cc/layers/layer_impl_test_properties.cc
@@ -6,13 +6,14 @@
#include "cc/layers/layer_impl.h"
#include "cc/trees/layer_tree_impl.h"
-#include "components/viz/common/quads/copy_output_request.h"
+#include "components/viz/common/frame_sinks/copy_output_request.h"
namespace cc {
LayerImplTestProperties::LayerImplTestProperties(LayerImpl* owning_layer)
: owning_layer(owning_layer),
double_sided(true),
+ trilinear_filtering(false),
cache_render_surface(false),
force_render_surface(false),
is_container_for_fixed_position_layers(false),
diff --git a/chromium/cc/layers/layer_impl_test_properties.h b/chromium/cc/layers/layer_impl_test_properties.h
index 5347236035c..fad5abd18c5 100644
--- a/chromium/cc/layers/layer_impl_test_properties.h
+++ b/chromium/cc/layers/layer_impl_test_properties.h
@@ -36,6 +36,7 @@ struct CC_EXPORT LayerImplTestProperties {
LayerImpl* owning_layer;
bool double_sided;
+ bool trilinear_filtering;
bool cache_render_surface;
bool force_render_surface;
bool is_container_for_fixed_position_layers;
diff --git a/chromium/cc/layers/layer_impl_unittest.cc b/chromium/cc/layers/layer_impl_unittest.cc
index c17ccb7ebf7..f3256692005 100644
--- a/chromium/cc/layers/layer_impl_unittest.cc
+++ b/chromium/cc/layers/layer_impl_unittest.cc
@@ -15,7 +15,6 @@
#include "cc/test/geometry_test_utils.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/trees/layer_tree_impl.h"
-#include "cc/trees/mutable_properties.h"
#include "cc/trees/single_thread_proxy.h"
#include "cc/trees/tree_synchronizer.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -191,9 +190,6 @@ TEST(LayerImplTest, VerifyPendingLayerChangesAreTrackedProperly) {
// but does cause the layer to need to push properties.
EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE(
root->SetElementId(ElementId(2)));
- EXECUTE_AND_VERIFY_NEEDS_PUSH_PROPERTIES_AND_SUBTREE_DID_NOT_CHANGE(
- root->SetMutableProperties(MutableProperty::kOpacity);
- root->SetNeedsPushProperties());
// After setting all these properties already, setting to the exact same
// values again should not cause any change.
@@ -392,8 +388,6 @@ TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) {
layer->SetBackgroundColor(arbitrary_color));
VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(arbitrary_size));
VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetElementId(ElementId(2)));
- VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(
- layer->SetMutableProperties(MutableProperty::kTransform));
}
TEST(LayerImplTest, SafeOpaqueBackgroundColor) {
@@ -480,13 +474,24 @@ TEST(LayerImplTest, PerspectiveTransformHasReasonableScale) {
ASSERT_TRUE(layer->ScreenSpaceTransform().HasPerspective());
EXPECT_FLOAT_EQ(127.f, layer->GetIdealContentsScale());
}
+ // Test case from crbug.com/766021.
+ {
+ gfx::Transform transform(-0.9397f, -0.7019f, 0.2796f, 2383.4521f, // row 1
+ -0.0038f, 0.0785f, 1.0613f, 1876.4553f, // row 2
+ -0.0835f, 0.9081f, -0.4105f, -2208.3035f, // row 3
+ 0.0001f, -0.0008f, 0.0003f, 2.8435f); // row 4
+ layer->draw_properties().screen_space_transform = transform;
+
+ ASSERT_TRUE(layer->ScreenSpaceTransform().HasPerspective());
+ EXPECT_FLOAT_EQ(1.f, layer->GetIdealContentsScale());
+ }
}
class LayerImplScrollTest : public testing::Test {
public:
LayerImplScrollTest() : LayerImplScrollTest(LayerTreeSettings()) {}
- LayerImplScrollTest(const LayerTreeSettings& settings)
+ explicit LayerImplScrollTest(const LayerTreeSettings& settings)
: host_impl_(settings, &task_runner_provider_, &task_graph_runner_),
root_id_(7) {
host_impl_.active_tree()->SetRootLayerForTesting(
diff --git a/chromium/cc/layers/layer_position_constraint_unittest.cc b/chromium/cc/layers/layer_position_constraint_unittest.cc
index 1afd8382e02..0b3be1b2254 100644
--- a/chromium/cc/layers/layer_position_constraint_unittest.cc
+++ b/chromium/cc/layers/layer_position_constraint_unittest.cc
@@ -94,8 +94,9 @@ class LayerPositionConstraintTest : public testing::Test {
outer_viewport_container_layer_ = Layer::Create();
child_transform_layer_ = Layer::Create();
child_ = Layer::Create();
- grand_child_ = make_scoped_refptr(new LayerWithForcedDrawsContent());
- great_grand_child_ = make_scoped_refptr(new LayerWithForcedDrawsContent());
+ grand_child_ = base::WrapRefCounted(new LayerWithForcedDrawsContent());
+ great_grand_child_ =
+ base::WrapRefCounted(new LayerWithForcedDrawsContent());
gfx::Transform IdentityMatrix;
gfx::Point3F transform_origin;
@@ -569,7 +570,7 @@ TEST_F(LayerPositionConstraintTest,
// Add one more layer to the test tree for this scenario.
scoped_refptr<Layer> fixed_position_child =
- make_scoped_refptr(new LayerWithForcedDrawsContent());
+ base::WrapRefCounted(new LayerWithForcedDrawsContent());
SetLayerPropertiesForTesting(fixed_position_child.get(), gfx::Transform(),
gfx::Point3F(), gfx::PointF(),
gfx::Size(100, 100), true);
@@ -729,7 +730,7 @@ TEST_F(
// Add one more layer to the test tree for this scenario.
scoped_refptr<Layer> fixed_position_child =
- make_scoped_refptr(new LayerWithForcedDrawsContent());
+ base::WrapRefCounted(new LayerWithForcedDrawsContent());
SetLayerPropertiesForTesting(fixed_position_child.get(), gfx::Transform(),
gfx::Point3F(), gfx::PointF(),
gfx::Size(100, 100), true);
@@ -1066,7 +1067,7 @@ TEST_F(LayerPositionConstraintTest,
// Add one more layer to the hierarchy for this test.
scoped_refptr<Layer> great_great_grand_child =
- make_scoped_refptr(new LayerWithForcedDrawsContent());
+ base::WrapRefCounted(new LayerWithForcedDrawsContent());
great_grand_child_->AddChild(great_great_grand_child);
child_->SetIsContainerForFixedPositionLayers(true);
@@ -1122,7 +1123,7 @@ TEST_F(LayerPositionConstraintTest,
// This test checks for correct scroll compensation when the fixed-position
// container is the outer viewport scroll layer and has non-zero bounds delta.
scoped_refptr<Layer> fixed_child =
- make_scoped_refptr(new LayerWithForcedDrawsContent());
+ base::WrapRefCounted(new LayerWithForcedDrawsContent());
fixed_child->SetBounds(gfx::Size(300, 300));
child_->AddChild(fixed_child);
fixed_child->SetPositionConstraint(fixed_to_top_left_);
diff --git a/chromium/cc/layers/layer_unittest.cc b/chromium/cc/layers/layer_unittest.cc
index e727164480d..5dc671cf3c2 100644
--- a/chromium/cc/layers/layer_unittest.cc
+++ b/chromium/cc/layers/layer_unittest.cc
@@ -22,14 +22,14 @@
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/geometry_test_utils.h"
#include "cc/test/layer_test_common.h"
+#include "cc/test/mock_layer_client.h"
#include "cc/test/stub_layer_tree_host_single_thread_client.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/trees/layer_tree_host.h"
-#include "cc/trees/mutable_properties.h"
#include "cc/trees/single_thread_proxy.h"
#include "cc/trees/transform_node.h"
-#include "components/viz/common/quads/copy_output_request.h"
-#include "components/viz/common/quads/copy_output_result.h"
+#include "components/viz/common/frame_sinks/copy_output_request.h"
+#include "components/viz/common/frame_sinks/copy_output_result.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkColor.h"
@@ -923,8 +923,6 @@ TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) {
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetForceRenderSurfaceForTesting(true));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetHideLayerAndSubtree(true));
EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetElementId(ElementId(2)));
- EXPECT_SET_NEEDS_COMMIT(
- 1, test_layer->SetMutableProperties(MutableProperty::kTransform));
EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, test_layer->SetMaskLayer(
dummy_layer1.get()));
@@ -1266,7 +1264,7 @@ TEST_F(LayerTest, SafeOpaqueBackgroundColor) {
class DrawsContentChangeLayer : public Layer {
public:
static scoped_refptr<DrawsContentChangeLayer> Create() {
- return make_scoped_refptr(new DrawsContentChangeLayer());
+ return base::WrapRefCounted(new DrawsContentChangeLayer());
}
void SetLayerTreeHost(LayerTreeHost* host) override {
@@ -1308,6 +1306,38 @@ TEST_F(LayerTest, DrawsContentChangedInSetLayerTreeHost) {
EXPECT_EQ(1, root_layer->NumDescendantsThatDrawContent());
}
+TEST_F(LayerTest, PushUpdatesShouldHitTest) {
+ scoped_refptr<Layer> root_layer = Layer::Create();
+ std::unique_ptr<LayerImpl> impl_layer =
+ LayerImpl::Create(host_impl_.active_tree(), 1);
+ EXPECT_SET_NEEDS_FULL_TREE_SYNC(1,
+ layer_tree_host_->SetRootLayer(root_layer));
+ EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(3);
+
+ // A layer that draws content should be hit testable.
+ root_layer->SetIsDrawable(true);
+ root_layer->PushPropertiesTo(impl_layer.get());
+ EXPECT_TRUE(impl_layer->DrawsContent());
+ EXPECT_FALSE(impl_layer->hit_testable_without_draws_content());
+ EXPECT_TRUE(impl_layer->should_hit_test());
+
+ // A layer that does not draw content and does not hit test without drawing
+ // content should not be hit testable.
+ root_layer->SetIsDrawable(false);
+ root_layer->PushPropertiesTo(impl_layer.get());
+ EXPECT_FALSE(impl_layer->DrawsContent());
+ EXPECT_FALSE(impl_layer->hit_testable_without_draws_content());
+ EXPECT_FALSE(impl_layer->should_hit_test());
+
+ // |SetHitTestableWithoutDrawsContent| should cause a layer to become hit
+ // testable even though it does not draw content.
+ root_layer->SetHitTestableWithoutDrawsContent(true);
+ root_layer->PushPropertiesTo(impl_layer.get());
+ EXPECT_FALSE(impl_layer->DrawsContent());
+ EXPECT_TRUE(impl_layer->hit_testable_without_draws_content());
+ EXPECT_TRUE(impl_layer->should_hit_test());
+}
+
void ReceiveCopyOutputResult(int* result_count,
std::unique_ptr<viz::CopyOutputResult> result) {
++(*result_count);
@@ -1320,11 +1350,13 @@ TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) {
// Create identical requests without the source being set, and expect the
// layer does not abort either one.
std::unique_ptr<viz::CopyOutputRequest> request =
- viz::CopyOutputRequest::CreateRequest(
+ std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
base::BindOnce(&ReceiveCopyOutputResult, &result_count));
layer->RequestCopyOfOutput(std::move(request));
EXPECT_EQ(0, result_count);
- request = viz::CopyOutputRequest::CreateRequest(
+ request = std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
base::BindOnce(&ReceiveCopyOutputResult, &result_count));
layer->RequestCopyOfOutput(std::move(request));
EXPECT_EQ(0, result_count);
@@ -1340,28 +1372,36 @@ TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) {
// the first request using |kArbitrarySourceId1| aborts immediately when
// the second request using |kArbitrarySourceId1| is made.
int did_receive_first_result_from_this_source = 0;
- request = viz::CopyOutputRequest::CreateRequest(base::BindOnce(
- &ReceiveCopyOutputResult, &did_receive_first_result_from_this_source));
+ request = std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
+ base::BindOnce(&ReceiveCopyOutputResult,
+ &did_receive_first_result_from_this_source));
request->set_source(kArbitrarySourceId1);
layer->RequestCopyOfOutput(std::move(request));
EXPECT_EQ(0, did_receive_first_result_from_this_source);
// Make a request from a different source.
int did_receive_result_from_different_source = 0;
- request = viz::CopyOutputRequest::CreateRequest(base::BindOnce(
- &ReceiveCopyOutputResult, &did_receive_result_from_different_source));
+ request = std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
+ base::BindOnce(&ReceiveCopyOutputResult,
+ &did_receive_result_from_different_source));
request->set_source(kArbitrarySourceId2);
layer->RequestCopyOfOutput(std::move(request));
EXPECT_EQ(0, did_receive_result_from_different_source);
// Make a request without specifying the source.
int did_receive_result_from_anonymous_source = 0;
- request = viz::CopyOutputRequest::CreateRequest(base::BindOnce(
- &ReceiveCopyOutputResult, &did_receive_result_from_anonymous_source));
+ request = std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
+ base::BindOnce(&ReceiveCopyOutputResult,
+ &did_receive_result_from_anonymous_source));
layer->RequestCopyOfOutput(std::move(request));
EXPECT_EQ(0, did_receive_result_from_anonymous_source);
// Make the second request from |kArbitrarySourceId1|.
int did_receive_second_result_from_this_source = 0;
- request = viz::CopyOutputRequest::CreateRequest(base::BindOnce(
- &ReceiveCopyOutputResult, &did_receive_second_result_from_this_source));
+ request = std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
+ base::BindOnce(&ReceiveCopyOutputResult,
+ &did_receive_second_result_from_this_source));
request->set_source(kArbitrarySourceId1);
layer->RequestCopyOfOutput(
std::move(request)); // First request to be aborted.
@@ -1407,7 +1447,7 @@ TEST_F(LayerTest, AnimationSchedulesLayerUpdate) {
Mock::VerifyAndClearExpectations(layer_tree_host_.get());
}
-TEST_F(LayerTest, ElementIdAndMutablePropertiesArePushed) {
+TEST_F(LayerTest, ElementIdIsPushed) {
scoped_refptr<Layer> test_layer = Layer::Create();
std::unique_ptr<LayerImpl> impl_layer =
LayerImpl::Create(host_impl_.active_tree(), 1);
@@ -1415,18 +1455,15 @@ TEST_F(LayerTest, ElementIdAndMutablePropertiesArePushed) {
EXPECT_SET_NEEDS_FULL_TREE_SYNC(1,
layer_tree_host_->SetRootLayer(test_layer));
- EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(2);
+ EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1);
test_layer->SetElementId(ElementId(2));
- test_layer->SetMutableProperties(MutableProperty::kTransform);
EXPECT_FALSE(impl_layer->element_id());
- EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties());
test_layer->PushPropertiesTo(impl_layer.get());
EXPECT_EQ(ElementId(2), impl_layer->element_id());
- EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties());
}
TEST_F(LayerTest, SetLayerTreeHostNotUsingLayerListsManagesElementId) {
@@ -1476,6 +1513,26 @@ TEST_F(LayerTest, SetElementIdNotUsingLayerLists) {
test_layer->SetLayerTreeHost(nullptr);
}
+// Verify that LayerClient::DidChangeLayerOpacity() is called when
+// Layer::SetOpacity() is called and the opacity changes.
+TEST_F(LayerTest, SetOpacityNotifiesClient) {
+ testing::StrictMock<MockLayerClient> client;
+ scoped_refptr<Layer> layer = Layer::Create();
+ layer->SetLayerClient(&client);
+ EXPECT_CALL(client, DidChangeLayerOpacity(1.0f, 0.5f));
+ layer->SetOpacity(0.5f);
+}
+
+// Verify that LayerClient::DidChangeLayerOpacity() is not called when
+// Layer::SetOpacity() is called but the opacity does not change.
+TEST_F(LayerTest, SetOpacityNoChangeDoesNotNotifyClient) {
+ testing::StrictMock<MockLayerClient> client;
+ scoped_refptr<Layer> layer = Layer::Create();
+ layer->SetLayerClient(&client);
+ // Since |client| is a StrictMock, the test will fail if it is notified.
+ layer->SetOpacity(1.0f);
+}
+
class LayerTestWithLayerLists : public LayerTest {
protected:
void SetUp() override {
diff --git a/chromium/cc/layers/layer_utils.cc b/chromium/cc/layers/layer_utils.cc
deleted file mode 100644
index 715fd06faad..00000000000
--- a/chromium/cc/layers/layer_utils.cc
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/layers/layer_utils.h"
-
-#include "cc/layers/layer_impl.h"
-#include "cc/trees/layer_tree_host_common.h"
-#include "cc/trees/layer_tree_impl.h"
-#include "cc/trees/transform_node.h"
-#include "ui/gfx/geometry/box_f.h"
-
-namespace cc {
-
-namespace {
-
-inline bool HasAncestorTransformAnimation(const TransformNode* transform_node) {
- return transform_node->to_screen_is_potentially_animated;
-}
-
-inline bool HasAncestorFilterAnimation(const LayerImpl& layer) {
- // This function returns false, it should use the effect tree once filters
- // and filter animations are known by the tree.
- return false;
-}
-
-} // namespace
-
-bool LayerUtils::GetAnimationBounds(const LayerImpl& layer_in, gfx::BoxF* out) {
- // We don't care about animated bounds for invisible layers.
- if (!layer_in.DrawsContent())
- return false;
-
- TransformTree& transform_tree =
- layer_in.layer_tree_impl()->property_trees()->transform_tree;
-
- // We also don't care for layers that are not animated or a child of an
- // animated layer.
- if (!HasAncestorTransformAnimation(
- transform_tree.Node(layer_in.transform_tree_index())) &&
- !HasAncestorFilterAnimation(layer_in))
- return false;
-
- // To compute the inflated bounds for a layer, we start by taking its bounds
- // and converting it to a 3d box, and then we transform or inflate it
- // repeatedly as we walk up the transform tree to the root.
- //
- // At each transform_node without transform animation that inflates bounds:
- //
- // 1) We concat transform_node->data.to_parent to the coalesced_transform.
- //
- // At each transform_node with a transform animation that inflates bounds:
- //
- // 1) We concat transform_node->data.pre_local to the coalesced_transform.
- // This is to translate the box so that the anchor point is the origin.
- // 2) We apply coalesced_transform to the 3d box and make the transform
- // identity. This is apply the accumulated transform to the box to inflate
- // it.
- // 3) We inflate the 3d box for animation as the node has a animated
- // transform.
- // 4) We concat transform_node->data.post_local to the coalesced_transform.
- // This step undoes the translation in step (1), accounts for the layer's
- // position and the 2d translation to the space of the parent transform
- // node.
-
- gfx::BoxF box(layer_in.bounds().width(), layer_in.bounds().height(), 0.f);
-
- // We want to inflate/transform the box as few times as possible. Each time
- // we do this, we have to make the box axis aligned again, so if we make many
- // small adjustments to the box by transforming it repeatedly rather than
- // once by the product of all these matrices, we will accumulate a bunch of
- // unnecessary inflation because of the the many axis-alignment fixes. This
- // matrix stores said product.
- gfx::Transform coalesced_transform;
-
- const TransformNode* transform_node =
- transform_tree.Node(layer_in.transform_tree_index());
-
- // If layer_in has a transform node, the offset_to_transform_parent() is 0
- coalesced_transform.Translate(layer_in.offset_to_transform_parent().x(),
- layer_in.offset_to_transform_parent().y());
-
- for (; transform_tree.parent(transform_node);
- transform_node = transform_tree.parent(transform_node)) {
- // Filter animation bounds are unimplemented, see function
- // HasAncestorFilterAnimation() for reference.
-
- if (transform_node->element_id != ElementId() &&
- layer_in.GetMutatorHost()->HasTransformAnimationThatInflatesBounds(
- transform_node->element_id)) {
- coalesced_transform.ConcatTransform(transform_node->pre_local);
- coalesced_transform.TransformBox(&box);
- coalesced_transform.MakeIdentity();
-
- gfx::BoxF inflated;
- if (!layer_in.GetMutatorHost()->TransformAnimationBoundsForBox(
- transform_node->element_id, box, &inflated))
- return false;
- box = inflated;
-
- coalesced_transform.ConcatTransform(transform_node->post_local);
- } else {
- coalesced_transform.ConcatTransform(transform_node->to_parent);
- }
- }
-
- // If we've got an unapplied coalesced transform at this point, it must still
- // be applied.
- if (!coalesced_transform.IsIdentity())
- coalesced_transform.TransformBox(&box);
-
- *out = box;
-
- return true;
-}
-
-} // namespace cc
diff --git a/chromium/cc/layers/layer_utils.h b/chromium/cc/layers/layer_utils.h
deleted file mode 100644
index e4a20888ee1..00000000000
--- a/chromium/cc/layers/layer_utils.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_LAYERS_LAYER_UTILS_H_
-#define CC_LAYERS_LAYER_UTILS_H_
-
-#include "cc/cc_export.h"
-
-namespace gfx {
-class BoxF;
-} // namespace gfx
-
-namespace cc {
-class LayerImpl;
-
-class CC_EXPORT LayerUtils {
- public:
- // Computes a box in screen space that should entirely contain the layer's
- // bounds through the entirety of the layer's current animation. Returns
- // true and sets |out| to the inflation if there are animations that can
- // inflate bounds in the path to the root layer and that it was able to
- // inflate correctly. Returns false otherwise.
- static bool GetAnimationBounds(const LayerImpl& layer, gfx::BoxF* out);
-};
-
-} // namespace cc
-
-#endif // CC_LAYERS_LAYER_UTILS_H_
diff --git a/chromium/cc/layers/layer_utils_unittest.cc b/chromium/cc/layers/layer_utils_unittest.cc
deleted file mode 100644
index 119ce90ea9a..00000000000
--- a/chromium/cc/layers/layer_utils_unittest.cc
+++ /dev/null
@@ -1,585 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/layers/layer_utils.h"
-
-#include "cc/animation/animation_host.h"
-#include "cc/animation/animation_id_provider.h"
-#include "cc/animation/transform_operations.h"
-#include "cc/layers/layer_impl.h"
-#include "cc/test/animation_test_common.h"
-#include "cc/test/fake_impl_task_runner_provider.h"
-#include "cc/test/fake_layer_tree_host_impl.h"
-#include "cc/test/test_task_graph_runner.h"
-#include "cc/trees/layer_tree_host_common.h"
-#include "cc/trees/layer_tree_impl.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/geometry/box_f.h"
-#include "ui/gfx/test/gfx_util.h"
-
-namespace cc {
-namespace {
-
-float diagonal(float width, float height) {
- return std::sqrt(width * width + height * height);
-}
-
-class LayerUtilsGetAnimationBoundsTest : public testing::Test {
- public:
- LayerUtilsGetAnimationBoundsTest()
- : host_impl_(&task_runner_provider_, &task_graph_runner_),
- root_(CreateTwoForkTree(&host_impl_)),
- parent1_(root_->test_properties()->children[0]),
- parent2_(root_->test_properties()->children[1]),
- child1_(parent1_->test_properties()->children[0]),
- child2_(parent2_->test_properties()->children[0]),
- grand_child_(child2_->test_properties()->children[0]),
- great_grand_child_(grand_child_->test_properties()->children[0]) {
- timeline_ =
- AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
- host_impl_.animation_host()->AddAnimationTimeline(timeline_);
- host_impl_.active_tree()->SetElementIdsForTesting();
- }
-
- LayerImpl* root() { return root_; }
- LayerImpl* parent1() { return parent1_; }
- LayerImpl* child1() { return child1_; }
- LayerImpl* parent2() { return parent2_; }
- LayerImpl* child2() { return child2_; }
- LayerImpl* grand_child() { return grand_child_; }
- LayerImpl* great_grand_child() { return great_grand_child_; }
-
- scoped_refptr<AnimationTimeline> timeline() { return timeline_; }
- FakeLayerTreeHostImpl& host_impl() { return host_impl_; }
-
- private:
- static LayerImpl* CreateTwoForkTree(LayerTreeHostImpl* host_impl) {
- std::unique_ptr<LayerImpl> root =
- LayerImpl::Create(host_impl->active_tree(), 1);
- LayerImpl* root_ptr = root.get();
- root->test_properties()->AddChild(
- LayerImpl::Create(host_impl->active_tree(), 2));
- root->test_properties()->children[0]->test_properties()->AddChild(
- LayerImpl::Create(host_impl->active_tree(), 3));
- root->test_properties()->AddChild(
- LayerImpl::Create(host_impl->active_tree(), 4));
- root->test_properties()->children[1]->test_properties()->AddChild(
- LayerImpl::Create(host_impl->active_tree(), 5));
- root->test_properties()
- ->children[1]
- ->test_properties()
- ->children[0]
- ->test_properties()
- ->AddChild(LayerImpl::Create(host_impl->active_tree(), 6));
- root->test_properties()
- ->children[1]
- ->test_properties()
- ->children[0]
- ->test_properties()
- ->children[0]
- ->test_properties()
- ->AddChild(LayerImpl::Create(host_impl->active_tree(), 7));
- host_impl->active_tree()->SetRootLayerForTesting(std::move(root));
- return root_ptr;
- }
-
- FakeImplTaskRunnerProvider task_runner_provider_;
- TestTaskGraphRunner task_graph_runner_;
- FakeLayerTreeHostImpl host_impl_;
- LayerImpl* root_;
- LayerImpl* parent1_;
- LayerImpl* parent2_;
- LayerImpl* child1_;
- LayerImpl* child2_;
- LayerImpl* grand_child_;
- LayerImpl* great_grand_child_;
- scoped_refptr<AnimationTimeline> timeline_;
-};
-
-TEST_F(LayerUtilsGetAnimationBoundsTest, ScaleRoot) {
- double duration = 1.0;
-
- TransformOperations start;
- start.AppendScale(1.f, 1.f, 1.f);
- TransformOperations end;
- end.AppendScale(2.f, 2.f, 1.f);
- AddAnimatedTransformToElementWithPlayer(root()->element_id(), timeline(),
- duration, start, end);
-
- root()->SetPosition(gfx::PointF());
- parent1()->SetPosition(gfx::PointF());
- parent1()->SetBounds(gfx::Size(350, 200));
-
- child1()->SetDrawsContent(true);
- child1()->SetPosition(gfx::PointF(150.f, 50.f));
- child1()->SetBounds(gfx::Size(100, 200));
-
- host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
-
- gfx::BoxF box;
- bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
- EXPECT_TRUE(success);
- gfx::BoxF expected(150.f, 50.f, 0.f, 350.f, 450.f, 0.f);
- EXPECT_BOXF_EQ(expected, box);
-}
-
-TEST_F(LayerUtilsGetAnimationBoundsTest, TranslateParentLayer) {
- double duration = 1.0;
-
- TransformOperations start;
- start.AppendTranslate(0.f, 0.f, 0.f);
- TransformOperations end;
- end.AppendTranslate(50.f, 50.f, 0.f);
- AddAnimatedTransformToElementWithPlayer(parent1()->element_id(), timeline(),
- duration, start, end);
-
- parent1()->SetBounds(gfx::Size(350, 200));
-
- child1()->SetDrawsContent(true);
- child1()->SetPosition(gfx::PointF(150.f, 50.f));
- child1()->SetBounds(gfx::Size(100, 200));
-
- host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
-
- gfx::BoxF box;
- bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
- EXPECT_TRUE(success);
- gfx::BoxF expected(150.f, 50.f, 0.f, 150.f, 250.f, 0.f);
- EXPECT_BOXF_EQ(expected, box);
-}
-
-TEST_F(LayerUtilsGetAnimationBoundsTest, TranslateChildLayer) {
- double duration = 1.0;
-
- TransformOperations start;
- start.AppendTranslate(0.f, 0.f, 0.f);
- TransformOperations end;
- end.AppendTranslate(50.f, 50.f, 0.f);
- AddAnimatedTransformToElementWithPlayer(child1()->element_id(), timeline(),
- duration, start, end);
- parent1()->SetBounds(gfx::Size(350, 200));
-
- child1()->SetDrawsContent(true);
- child1()->SetPosition(gfx::PointF(150.f, 50.f));
- child1()->SetBounds(gfx::Size(100, 200));
-
- host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
-
- gfx::BoxF box;
- bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
- EXPECT_TRUE(success);
- gfx::BoxF expected(150.f, 50.f, 0.f, 150.f, 250.f, 0.f);
- EXPECT_BOXF_EQ(expected, box);
-}
-
-TEST_F(LayerUtilsGetAnimationBoundsTest, TranslateBothLayers) {
- double duration = 1.0;
-
- TransformOperations start;
- start.AppendTranslate(0.f, 0.f, 0.f);
- TransformOperations child_end;
- child_end.AppendTranslate(50.f, 0.f, 0.f);
- AddAnimatedTransformToElementWithPlayer(parent1()->element_id(), timeline(),
- duration, start, child_end);
-
- TransformOperations grand_child_end;
- grand_child_end.AppendTranslate(0.f, 50.f, 0.f);
- AddAnimatedTransformToElementWithPlayer(child1()->element_id(), timeline(),
- duration, start, grand_child_end);
-
- parent1()->SetBounds(gfx::Size(350, 200));
-
- child1()->SetDrawsContent(true);
- child1()->SetPosition(gfx::PointF(150.f, 50.f));
- child1()->SetBounds(gfx::Size(100, 200));
-
- host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
-
- gfx::BoxF box;
- bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
- EXPECT_TRUE(success);
- gfx::BoxF expected(150.f, 50.f, 0.f, 150.f, 250.f, 0.f);
- EXPECT_BOXF_EQ(expected, box);
-}
-
-TEST_F(LayerUtilsGetAnimationBoundsTest, RotateXNoPerspective) {
- double duration = 1.0;
-
- TransformOperations start;
- start.AppendRotate(1.f, 0.f, 0.f, 0.f);
- TransformOperations end;
- end.AppendRotate(1.f, 0.f, 0.f, 90.f);
-
- AddAnimatedTransformToElementWithPlayer(child1()->element_id(), timeline(),
- duration, start, end);
-
- parent1()->SetBounds(gfx::Size(350, 200));
-
- gfx::Size bounds(100, 100);
- child1()->SetDrawsContent(true);
- child1()->SetPosition(gfx::PointF(150.f, 50.f));
- child1()->SetBounds(bounds);
- child1()->test_properties()->transform_origin =
- gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0);
-
- host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
-
- gfx::BoxF box;
- bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
- EXPECT_TRUE(success);
- gfx::BoxF expected(150.f, 50.f, -50.f, 100.f, 100.f, 100.f);
- EXPECT_BOXF_EQ(expected, box);
-}
-
-TEST_F(LayerUtilsGetAnimationBoundsTest, RotateXWithPerspective) {
- double duration = 1.0;
-
- TransformOperations start;
- start.AppendRotate(1.f, 0.f, 0.f, 0.f);
- TransformOperations end;
- end.AppendRotate(1.f, 0.f, 0.f, 90.f);
-
- AddAnimatedTransformToElementWithPlayer(child1()->element_id(), timeline(),
- duration, start, end);
-
- // Make the anchor point not the default 0.5 value and line up with the
- // child center to make the math easier.
- parent1()->test_properties()->transform_origin =
- gfx::Point3F(0.375f * 400.f, 0.375f * 400.f, 0.f);
- parent1()->SetBounds(gfx::Size(400, 400));
-
- gfx::Transform perspective;
- perspective.ApplyPerspectiveDepth(100.f);
- parent1()->test_properties()->transform = perspective;
-
- gfx::Size bounds(100, 100);
- child1()->SetDrawsContent(true);
- child1()->SetPosition(gfx::PointF(100.f, 100.f));
- child1()->SetBounds(bounds);
- child1()->test_properties()->transform_origin =
- gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0);
-
- host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
-
- gfx::BoxF box;
- bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
- EXPECT_TRUE(success);
- gfx::BoxF expected(50.f, 50.f, -33.333336f, 200.f, 200.f, 133.333344f);
- EXPECT_BOXF_EQ(expected, box);
-}
-
-TEST_F(LayerUtilsGetAnimationBoundsTest, RotateXWithPerspectiveOnSameLayer) {
- // This test is used to check whether GetAnimationBounds correctly ignores the
- // local transform when there is an animation applied to the layer / node.
- // The intended behavior is that the animation should overwrite the transform.
-
- double duration = 1.0;
-
- TransformOperations start;
- start.AppendRotate(1.f, 0.f, 0.f, 0.f);
- TransformOperations end;
- end.AppendRotate(1.f, 0.f, 0.f, 90.f);
-
- AddAnimatedTransformToElementWithPlayer(parent1()->element_id(), timeline(),
- duration, start, end);
-
- // Make the anchor point not the default 0.5 value and line up
- // with the child center to make the math easier.
- parent1()->test_properties()->transform_origin =
- gfx::Point3F(0.375f * 400.f, 0.375f * 400.f, 0.f);
- parent1()->SetBounds(gfx::Size(400, 400));
-
- gfx::Transform perspective;
- perspective.ApplyPerspectiveDepth(100.f);
- parent1()->test_properties()->transform = perspective;
-
- gfx::Size bounds(100, 100);
- child1()->SetDrawsContent(true);
- child1()->SetPosition(gfx::PointF(100.f, 100.f));
- child1()->SetBounds(bounds);
- child1()->test_properties()->transform_origin =
- gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0);
-
- host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
-
- gfx::BoxF box;
- bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
- EXPECT_TRUE(success);
- gfx::BoxF expected(100.f, 100.f, -50.f, 100.f, 100.f, 100.f);
- EXPECT_BOXF_EQ(expected, box);
-}
-
-TEST_F(LayerUtilsGetAnimationBoundsTest, RotateZ) {
- double duration = 1.0;
-
- TransformOperations start;
- start.AppendRotate(0.f, 0.f, 1.f, 0.f);
- TransformOperations end;
- end.AppendRotate(0.f, 0.f, 1.f, 90.f);
- AddAnimatedTransformToElementWithPlayer(child1()->element_id(), timeline(),
- duration, start, end);
-
- parent1()->SetBounds(gfx::Size(350, 200));
-
- gfx::Size bounds(100, 100);
- child1()->SetDrawsContent(true);
- child1()->SetPosition(gfx::PointF(150.f, 50.f));
- child1()->SetBounds(bounds);
- child1()->test_properties()->transform_origin =
- gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0);
-
- host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
-
- gfx::BoxF box;
- bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
- EXPECT_TRUE(success);
- float diag = diagonal(bounds.width(), bounds.height());
- gfx::BoxF expected(150.f + 0.5f * (bounds.width() - diag),
- 50.f + 0.5f * (bounds.height() - diag),
- 0.f,
- diag,
- diag,
- 0.f);
- EXPECT_BOXF_EQ(expected, box);
-}
-
-TEST_F(LayerUtilsGetAnimationBoundsTest, MismatchedTransforms) {
- double duration = 1.0;
-
- TransformOperations start;
- start.AppendTranslate(5, 6, 7);
- TransformOperations end;
- end.AppendRotate(0.f, 0.f, 1.f, 90.f);
- AddAnimatedTransformToElementWithPlayer(child1()->element_id(), timeline(),
- duration, start, end);
-
- parent1()->SetBounds(gfx::Size(350, 200));
-
- gfx::Size bounds(100, 100);
- child1()->SetDrawsContent(true);
- child1()->SetPosition(gfx::PointF(150.f, 50.f));
- child1()->SetBounds(bounds);
-
- host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
-
- gfx::BoxF box;
- bool success = LayerUtils::GetAnimationBounds(*child1(), &box);
- EXPECT_FALSE(success);
-}
-
-TEST_F(LayerUtilsGetAnimationBoundsTest,
- TransformUnderAncestorsWithPositionOr2DTransform) {
- // Tree topology:
- // +root (Bounds)
- // +--parent2 (Position)
- // +----child2 (2d transform)
- // +------grand_child (Transform animation)
- // +--------great_grand_child (DrawsContent)
- // This test is used to check if GetAnimationBounds correctly skips layers and
- // take layers which do not own a transform_node into consideration.
- // Under this topology, only root and grand_child own transform_nodes.
-
- double duration = 1.0;
-
- TransformOperations start;
- start.AppendTranslate(0.f, 0.f, 0.f);
- TransformOperations great_grand_child_end;
- great_grand_child_end.AppendTranslate(50.f, 0.f, 0.f);
- AddAnimatedTransformToElementWithPlayer(grand_child()->element_id(),
- timeline(), duration, start,
- great_grand_child_end);
-
- gfx::Transform translate_2d_transform;
- translate_2d_transform.Translate(80.f, 60.f);
- root()->SetBounds(gfx::Size(350, 200));
- parent2()->SetPosition(gfx::PointF(40.f, 45.f));
- child2()->test_properties()->transform = translate_2d_transform;
- great_grand_child()->SetDrawsContent(true);
- great_grand_child()->SetPosition(gfx::PointF(150.f, 50.f));
- great_grand_child()->SetBounds(gfx::Size(100, 200));
- host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
-
- gfx::BoxF box;
- bool success = LayerUtils::GetAnimationBounds(*great_grand_child(), &box);
- EXPECT_TRUE(success);
- gfx::BoxF expected(270.f, 155.f, 0.f, 150.f, 200.f, 0.f);
- EXPECT_BOXF_EQ(expected, box);
-}
-
-TEST_F(LayerUtilsGetAnimationBoundsTest,
- RotateZUnderAncestorsWithPositionOr2DTransform) {
- double duration = 1.0;
-
- TransformOperations start;
- start.AppendRotate(0.f, 0.f, 1.f, 0.f);
- TransformOperations great_grand_child_end;
- great_grand_child_end.AppendRotate(0.f, 0.f, 1.f, 90.f);
- AddAnimatedTransformToElementWithPlayer(grand_child()->element_id(),
- timeline(), duration, start,
- great_grand_child_end);
-
- gfx::Transform translate_2d_transform;
- translate_2d_transform.Translate(80.f, 60.f);
- root()->SetBounds(gfx::Size(350, 200));
- parent2()->SetPosition(gfx::PointF(40.f, 45.f));
- child2()->test_properties()->transform = translate_2d_transform;
-
- gfx::Size bounds(100, 100);
- grand_child()->SetPosition(gfx::PointF(150.f, 50.f));
- grand_child()->SetBounds(bounds);
- grand_child()->test_properties()->transform_origin =
- gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0);
-
- great_grand_child()->SetPosition(gfx::PointF(25.f, 25.f));
- great_grand_child()->SetBounds(gfx::Size(50.f, 50.f));
- great_grand_child()->SetDrawsContent(true);
-
- host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
-
- gfx::BoxF box;
- bool success = LayerUtils::GetAnimationBounds(*great_grand_child(), &box);
- EXPECT_TRUE(success);
-
- float diag = diagonal(50.f, 50.f);
- gfx::BoxF expected(320.f - 0.5f * diag, 205.f - 0.5f * diag, 0.f, diag, diag,
- 0.f);
- EXPECT_BOXF_EQ(expected, box);
-}
-
-TEST_F(LayerUtilsGetAnimationBoundsTest,
- RotateXWithPerspectiveUnderAncestorsWithPositionOr2DTransform) {
- // Tree topology:
- // +root (Bounds)
- // +--parent2 (Position)
- // +----child2 (2d transform)
- // +------grand_child (Perspective)
- // +--------great_grand_child (RotateX, DrawsContent)
- // Due to the RotateX animation, great_grand_child also owns a transform_node
-
- double duration = 1.0;
-
- TransformOperations start;
- start.AppendRotate(1.f, 0.f, 0.f, 0.f);
- TransformOperations great_grand_child_end;
- great_grand_child_end.AppendRotate(1.f, 0.f, 0.f, 90.f);
- AddAnimatedTransformToElementWithPlayer(great_grand_child()->element_id(),
- timeline(), duration, start,
- great_grand_child_end);
-
- gfx::Transform translate_2d_transform;
- translate_2d_transform.Translate(80.f, 60.f);
-
- root()->SetBounds(gfx::Size(350, 200));
- parent2()->SetPosition(gfx::PointF(40.f, 45.f));
- child2()->test_properties()->transform = translate_2d_transform;
-
- gfx::Transform perspective;
- perspective.ApplyPerspectiveDepth(100.f);
-
- gfx::Size bounds(100.f, 100.f);
- grand_child()->SetPosition(gfx::PointF(150.f, 50.f));
- grand_child()->SetBounds(bounds);
- grand_child()->test_properties()->transform = perspective;
- grand_child()->test_properties()->transform_origin =
- gfx::Point3F(bounds.width() * 0.5f, bounds.height() * 0.5f, 0);
-
- great_grand_child()->test_properties()->transform_origin =
- gfx::Point3F(bounds.width() * 0.25f, bounds.height() * 0.25f, 0);
- great_grand_child()->SetPosition(gfx::PointF(25.f, 25.f));
- great_grand_child()->SetBounds(gfx::Size(50.f, 50.f));
- great_grand_child()->SetDrawsContent(true);
-
- host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
-
- gfx::BoxF box;
- bool success = LayerUtils::GetAnimationBounds(*great_grand_child(), &box);
- EXPECT_TRUE(success);
-
- // Translate and position offset to the root:
- // 40 + 150 + 80 + 25 = 295
- // 45 + 60 +50 + 25 = 180
- // 0
- // Animation Bounds Before Perspective:
- // 0, 0, -25, 50, 50, 50
- // Apply Perspective:
- // When RotateX theta:
- // y
- // ^
- // d1 |
- // | / |
- // | / |
- // |/ |
- // /| |
- // / | |
- // / | |
- // theta |
- // z<----------------------X
- // d2
- //
- // the diag is 25 * 2
- //
- // box w: 2 * 25 * 100 / (100 - 25 * sin(theta)), max = 200 / 3 = 66.67
- // h: same as w, 66.67
- // d1: 25 * 100 * sin(theta) / (100 + 25 * sin(theta)), max = 100 / 5
- // = 20
- // d2: 25 * 100 * sin(theta) / (100 - 25 * sin(theta)), max = 100 / 3
- // = 33.33
- // d = d1 + d2 = 53.33
- //
- // Position Fix:
- // 295 - (66.67 - 50) / 2 = 286.67
- // 180 - (66.67 - 50) / 2 = 171.67
- // 0 - 20 = -20
-
- gfx::BoxF expected(286.666687f, 171.666672f, -20.f, 66.666656f, 66.666672f,
- 53.333336f);
- EXPECT_BOXF_EQ(expected, box);
-}
-
-TEST_F(LayerUtilsGetAnimationBoundsTest,
- RotateXNoPerspectiveUnderAncestorsWithPositionOr2DTransform) {
- double duration = 1.0;
-
- TransformOperations start;
- start.AppendRotate(1.f, 0.f, 0.f, 0.f);
- TransformOperations rotate_x_end;
- rotate_x_end.AppendRotate(1.f, 0.f, 0.f, 90.f);
- AddAnimatedTransformToElementWithPlayer(great_grand_child()->element_id(),
- timeline(), duration, start,
- rotate_x_end);
-
- gfx::Transform translate_2d_transform;
- translate_2d_transform.Translate(80.f, 60.f);
-
- root()->SetBounds(gfx::Size(350, 200));
- parent2()->SetPosition(gfx::PointF(40.f, 45.f));
- child2()->test_properties()->transform = translate_2d_transform;
-
- gfx::Size bounds(100.f, 100.f);
- grand_child()->SetPosition(gfx::PointF(150.f, 50.f));
- grand_child()->SetBounds(bounds);
-
- great_grand_child()->test_properties()->transform_origin =
- gfx::Point3F(bounds.width() * 0.25f, bounds.height() * 0.25f, 0);
- great_grand_child()->SetPosition(gfx::PointF(25.f, 25.f));
- great_grand_child()->SetBounds(
- gfx::Size(bounds.width() * 0.5f, bounds.height() * 0.5f));
- great_grand_child()->SetDrawsContent(true);
-
- host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
-
- gfx::BoxF box;
- bool success = LayerUtils::GetAnimationBounds(*great_grand_child(), &box);
- EXPECT_TRUE(success);
-
- // Same as RotateXWithPerspectiveUnderAncestorsWithPositionOr2DTransform test,
- // except for the perspective calculations.
-
- gfx::BoxF expected(295.f, 180.f, -25.f, 50.f, 50.f, 50.f);
- EXPECT_BOXF_EQ(expected, box);
-}
-
-} // namespace
-
-} // namespace cc
diff --git a/chromium/cc/quads/nine_patch_generator.cc b/chromium/cc/layers/nine_patch_generator.cc
index 9e07d88e989..ac64a5049e1 100644
--- a/chromium/cc/quads/nine_patch_generator.cc
+++ b/chromium/cc/layers/nine_patch_generator.cc
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "cc/quads/nine_patch_generator.h"
+#include "cc/layers/nine_patch_generator.h"
-#include "cc/quads/render_pass.h"
-#include "cc/quads/texture_draw_quad.h"
#include "cc/trees/layer_tree_impl.h"
+#include "components/viz/common/quads/render_pass.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/rect_f.h"
@@ -330,7 +330,7 @@ std::vector<NinePatchGenerator::Patch> NinePatchGenerator::GeneratePatches()
void NinePatchGenerator::AppendQuads(LayerImpl* layer_impl,
UIResourceId ui_resource_id,
- RenderPass* render_pass,
+ viz::RenderPass* render_pass,
viz::SharedQuadState* shared_quad_state,
const std::vector<Patch>& patches) {
if (!ui_resource_id)
@@ -356,8 +356,7 @@ void NinePatchGenerator::AppendQuads(LayerImpl* layer_impl,
bool needs_blending = !opaque;
if (!visible_rect.IsEmpty()) {
gfx::RectF image_rect = patch.normalized_image_rect;
- TextureDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
+ auto* quad = render_pass->CreateAndAppendDrawQuad<viz::TextureDrawQuad>();
quad->SetNew(shared_quad_state, output_rect, visible_rect, needs_blending,
resource, premultiplied_alpha, image_rect.origin(),
image_rect.bottom_right(), SK_ColorTRANSPARENT,
diff --git a/chromium/cc/quads/nine_patch_generator.h b/chromium/cc/layers/nine_patch_generator.h
index eb6fae3965d..bb0cd34fd44 100644
--- a/chromium/cc/quads/nine_patch_generator.h
+++ b/chromium/cc/layers/nine_patch_generator.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CC_QUADS_NINE_PATCH_GENERATOR_H_
-#define CC_QUADS_NINE_PATCH_GENERATOR_H_
+#ifndef CC_LAYERS_NINE_PATCH_GENERATOR_H_
+#define CC_LAYERS_NINE_PATCH_GENERATOR_H_
#include <string>
#include <vector>
@@ -21,13 +21,12 @@ class DictionaryValue;
}
namespace viz {
+class RenderPass;
class SharedQuadState;
-}
+} // namespace viz
namespace cc {
-
class LayerImpl;
-class RenderPass;
class CC_EXPORT NinePatchGenerator {
public:
@@ -102,7 +101,7 @@ class CC_EXPORT NinePatchGenerator {
void AppendQuads(LayerImpl* layer_impl,
UIResourceId ui_resource_id,
- RenderPass* render_pass,
+ viz::RenderPass* render_pass,
viz::SharedQuadState* shared_quad_state,
const std::vector<Patch>& patches);
@@ -130,4 +129,4 @@ class CC_EXPORT NinePatchGenerator {
} // namespace cc
-#endif // CC_QUADS_NINE_PATCH_GENERATOR_H_
+#endif // CC_LAYERS_NINE_PATCH_GENERATOR_H_
diff --git a/chromium/cc/quads/nine_patch_generator_unittest.cc b/chromium/cc/layers/nine_patch_generator_unittest.cc
index a0625f2ce51..78cc6887612 100644
--- a/chromium/cc/quads/nine_patch_generator_unittest.cc
+++ b/chromium/cc/layers/nine_patch_generator_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "cc/quads/nine_patch_generator.h"
+#include "cc/layers/nine_patch_generator.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect.h"
diff --git a/chromium/cc/layers/nine_patch_layer.cc b/chromium/cc/layers/nine_patch_layer.cc
index 03d3c8f3e36..b2555fb45e2 100644
--- a/chromium/cc/layers/nine_patch_layer.cc
+++ b/chromium/cc/layers/nine_patch_layer.cc
@@ -13,7 +13,7 @@
namespace cc {
scoped_refptr<NinePatchLayer> NinePatchLayer::Create() {
- return make_scoped_refptr(new NinePatchLayer());
+ return base::WrapRefCounted(new NinePatchLayer());
}
NinePatchLayer::NinePatchLayer()
diff --git a/chromium/cc/layers/nine_patch_layer_impl.cc b/chromium/cc/layers/nine_patch_layer_impl.cc
index dca9aeb8bcd..94145913d96 100644
--- a/chromium/cc/layers/nine_patch_layer_impl.cc
+++ b/chromium/cc/layers/nine_patch_layer_impl.cc
@@ -7,9 +7,9 @@
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "cc/base/math_util.h"
-#include "cc/quads/texture_draw_quad.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/occlusion.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/rect_f.h"
@@ -49,18 +49,26 @@ void NinePatchLayerImpl::SetLayout(const gfx::Rect& aperture,
NoteLayerPropertyChanged();
}
-void NinePatchLayerImpl::AppendQuads(
- RenderPass* render_pass,
- AppendQuadsData* append_quads_data) {
+void NinePatchLayerImpl::AppendQuads(viz::RenderPass* render_pass,
+ AppendQuadsData* append_quads_data) {
+ DCHECK(!bounds().IsEmpty());
quad_generator_.CheckGeometryLimitations();
+
viz::SharedQuadState* shared_quad_state =
render_pass->CreateAndAppendSharedQuadState();
- PopulateSharedQuadState(shared_quad_state);
-
- AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state,
+ bool is_resource =
+ ui_resource_id_ &&
+ layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_);
+ bool are_contents_opaque =
+ is_resource ? layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_) ||
+ contents_opaque()
+ : false;
+ PopulateSharedQuadState(shared_quad_state, are_contents_opaque);
+ AppendDebugBorderQuad(render_pass, gfx::Rect(bounds()), shared_quad_state,
append_quads_data);
- DCHECK(!bounds().IsEmpty());
+ if (!is_resource)
+ return;
std::vector<NinePatchGenerator::Patch> patches =
quad_generator_.GeneratePatches();
@@ -77,8 +85,8 @@ const char* NinePatchLayerImpl::LayerTypeAsString() const {
return "cc::NinePatchLayerImpl";
}
-std::unique_ptr<base::DictionaryValue> NinePatchLayerImpl::LayerTreeAsJson() {
- std::unique_ptr<base::DictionaryValue> result = LayerImpl::LayerTreeAsJson();
+std::unique_ptr<base::DictionaryValue> NinePatchLayerImpl::LayerAsJson() {
+ std::unique_ptr<base::DictionaryValue> result = LayerImpl::LayerAsJson();
quad_generator_.AsJson(result.get());
return result;
}
diff --git a/chromium/cc/layers/nine_patch_layer_impl.h b/chromium/cc/layers/nine_patch_layer_impl.h
index 1422d9672c3..9e5c9d65580 100644
--- a/chromium/cc/layers/nine_patch_layer_impl.h
+++ b/chromium/cc/layers/nine_patch_layer_impl.h
@@ -11,8 +11,8 @@
#include "base/memory/ptr_util.h"
#include "cc/cc_export.h"
#include "cc/layers/layer_impl.h"
+#include "cc/layers/nine_patch_generator.h"
#include "cc/layers/ui_resource_layer_impl.h"
-#include "cc/quads/nine_patch_generator.h"
#include "cc/resources/resource_provider.h"
#include "cc/resources/ui_resource_client.h"
#include "ui/gfx/geometry/rect.h"
@@ -42,10 +42,10 @@ class CC_EXPORT NinePatchLayerImpl : public UIResourceLayerImpl {
std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
void PushPropertiesTo(LayerImpl* layer) override;
- void AppendQuads(RenderPass* render_pass,
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override;
- std::unique_ptr<base::DictionaryValue> LayerTreeAsJson() override;
+ std::unique_ptr<base::DictionaryValue> LayerAsJson() override;
protected:
NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id);
diff --git a/chromium/cc/layers/nine_patch_layer_impl_unittest.cc b/chromium/cc/layers/nine_patch_layer_impl_unittest.cc
index 7d6636bdfbc..385b044e2f4 100644
--- a/chromium/cc/layers/nine_patch_layer_impl_unittest.cc
+++ b/chromium/cc/layers/nine_patch_layer_impl_unittest.cc
@@ -6,7 +6,6 @@
#include "cc/layers/append_quads_data.h"
#include "cc/layers/nine_patch_layer_impl.h"
-#include "cc/quads/texture_draw_quad.h"
#include "cc/resources/ui_resource_bitmap.h"
#include "cc/resources/ui_resource_client.h"
#include "cc/test/fake_impl_task_runner_provider.h"
@@ -15,6 +14,7 @@
#include "cc/test/geometry_test_utils.h"
#include "cc/test/layer_test_common.h"
#include "cc/trees/single_thread_proxy.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect_conversions.h"
@@ -37,7 +37,7 @@ void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size,
const gfx::Rect& border,
bool fill_center,
size_t expected_quad_size) {
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
gfx::Rect visible_layer_rect(layer_size);
gfx::Rect expected_remaining(border.x(), border.y(),
layer_size.width() - border.width(),
@@ -74,7 +74,7 @@ void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size,
render_pass.get(), &data);
// Verify quad rects
- const QuadList& quads = render_pass->quad_list;
+ const auto& quads = render_pass->quad_list;
EXPECT_EQ(expected_quad_size, quads.size());
Region layer_remaining(visible_layer_rect);
@@ -83,6 +83,8 @@ void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size,
EXPECT_TRUE(visible_layer_rect.Contains(quad_rect)) << iter.index();
EXPECT_TRUE(layer_remaining.Contains(quad_rect)) << iter.index();
+ EXPECT_EQ(iter->needs_blending,
+ !iter->shared_quad_state->are_contents_opaque);
layer_remaining.Subtract(Region(quad_rect));
}
@@ -98,7 +100,8 @@ void NinePatchLayerLayoutTest(const gfx::Size& bitmap_size,
gfx::Rect bitmap_rect(bitmap_size);
Region tex_remaining(bitmap_rect);
for (auto* quad : quads) {
- const TextureDrawQuad* tex_quad = TextureDrawQuad::MaterialCast(quad);
+ const viz::TextureDrawQuad* tex_quad =
+ viz::TextureDrawQuad::MaterialCast(quad);
gfx::RectF tex_rect =
gfx::BoundingRect(tex_quad->uv_top_left, tex_quad->uv_bottom_right);
tex_rect.Scale(bitmap_size.width(), bitmap_size.height());
@@ -121,7 +124,7 @@ void NinePatchLayerLayoutTestWithOcclusion(const gfx::Size& bitmap_size,
const gfx::Rect& occlusion,
bool fill_center,
size_t expected_quad_size) {
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
gfx::Rect visible_layer_rect(layer_size);
int border_left = std::min(border.x(), occlusion.x()),
border_top = std::min(border.y(), occlusion.y()),
@@ -182,7 +185,7 @@ void NinePatchLayerLayoutTestWithOcclusion(const gfx::Size& bitmap_size,
render_pass.get(), &data);
// Verify quad rects
- const QuadList& quads = render_pass->quad_list;
+ const auto& quads = render_pass->quad_list;
EXPECT_EQ(expected_quad_size, quads.size());
Region layer_remaining(visible_layer_rect);
@@ -191,6 +194,8 @@ void NinePatchLayerLayoutTestWithOcclusion(const gfx::Size& bitmap_size,
EXPECT_TRUE(visible_layer_rect.Contains(quad_rect)) << iter.index();
EXPECT_TRUE(layer_remaining.Contains(quad_rect)) << iter.index();
+ EXPECT_EQ(iter->needs_blending,
+ !iter->shared_quad_state->are_contents_opaque);
layer_remaining.Subtract(Region(quad_rect));
}
@@ -202,7 +207,8 @@ void NinePatchLayerLayoutTestWithOcclusion(const gfx::Size& bitmap_size,
gfx::Rect bitmap_rect(bitmap_size);
Region tex_remaining(bitmap_rect);
for (auto* quad : quads) {
- const TextureDrawQuad* tex_quad = TextureDrawQuad::MaterialCast(quad);
+ const viz::TextureDrawQuad* tex_quad =
+ viz::TextureDrawQuad::MaterialCast(quad);
gfx::RectF tex_rect =
gfx::BoundingRect(tex_quad->uv_top_left, tex_quad->uv_bottom_right);
tex_rect.Scale(bitmap_size.width(), bitmap_size.height());
@@ -441,8 +447,8 @@ TEST(NinePatchLayerImplTest, OpaqueRect) {
impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, gfx::Rect());
- const QuadList &quad_list = impl.quad_list();
- for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin();
+ const auto& quad_list = impl.quad_list();
+ for (auto it = quad_list.BackToFrontBegin();
it != quad_list.BackToFrontEnd(); ++it)
EXPECT_FALSE(it->ShouldDrawWithBlending());
}
@@ -454,8 +460,8 @@ TEST(NinePatchLayerImplTest, OpaqueRect) {
impl.AppendQuadsWithOcclusion(nine_patch_layer_impl, gfx::Rect());
- const QuadList &quad_list = impl.quad_list();
- for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin();
+ const auto& quad_list = impl.quad_list();
+ for (auto it = quad_list.BackToFrontBegin();
it != quad_list.BackToFrontEnd(); ++it)
EXPECT_TRUE(it->ShouldDrawWithBlending());
}
diff --git a/chromium/cc/layers/painted_overlay_scrollbar_layer.cc b/chromium/cc/layers/painted_overlay_scrollbar_layer.cc
index c093db97ba4..c81cf6e8bcf 100644
--- a/chromium/cc/layers/painted_overlay_scrollbar_layer.cc
+++ b/chromium/cc/layers/painted_overlay_scrollbar_layer.cc
@@ -33,7 +33,7 @@ std::unique_ptr<LayerImpl> PaintedOverlayScrollbarLayer::CreateLayerImpl(
scoped_refptr<PaintedOverlayScrollbarLayer>
PaintedOverlayScrollbarLayer::Create(std::unique_ptr<Scrollbar> scrollbar,
ElementId scroll_element_id) {
- return make_scoped_refptr(new PaintedOverlayScrollbarLayer(
+ return base::WrapRefCounted(new PaintedOverlayScrollbarLayer(
std::move(scrollbar), scroll_element_id));
}
diff --git a/chromium/cc/layers/painted_overlay_scrollbar_layer_impl.cc b/chromium/cc/layers/painted_overlay_scrollbar_layer_impl.cc
index e525a30c3c5..fbbd8fad00f 100644
--- a/chromium/cc/layers/painted_overlay_scrollbar_layer_impl.cc
+++ b/chromium/cc/layers/painted_overlay_scrollbar_layer_impl.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "cc/layers/painted_overlay_scrollbar_layer_impl.h"
+#include "cc/trees/layer_tree_impl.h"
namespace cc {
@@ -58,17 +59,34 @@ void PaintedOverlayScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) {
bool PaintedOverlayScrollbarLayerImpl::WillDraw(
DrawMode draw_mode,
- ResourceProvider* resource_provider) {
+ LayerTreeResourceProvider* resource_provider) {
DCHECK(draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE);
return LayerImpl::WillDraw(draw_mode, resource_provider);
}
void PaintedOverlayScrollbarLayerImpl::AppendQuads(
- RenderPass* render_pass,
+ viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) {
if (aperture_.IsEmpty())
return;
+ viz::SharedQuadState* shared_quad_state =
+ render_pass->CreateAndAppendSharedQuadState();
+ bool is_resource =
+ thumb_ui_resource_id_ &&
+ layer_tree_impl()->ResourceIdForUIResource(thumb_ui_resource_id_);
+ bool are_contents_opaque =
+ is_resource
+ ? layer_tree_impl()->IsUIResourceOpaque(thumb_ui_resource_id_) ||
+ contents_opaque()
+ : false;
+ PopulateSharedQuadState(shared_quad_state, are_contents_opaque);
+ AppendDebugBorderQuad(render_pass, gfx::Rect(bounds()), shared_quad_state,
+ append_quads_data);
+
+ if (!is_resource)
+ return;
+
// For overlay scrollbars, the border should match the inset of the aperture
// and be symmetrical.
gfx::Rect border(aperture_.x(), aperture_.y(), aperture_.x() * 2,
@@ -89,13 +107,6 @@ void PaintedOverlayScrollbarLayerImpl::AppendQuads(
nearest_neighbor);
quad_generator_.CheckGeometryLimitations();
- viz::SharedQuadState* shared_quad_state =
- render_pass->CreateAndAppendSharedQuadState();
- PopulateSharedQuadState(shared_quad_state);
-
- AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state,
- append_quads_data);
-
std::vector<NinePatchGenerator::Patch> patches =
quad_generator_.GeneratePatches();
diff --git a/chromium/cc/layers/painted_overlay_scrollbar_layer_impl.h b/chromium/cc/layers/painted_overlay_scrollbar_layer_impl.h
index 51858947383..104287b1995 100644
--- a/chromium/cc/layers/painted_overlay_scrollbar_layer_impl.h
+++ b/chromium/cc/layers/painted_overlay_scrollbar_layer_impl.h
@@ -8,8 +8,8 @@
#include "base/macros.h"
#include "cc/cc_export.h"
#include "cc/input/scrollbar.h"
+#include "cc/layers/nine_patch_generator.h"
#include "cc/layers/scrollbar_layer_impl_base.h"
-#include "cc/quads/nine_patch_generator.h"
#include "cc/resources/ui_resource_client.h"
namespace cc {
@@ -31,8 +31,8 @@ class CC_EXPORT PaintedOverlayScrollbarLayerImpl
void PushPropertiesTo(LayerImpl* layer) override;
bool WillDraw(DrawMode draw_mode,
- ResourceProvider* resource_provider) override;
- void AppendQuads(RenderPass* render_pass,
+ LayerTreeResourceProvider* resource_provider) override;
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override;
void SetThumbThickness(int thumb_thickness);
diff --git a/chromium/cc/layers/painted_scrollbar_layer.cc b/chromium/cc/layers/painted_scrollbar_layer.cc
index 0ce5723c08c..170e6330df3 100644
--- a/chromium/cc/layers/painted_scrollbar_layer.cc
+++ b/chromium/cc/layers/painted_scrollbar_layer.cc
@@ -39,7 +39,7 @@ std::unique_ptr<LayerImpl> PaintedScrollbarLayer::CreateLayerImpl(
scoped_refptr<PaintedScrollbarLayer> PaintedScrollbarLayer::Create(
std::unique_ptr<Scrollbar> scrollbar,
ElementId scroll_element_id) {
- return make_scoped_refptr(
+ return base::WrapRefCounted(
new PaintedScrollbarLayer(std::move(scrollbar), scroll_element_id));
}
@@ -268,22 +268,18 @@ UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart(
skbitmap.allocN32Pixels(content_rect.width(), content_rect.height());
}
SkiaPaintCanvas canvas(skbitmap);
+ canvas.clear(SK_ColorTRANSPARENT);
float scale_x =
content_rect.width() / static_cast<float>(layer_rect.width());
float scale_y =
content_rect.height() / static_cast<float>(layer_rect.height());
-
canvas.scale(SkFloatToScalar(scale_x), SkFloatToScalar(scale_y));
- canvas.translate(SkFloatToScalar(-layer_rect.x()),
- SkFloatToScalar(-layer_rect.y()));
-
- SkRect layer_skrect = RectToSkRect(layer_rect);
- PaintFlags paint;
- paint.setAntiAlias(false);
- paint.setBlendMode(SkBlendMode::kClear);
- canvas.drawRect(layer_skrect, paint);
- canvas.clipRect(layer_skrect);
+ // TODO(pdr): Scrollbars are painted with an offset (see Scrollbar::PaintPart)
+ // and the canvas is translated so that scrollbars are drawn at the origin.
+ // Refactor this code to not use an offset at all so Scrollbar::PaintPart
+ // paints at the origin and no translation is needed below.
+ canvas.translate(-layer_rect.x(), -layer_rect.y());
scrollbar_->PaintPart(&canvas, part, layer_rect);
// Make sure that the pixels are no longer mutable to unavoid unnecessary
diff --git a/chromium/cc/layers/painted_scrollbar_layer_impl.cc b/chromium/cc/layers/painted_scrollbar_layer_impl.cc
index 73dbaf3c7d2..dc29d3c4ec5 100644
--- a/chromium/cc/layers/painted_scrollbar_layer_impl.cc
+++ b/chromium/cc/layers/painted_scrollbar_layer_impl.cc
@@ -9,11 +9,11 @@
#include "base/memory/ptr_util.h"
#include "cc/input/scrollbar_animation_controller.h"
#include "cc/layers/layer.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/layer_tree_settings.h"
#include "cc/trees/occlusion.h"
+#include "components/viz/common/quads/solid_color_draw_quad.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
#include "ui/gfx/geometry/rect_conversions.h"
namespace cc {
@@ -77,14 +77,15 @@ void PaintedScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) {
scrollbar_layer->set_thumb_opacity(thumb_opacity_);
}
-bool PaintedScrollbarLayerImpl::WillDraw(DrawMode draw_mode,
- ResourceProvider* resource_provider) {
+bool PaintedScrollbarLayerImpl::WillDraw(
+ DrawMode draw_mode,
+ LayerTreeResourceProvider* resource_provider) {
DCHECK(draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE);
return LayerImpl::WillDraw(draw_mode, resource_provider);
}
void PaintedScrollbarLayerImpl::AppendQuads(
- RenderPass* render_pass,
+ viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) {
bool premultipled_alpha = true;
bool flipped = false;
@@ -95,9 +96,9 @@ void PaintedScrollbarLayerImpl::AppendQuads(
viz::SharedQuadState* shared_quad_state =
render_pass->CreateAndAppendSharedQuadState();
PopulateScaledSharedQuadState(shared_quad_state, internal_contents_scale_,
- internal_contents_scale_);
+ internal_contents_scale_, contents_opaque());
- AppendDebugBorderQuad(render_pass, internal_content_bounds_,
+ AppendDebugBorderQuad(render_pass, gfx::Rect(internal_content_bounds_),
shared_quad_state, append_quads_data);
gfx::Rect thumb_quad_rect = ComputeThumbQuadRect();
@@ -118,8 +119,7 @@ void PaintedScrollbarLayerImpl::AppendQuads(
bool needs_blending = true;
const float opacity[] = {thumb_opacity_, thumb_opacity_, thumb_opacity_,
thumb_opacity_};
- TextureDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
+ auto* quad = render_pass->CreateAndAppendDrawQuad<viz::TextureDrawQuad>();
quad->SetNew(shared_quad_state, scaled_thumb_quad_rect,
scaled_visible_thumb_quad_rect, needs_blending,
thumb_resource_id, premultipled_alpha, uv_top_left,
@@ -138,8 +138,7 @@ void PaintedScrollbarLayerImpl::AppendQuads(
if (track_resource_id && !visible_track_quad_rect.IsEmpty()) {
bool needs_blending = !contents_opaque();
const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
- TextureDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
+ auto* quad = render_pass->CreateAndAppendDrawQuad<viz::TextureDrawQuad>();
quad->SetNew(shared_quad_state, scaled_track_quad_rect,
scaled_visible_track_quad_rect, needs_blending,
track_resource_id, premultipled_alpha, uv_top_left,
diff --git a/chromium/cc/layers/painted_scrollbar_layer_impl.h b/chromium/cc/layers/painted_scrollbar_layer_impl.h
index 81b5aa20538..a08bfb3d161 100644
--- a/chromium/cc/layers/painted_scrollbar_layer_impl.h
+++ b/chromium/cc/layers/painted_scrollbar_layer_impl.h
@@ -30,8 +30,8 @@ class CC_EXPORT PaintedScrollbarLayerImpl : public ScrollbarLayerImplBase {
void PushPropertiesTo(LayerImpl* layer) override;
bool WillDraw(DrawMode draw_mode,
- ResourceProvider* resource_provider) override;
- void AppendQuads(RenderPass* render_pass,
+ LayerTreeResourceProvider* resource_provider) override;
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override;
gfx::Rect GetEnclosingRectInTargetSpace() const override;
diff --git a/chromium/cc/layers/painted_scrollbar_layer_impl_unittest.cc b/chromium/cc/layers/painted_scrollbar_layer_impl_unittest.cc
index e3af2a87919..bef40d67ea2 100644
--- a/chromium/cc/layers/painted_scrollbar_layer_impl_unittest.cc
+++ b/chromium/cc/layers/painted_scrollbar_layer_impl_unittest.cc
@@ -6,10 +6,10 @@
#include <stddef.h>
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
#include "cc/resources/ui_resource_bitmap.h"
#include "cc/test/layer_test_common.h"
+#include "components/viz/common/quads/draw_quad.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
@@ -77,20 +77,22 @@ TEST(PaintedScrollbarLayerImplTest, Occlusion) {
// Note: this is also testing that the thumb and track are both
// scaled by the internal contents scale. It's not occlusion-related
// but is easy to verify here.
- const DrawQuad* thumb_draw_quad = impl.quad_list().ElementAt(0);
- const DrawQuad* track_draw_quad = impl.quad_list().ElementAt(1);
+ const viz::DrawQuad* thumb_draw_quad = impl.quad_list().ElementAt(0);
+ const viz::DrawQuad* track_draw_quad = impl.quad_list().ElementAt(1);
- EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, thumb_draw_quad->material);
- EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, track_draw_quad->material);
+ EXPECT_EQ(viz::DrawQuad::TEXTURE_CONTENT, thumb_draw_quad->material);
+ EXPECT_EQ(viz::DrawQuad::TEXTURE_CONTENT, track_draw_quad->material);
- const TextureDrawQuad* thumb_quad =
- TextureDrawQuad::MaterialCast(thumb_draw_quad);
- const TextureDrawQuad* track_quad =
- TextureDrawQuad::MaterialCast(track_draw_quad);
+ const viz::TextureDrawQuad* thumb_quad =
+ viz::TextureDrawQuad::MaterialCast(thumb_draw_quad);
+ const viz::TextureDrawQuad* track_quad =
+ viz::TextureDrawQuad::MaterialCast(track_draw_quad);
gfx::Rect scaled_thumb_rect = gfx::ScaleToEnclosingRect(thumb_rect, scale);
EXPECT_EQ(track_quad->rect.ToString(),
gfx::Rect(scaled_layer_size).ToString());
+ EXPECT_EQ(scrollbar_layer_impl->contents_opaque(),
+ track_quad->shared_quad_state->are_contents_opaque);
EXPECT_EQ(track_quad->visible_rect.ToString(),
gfx::Rect(scaled_layer_size).ToString());
EXPECT_FALSE(track_quad->needs_blending);
@@ -98,6 +100,8 @@ TEST(PaintedScrollbarLayerImplTest, Occlusion) {
EXPECT_EQ(thumb_quad->visible_rect.ToString(),
scaled_thumb_rect.ToString());
EXPECT_TRUE(thumb_quad->needs_blending);
+ EXPECT_EQ(scrollbar_layer_impl->contents_opaque(),
+ thumb_quad->shared_quad_state->are_contents_opaque);
for (size_t i = 0; i < 4; ++i) {
EXPECT_EQ(thumb_opacity, thumb_quad->vertex_opacity[i]);
EXPECT_EQ(1.f, track_quad->vertex_opacity[i]);
diff --git a/chromium/cc/layers/picture_image_layer.cc b/chromium/cc/layers/picture_image_layer.cc
index 66f66c9adb8..b0c06b84cae 100644
--- a/chromium/cc/layers/picture_image_layer.cc
+++ b/chromium/cc/layers/picture_image_layer.cc
@@ -15,7 +15,7 @@
namespace cc {
scoped_refptr<PictureImageLayer> PictureImageLayer::Create() {
- return make_scoped_refptr(new PictureImageLayer());
+ return base::WrapRefCounted(new PictureImageLayer());
}
PictureImageLayer::PictureImageLayer() : PictureLayer(this) {}
diff --git a/chromium/cc/layers/picture_image_layer_unittest.cc b/chromium/cc/layers/picture_image_layer_unittest.cc
index f3ff642de2d..9822c0d7f7e 100644
--- a/chromium/cc/layers/picture_image_layer_unittest.cc
+++ b/chromium/cc/layers/picture_image_layer_unittest.cc
@@ -40,7 +40,7 @@ TEST(PictureImageLayerTest, PaintContentsToDisplayList) {
image_canvas->drawRect(SkRect::MakeWH(100, 100), blue_paint);
image_canvas->drawRect(SkRect::MakeLTRB(100, 100, 200, 200), blue_paint);
- layer->SetImage(PaintImageBuilder()
+ layer->SetImage(PaintImageBuilder::WithDefault()
.set_id(PaintImage::GetNextId())
.set_image(image_surface->makeImageSnapshot())
.TakePaintImage());
diff --git a/chromium/cc/layers/picture_layer.cc b/chromium/cc/layers/picture_layer.cc
index a58bcd77ff8..45a1f59b1d2 100644
--- a/chromium/cc/layers/picture_layer.cc
+++ b/chromium/cc/layers/picture_layer.cc
@@ -24,7 +24,7 @@ PictureLayer::PictureLayerInputs::PictureLayerInputs() = default;
PictureLayer::PictureLayerInputs::~PictureLayerInputs() = default;
scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) {
- return make_scoped_refptr(new PictureLayer(client));
+ return base::WrapRefCounted(new PictureLayer(client));
}
PictureLayer::PictureLayer(ContentLayerClient* client)
diff --git a/chromium/cc/layers/picture_layer.h b/chromium/cc/layers/picture_layer.h
index f8bc1091caf..b4d2f7abb27 100644
--- a/chromium/cc/layers/picture_layer.h
+++ b/chromium/cc/layers/picture_layer.h
@@ -55,6 +55,8 @@ class CC_EXPORT PictureLayer : public Layer {
const DisplayItemList* GetDisplayItemList();
+ LayerMaskType mask_type() { return mask_type_; }
+
protected:
// Encapsulates all data, callbacks or interfaces received from the embedder.
struct PictureLayerInputs {
@@ -77,8 +79,6 @@ class CC_EXPORT PictureLayer : public Layer {
bool HasDrawableContent() const override;
- LayerMaskType mask_type() { return mask_type_; }
-
PictureLayerInputs picture_layer_inputs_;
private:
diff --git a/chromium/cc/layers/picture_layer_impl.cc b/chromium/cc/layers/picture_layer_impl.cc
index 53f018770cc..ce10cd0db84 100644
--- a/chromium/cc/layers/picture_layer_impl.cc
+++ b/chromium/cc/layers/picture_layer_impl.cc
@@ -20,15 +20,16 @@
#include "cc/debug/debug_colors.h"
#include "cc/layers/append_quads_data.h"
#include "cc/layers/solid_color_layer_impl.h"
-#include "cc/quads/debug_border_draw_quad.h"
-#include "cc/quads/picture_draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/tile_draw_quad.h"
+#include "cc/paint/display_item_list.h"
#include "cc/tiles/tile_manager.h"
#include "cc/tiles/tiling_set_raster_queue_all.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/occlusion.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"
+#include "components/viz/common/quads/debug_border_draw_quad.h"
+#include "components/viz/common/quads/picture_draw_quad.h"
+#include "components/viz/common/quads/solid_color_draw_quad.h"
+#include "components/viz/common/quads/tile_draw_quad.h"
#include "components/viz/common/traced_value.h"
#include "ui/gfx/geometry/quad_f.h"
#include "ui/gfx/geometry/rect_conversions.h"
@@ -119,6 +120,9 @@ PictureLayerImpl::~PictureLayerImpl() {
if (twin_layer_)
twin_layer_->twin_layer_ = nullptr;
layer_tree_impl()->UnregisterPictureLayerImpl(this);
+
+ // Unregister for all images on the current raster source.
+ UnregisterAnimatedImages();
}
void PictureLayerImpl::SetLayerMaskType(Layer::LayerMaskType mask_type) {
@@ -194,7 +198,7 @@ void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) {
layer_tree_impl()->AddLayerShouldPushProperties(this);
}
-void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
+void PictureLayerImpl::AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) {
// The bounds and the pile size may differ if the pile wasn't updated (ie.
// PictureLayer::Update didn't happen). In that case the pile will be empty.
@@ -207,23 +211,34 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
render_pass->CreateAndAppendSharedQuadState();
if (raster_source_->IsSolidColor()) {
- PopulateSharedQuadState(shared_quad_state);
+ float max_contents_scale = GetIdealContentsScale();
- AppendDebugBorderQuad(
- render_pass, bounds(), shared_quad_state, append_quads_data);
+ // The downstream CA layers use shared_quad_state to generate resources of
+ // the right size even if it is a solid color picture layer.
+ PopulateScaledSharedQuadState(shared_quad_state, max_contents_scale,
+ max_contents_scale, contents_opaque());
+
+ AppendDebugBorderQuad(render_pass, gfx::Rect(bounds()), shared_quad_state,
+ append_quads_data);
+ gfx::Rect scaled_visible_layer_rect =
+ shared_quad_state->visible_quad_layer_rect;
+ Occlusion scaled_occlusion =
+ draw_properties()
+ .occlusion_in_content_space.GetOcclusionWithGivenDrawTransform(
+ shared_quad_state->quad_to_target_transform);
SolidColorLayerImpl::AppendSolidQuads(
- render_pass, draw_properties().occlusion_in_content_space,
- shared_quad_state, visible_layer_rect(),
- raster_source_->GetSolidColor(), append_quads_data);
+ render_pass, scaled_occlusion, shared_quad_state,
+ scaled_visible_layer_rect, raster_source_->GetSolidColor(),
+ !layer_tree_impl()->settings().enable_edge_anti_aliasing,
+ append_quads_data);
return;
}
- float device_scale_factor =
- layer_tree_impl() ? layer_tree_impl()->device_scale_factor() : 1;
+ float device_scale_factor = layer_tree_impl()->device_scale_factor();
float max_contents_scale = MaximumTilingContentsScale();
PopulateScaledSharedQuadState(shared_quad_state, max_contents_scale,
- max_contents_scale);
+ max_contents_scale, contents_opaque());
Occlusion scaled_occlusion;
if (mask_type_ == Layer::LayerMaskType::NOT_MASK) {
scaled_occlusion =
@@ -233,10 +248,10 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
}
if (current_draw_mode_ == DRAW_MODE_RESOURCELESS_SOFTWARE) {
+ DCHECK(shared_quad_state->quad_layer_rect.origin() == gfx::Point(0, 0));
AppendDebugBorderQuad(
- render_pass, shared_quad_state->quad_layer_rect.size(),
- shared_quad_state, append_quads_data,
- DebugColors::DirectPictureBorderColor(),
+ render_pass, shared_quad_state->quad_layer_rect, shared_quad_state,
+ append_quads_data, DebugColors::DirectPictureBorderColor(),
DebugColors::DirectPictureBorderWidth(device_scale_factor));
gfx::Rect geometry_rect = shared_quad_state->visible_quad_layer_rect;
@@ -259,18 +274,32 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
gfx::Size texture_size = quad_content_rect.size();
gfx::RectF texture_rect = gfx::RectF(gfx::SizeF(texture_size));
- PictureDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
+ auto* quad = render_pass->CreateAndAppendDrawQuad<viz::PictureDrawQuad>();
quad->SetNew(shared_quad_state, geometry_rect, visible_geometry_rect,
needs_blending, texture_rect, texture_size, nearest_neighbor_,
viz::RGBA_8888, quad_content_rect, max_contents_scale,
- raster_source_);
+ raster_source_->GetDisplayItemList());
ValidateQuadResources(quad);
return;
}
- AppendDebugBorderQuad(render_pass, shared_quad_state->quad_layer_rect.size(),
- shared_quad_state, append_quads_data);
+ // If we're doing a regular AppendQuads (ie, not solid color or resourceless
+ // software draw, and if the visible rect is scrolled far enough away, then we
+ // may run into a floating point precision in AA calculations in the renderer.
+ // See crbug.com/765297. In order to avoid this, we shift the quads up from
+ // where they logically reside and adjust the shared_quad_state's transform
+ // instead. We only do this in a scale/translate matrices to ensure the math
+ // is correct.
+ gfx::Vector2d quad_offset;
+ if (shared_quad_state->quad_to_target_transform.IsScaleOrTranslation()) {
+ const auto& visible_rect = shared_quad_state->visible_quad_layer_rect;
+ quad_offset = gfx::Vector2d(-visible_rect.x(), -visible_rect.y());
+ }
+
+ gfx::Rect debug_border_rect(shared_quad_state->quad_layer_rect);
+ debug_border_rect.Offset(quad_offset);
+ AppendDebugBorderQuad(render_pass, debug_border_rect, shared_quad_state,
+ append_quads_data);
if (ShowDebugBorders(DebugBorderType::LAYER)) {
for (PictureLayerTilingSet::CoverageIterator iter(
@@ -308,9 +337,10 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
width = DebugColors::MissingTileBorderWidth(device_scale_factor);
}
- DebugBorderDrawQuad* debug_border_quad =
- render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
+ auto* debug_border_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::DebugBorderDrawQuad>();
gfx::Rect geometry_rect = iter.geometry_rect();
+ geometry_rect.Offset(quad_offset);
gfx::Rect visible_geometry_rect = geometry_rect;
debug_border_quad->SetNew(shared_quad_state,
geometry_rect,
@@ -342,6 +372,12 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
gfx::Rect geometry_rect = iter.geometry_rect();
gfx::Rect visible_geometry_rect =
scaled_occlusion.GetUnoccludedContentRect(geometry_rect);
+
+ gfx::Rect offset_geometry_rect = geometry_rect;
+ offset_geometry_rect.Offset(quad_offset);
+ gfx::Rect offset_visible_geometry_rect = visible_geometry_rect;
+ offset_visible_geometry_rect.Offset(quad_offset);
+
bool needs_blending = !contents_opaque();
if (visible_geometry_rect.IsEmpty())
continue;
@@ -354,6 +390,7 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
bool has_draw_quad = false;
if (*iter && iter->draw_info().IsReadyToDraw()) {
const TileDrawInfo& draw_info = iter->draw_info();
+
switch (draw_info.mode()) {
case TileDrawInfo::RESOURCE_MODE: {
gfx::RectF texture_rect = iter.texture_rect();
@@ -370,12 +407,14 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
append_quads_data->num_incomplete_tiles++;
}
- TileDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<TileDrawQuad>();
- quad->SetNew(shared_quad_state, geometry_rect, visible_geometry_rect,
- needs_blending, draw_info.resource_id(), texture_rect,
- draw_info.resource_size(), draw_info.contents_swizzled(),
- nearest_neighbor_);
+ auto* quad =
+ render_pass->CreateAndAppendDrawQuad<viz::TileDrawQuad>();
+ quad->SetNew(
+ shared_quad_state, offset_geometry_rect,
+ offset_visible_geometry_rect, needs_blending,
+ draw_info.resource_id(), texture_rect, draw_info.resource_size(),
+ draw_info.contents_swizzled(), nearest_neighbor_,
+ !layer_tree_impl()->settings().enable_edge_anti_aliasing);
ValidateQuadResources(quad);
has_draw_quad = true;
break;
@@ -386,10 +425,12 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
shared_quad_state->opacity;
if (mask_type_ == Layer::LayerMaskType::MULTI_TEXTURE_MASK ||
alpha >= std::numeric_limits<float>::epsilon()) {
- SolidColorDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- quad->SetNew(shared_quad_state, geometry_rect,
- visible_geometry_rect, draw_info.solid_color(), false);
+ auto* quad =
+ render_pass->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
+ quad->SetNew(
+ shared_quad_state, offset_geometry_rect,
+ offset_visible_geometry_rect, draw_info.solid_color(),
+ !layer_tree_impl()->settings().enable_edge_anti_aliasing);
ValidateQuadResources(quad);
}
has_draw_quad = true;
@@ -407,10 +448,10 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
// Fill the whole tile with the missing tile color.
color = DebugColors::OOMTileBorderColor();
}
- SolidColorDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- quad->SetNew(shared_quad_state, geometry_rect, visible_geometry_rect,
- color, false);
+ auto* quad =
+ render_pass->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
+ quad->SetNew(shared_quad_state, offset_geometry_rect,
+ offset_visible_geometry_rect, color, false);
ValidateQuadResources(quad);
if (geometry_rect.Intersects(scaled_viewport_for_tile_priority)) {
@@ -451,6 +492,12 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass,
}
}
+ // Adjust shared_quad_state with the quad_offset, since we've adjusted each
+ // quad we've appended by it.
+ shared_quad_state->quad_to_target_transform.Translate(-quad_offset);
+ shared_quad_state->quad_layer_rect.Offset(quad_offset);
+ shared_quad_state->visible_quad_layer_rect.Offset(quad_offset);
+
if (missing_tile_count) {
TRACE_EVENT_INSTANT2("cc",
"PictureLayerImpl::AppendQuads checkerboard",
@@ -599,11 +646,27 @@ void PictureLayerImpl::UpdateRasterSource(
<< " bounds " << bounds().ToString() << " pile "
<< raster_source->GetSize().ToString();
+ // We have an updated recording if the DisplayItemList in the new RasterSource
+ // is different.
+ const bool recording_updated =
+ !raster_source_ || raster_source_->GetDisplayItemList() !=
+ raster_source->GetDisplayItemList();
+
+ // Unregister for all images on the current raster source, if the recording
+ // was updated.
+ if (recording_updated)
+ UnregisterAnimatedImages();
+
// The |raster_source_| is initially null, so have to check for that for the
// first frame.
bool could_have_tilings = raster_source_.get() && CanHaveTilings();
raster_source_.swap(raster_source);
+ // Register images from the new raster source, if the recording was updated.
+ // TODO(khushalsagar): UMA the number of animated images in layer?
+ if (recording_updated)
+ RegisterAnimatedImages();
+
// The |new_invalidation| must be cleared before updating tilings since they
// access the invalidation through the PictureLayerTilingClient interface.
invalidation_.Clear();
@@ -747,6 +810,26 @@ gfx::Rect PictureLayerImpl::GetEnclosingRectInTargetSpace() const {
return GetScaledEnclosingRectInTargetSpace(MaximumTilingContentsScale());
}
+bool PictureLayerImpl::ShouldAnimate(PaintImage::Id paint_image_id) const {
+ DCHECK(raster_source_);
+
+ // Only animate images for layers which HasValidTilePriorities. This check is
+ // important for 2 reasons:
+ // 1) It avoids doing additional work for layers we don't plan to rasterize
+ // and/or draw. The updated state will be pulled by the animation system
+ // if the draw properties change.
+ // 2) It eliminates considering layers on the recycle tree. Once the pending
+ // tree is activated, the layers on the recycle tree remain registered as
+ // animation drivers, but should not drive animations since they don't have
+ // updated draw properties.
+ //
+ // Additionally only animate images which are on-screen, animations are
+ // paused once they are not visible.
+ return HasValidTilePriorities() &&
+ raster_source_->GetRectForImage(paint_image_id)
+ .Intersects(visible_layer_rect());
+}
+
gfx::Size PictureLayerImpl::CalculateTileSize(
const gfx::Size& content_bounds) const {
int max_texture_size =
@@ -1489,6 +1572,13 @@ void PictureLayerImpl::InvalidateRegionForImages(
return;
}
+ // Make sure to union the rect from this invalidation with the update_rect
+ // instead of over-writing it. We don't want to reset the update that came
+ // from the main thread.
+ gfx::Rect new_update_rect = invalidation.bounds();
+ new_update_rect.Union(update_rect());
+ SetUpdateRect(new_update_rect);
+
invalidation_.Union(invalidation);
tilings_->Invalidate(invalidation);
SetNeedsPushProperties();
@@ -1496,4 +1586,38 @@ void PictureLayerImpl::InvalidateRegionForImages(
"Invalidation", invalidation.ToString());
}
+void PictureLayerImpl::RegisterAnimatedImages() {
+ if (!raster_source_ || !raster_source_->GetDisplayItemList())
+ return;
+
+ auto* controller = layer_tree_impl()->image_animation_controller();
+ if (!controller)
+ return;
+
+ const auto& metadata = raster_source_->GetDisplayItemList()
+ ->discardable_image_map()
+ .animated_images_metadata();
+ for (const auto& data : metadata) {
+ // Only update the metadata from updated recordings received from a commit.
+ if (layer_tree_impl()->IsSyncTree())
+ controller->UpdateAnimatedImage(data);
+ controller->RegisterAnimationDriver(data.paint_image_id, this);
+ }
+}
+
+void PictureLayerImpl::UnregisterAnimatedImages() {
+ if (!raster_source_ || !raster_source_->GetDisplayItemList())
+ return;
+
+ auto* controller = layer_tree_impl()->image_animation_controller();
+ if (!controller)
+ return;
+
+ const auto& metadata = raster_source_->GetDisplayItemList()
+ ->discardable_image_map()
+ .animated_images_metadata();
+ for (const auto& data : metadata)
+ controller->UnregisterAnimationDriver(data.paint_image_id, this);
+}
+
} // namespace cc
diff --git a/chromium/cc/layers/picture_layer_impl.h b/chromium/cc/layers/picture_layer_impl.h
index ebc2c8bdbeb..10ebaed0caa 100644
--- a/chromium/cc/layers/picture_layer_impl.h
+++ b/chromium/cc/layers/picture_layer_impl.h
@@ -20,6 +20,7 @@
#include "cc/tiles/picture_layer_tiling.h"
#include "cc/tiles/picture_layer_tiling_set.h"
#include "cc/tiles/tiling_set_eviction_queue.h"
+#include "cc/trees/image_animation_controller.h"
namespace cc {
@@ -27,8 +28,10 @@ class AppendQuadsData;
class MicroBenchmarkImpl;
class Tile;
-class CC_EXPORT PictureLayerImpl : public LayerImpl,
- public PictureLayerTilingClient {
+class CC_EXPORT PictureLayerImpl
+ : public LayerImpl,
+ public PictureLayerTilingClient,
+ public ImageAnimationController::AnimationDriver {
public:
static std::unique_ptr<PictureLayerImpl>
Create(LayerTreeImpl* tree_impl, int id, Layer::LayerMaskType mask_type) {
@@ -43,7 +46,7 @@ class CC_EXPORT PictureLayerImpl : public LayerImpl,
const char* LayerTypeAsString() const override;
std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
void PushPropertiesTo(LayerImpl* layer) override;
- void AppendQuads(RenderPass* render_pass,
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override;
void NotifyTileStateChanged(const Tile* tile) override;
void ResetRasterScale();
@@ -63,6 +66,9 @@ class CC_EXPORT PictureLayerImpl : public LayerImpl,
bool RequiresHighResToDraw() const override;
gfx::Rect GetEnclosingRectInTargetSpace() const override;
+ // ImageAnimationController::AnimationDriver overrides.
+ bool ShouldAnimate(PaintImage::Id paint_image_id) const override;
+
void set_gpu_raster_max_texture_size(gfx::Size gpu_raster_max_texture_size) {
gpu_raster_max_texture_size_ = gpu_raster_max_texture_size;
}
@@ -107,6 +113,8 @@ class CC_EXPORT PictureLayerImpl : public LayerImpl,
bool RasterSourceUsesLCDTextForTesting() const { return can_use_lcd_text_; }
+ const Region& InvalidationForTesting() const { return invalidation_; }
+
protected:
PictureLayerImpl(LayerTreeImpl* tree_impl,
int id,
@@ -136,6 +144,9 @@ class CC_EXPORT PictureLayerImpl : public LayerImpl,
float MaximumTilingContentsScale() const;
std::unique_ptr<PictureLayerTilingSet> CreatePictureLayerTilingSet();
+ void RegisterAnimatedImages();
+ void UnregisterAnimatedImages();
+
PictureLayerImpl* twin_layer_;
std::unique_ptr<PictureLayerTilingSet> tilings_;
diff --git a/chromium/cc/layers/picture_layer_impl_unittest.cc b/chromium/cc/layers/picture_layer_impl_unittest.cc
index cc8e860fb51..213dd900168 100644
--- a/chromium/cc/layers/picture_layer_impl_unittest.cc
+++ b/chromium/cc/layers/picture_layer_impl_unittest.cc
@@ -18,8 +18,6 @@
#include "cc/base/math_util.h"
#include "cc/layers/append_quads_data.h"
#include "cc/layers/picture_layer.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/tile_draw_quad.h"
#include "cc/test/fake_content_layer_client.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_frame_sink.h"
@@ -31,17 +29,21 @@
#include "cc/test/fake_recording_source.h"
#include "cc/test/geometry_test_utils.h"
#include "cc/test/layer_test_common.h"
+#include "cc/test/skia_common.h"
#include "cc/test/test_layer_tree_host_base.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/test/test_web_graphics_context_3d.h"
#include "cc/tiles/tiling_set_raster_queue_all.h"
#include "cc/tiles/tiling_set_raster_queue_required.h"
#include "cc/trees/layer_tree_impl.h"
+#include "components/viz/common/quads/draw_quad.h"
+#include "components/viz/common/quads/tile_draw_quad.h"
#include "components/viz/common/resources/buffer_to_texture_target_map.h"
#include "components/viz/test/begin_frame_args_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/size_conversions.h"
+#include "ui/gfx/test/gfx_util.h"
namespace cc {
namespace {
@@ -84,6 +86,7 @@ class PictureLayerImplTest : public TestLayerTreeHostBase {
settings.create_low_res_tiling = true;
settings.resource_settings.buffer_to_texture_target_map =
viz::DefaultBufferToTextureTargetMapForTesting();
+ settings.enable_image_animations = true;
return settings;
}
@@ -738,8 +741,9 @@ TEST_F(PictureLayerImplTest, ScaledBoundsOverflowInt) {
active_layer()->draw_properties().visible_layer_rect =
gfx::Rect(layer_bounds);
viz::SharedQuadState state;
- active_layer()->PopulateScaledSharedQuadState(&state, adjusted_scale,
- adjusted_scale);
+ active_layer()->PopulateScaledSharedQuadState(
+ &state, adjusted_scale, adjusted_scale,
+ active_layer()->contents_opaque());
}
TEST_F(PictureLayerImplTest, PinchGestureTilings) {
@@ -1506,7 +1510,7 @@ TEST_F(PictureLayerImplTest, ClampSingleTileToToMaxTileSize) {
}
TEST_F(PictureLayerImplTest, DisallowTileDrawQuads) {
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
gfx::Size layer_bounds(1300, 1900);
gfx::Rect layer_rect(layer_bounds);
@@ -1524,15 +1528,17 @@ TEST_F(PictureLayerImplTest, DisallowTileDrawQuads) {
active_layer()->DidDraw(nullptr);
ASSERT_EQ(1u, render_pass->quad_list.size());
- EXPECT_EQ(DrawQuad::PICTURE_CONTENT,
+ EXPECT_EQ(viz::DrawQuad::PICTURE_CONTENT,
render_pass->quad_list.front()->material);
EXPECT_EQ(render_pass->quad_list.front()->rect, layer_rect);
EXPECT_FALSE(render_pass->quad_list.front()->needs_blending);
+ EXPECT_TRUE(
+ render_pass->quad_list.front()->shared_quad_state->are_contents_opaque);
EXPECT_EQ(render_pass->quad_list.front()->visible_rect, layer_rect);
}
TEST_F(PictureLayerImplTest, ResourcelessPartialRecording) {
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
gfx::Size tile_size(400, 400);
gfx::Size layer_bounds(700, 650);
@@ -1560,16 +1566,17 @@ TEST_F(PictureLayerImplTest, ResourcelessPartialRecording) {
gfx::Rect quad_visible = gfx::IntersectRects(scaled_visible, scaled_recorded);
ASSERT_EQ(1U, render_pass->quad_list.size());
- EXPECT_EQ(DrawQuad::PICTURE_CONTENT,
+ EXPECT_EQ(viz::DrawQuad::PICTURE_CONTENT,
render_pass->quad_list.front()->material);
- const DrawQuad* quad = render_pass->quad_list.front();
+ const viz::DrawQuad* quad = render_pass->quad_list.front();
EXPECT_EQ(quad_visible, quad->rect);
+ EXPECT_TRUE(quad->shared_quad_state->are_contents_opaque);
EXPECT_EQ(quad_visible, quad->visible_rect);
EXPECT_FALSE(quad->needs_blending);
}
TEST_F(PictureLayerImplTest, ResourcelessEmptyRecording) {
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
gfx::Size layer_bounds(700, 650);
scoped_refptr<FakeRasterSource> active_raster_source =
@@ -1589,8 +1596,163 @@ TEST_F(PictureLayerImplTest, ResourcelessEmptyRecording) {
EXPECT_EQ(0U, render_pass->quad_list.size());
}
+TEST_F(PictureLayerImplTest, FarScrolledQuadsShifted) {
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
+
+ gfx::Size layer_bounds(1000, 10000);
+ scoped_refptr<FakeRasterSource> active_raster_source =
+ FakeRasterSource::CreateFilled(layer_bounds);
+ SetupPendingTree(active_raster_source);
+ ActivateTree();
+
+ active_layer()->SetContentsOpaque(true);
+ active_layer()->draw_properties().visible_layer_rect =
+ gfx::Rect(0, 5000, 1000, 1000);
+ active_layer()->UpdateTiles();
+
+ auto* high_res_tiling = active_layer()->HighResTiling();
+ ASSERT_TRUE(high_res_tiling);
+ const std::vector<Tile*>& tiles = high_res_tiling->AllTilesForTesting();
+ ASSERT_GT(tiles.size(), 0u);
+
+ host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
+
+ AppendQuadsData data;
+ active_layer()->WillDraw(DRAW_MODE_HARDWARE, nullptr);
+ active_layer()->AppendQuads(render_pass.get(), &data);
+ active_layer()->DidDraw(nullptr);
+
+ EXPECT_EQ(20u, render_pass->quad_list.size());
+ int last_y = -1;
+ int last_height = -1;
+ int min_y = std::numeric_limits<int>::max();
+ float min_transformed_y = std::numeric_limits<float>::max();
+ float max_transformed_y = -1;
+ for (auto* draw_quad : render_pass->quad_list) {
+ if (last_y == -1) {
+ last_y = draw_quad->rect.y();
+ min_y = last_y;
+ last_height = draw_quad->rect.height();
+ }
+
+ if (last_y != draw_quad->rect.y()) {
+ EXPECT_EQ(last_y + last_height, draw_quad->rect.y());
+ last_y = draw_quad->rect.y();
+ min_y = std::min(min_y, last_y);
+ last_height = draw_quad->rect.height();
+ }
+ EXPECT_LT(last_y, 5000);
+ EXPECT_EQ(draw_quad->material, viz::DrawQuad::TILED_CONTENT);
+
+ auto transform = [draw_quad](const gfx::Rect& rect) {
+ gfx::RectF result(rect);
+ draw_quad->shared_quad_state->quad_to_target_transform.TransformRect(
+ &result);
+ return result;
+ };
+
+ gfx::RectF transformed_rect = transform(draw_quad->rect);
+ EXPECT_GT(transformed_rect.y(), 0);
+ if (min_transformed_y < 0 || transformed_rect.y() < min_transformed_y)
+ min_transformed_y = transformed_rect.y();
+ if (transformed_rect.bottom() > max_transformed_y)
+ max_transformed_y = transformed_rect.bottom();
+
+ gfx::RectF transformed_quad_layer_rect =
+ transform(draw_quad->shared_quad_state->quad_layer_rect);
+ EXPECT_RECTF_EQ(transformed_quad_layer_rect,
+ gfx::RectF(0.f, 0.f, 1000.f, 10000.f));
+
+ gfx::RectF transformed_visible_quad_layer_rect =
+ transform(draw_quad->shared_quad_state->visible_quad_layer_rect);
+ EXPECT_RECTF_EQ(transformed_visible_quad_layer_rect,
+ gfx::RectF(0.f, 5000.f, 1000.f, 1000.f));
+ }
+ EXPECT_EQ(min_y, 0);
+ EXPECT_FLOAT_EQ(min_transformed_y, 5000.f);
+ EXPECT_FLOAT_EQ(max_transformed_y, 6000.f);
+}
+
+TEST_F(PictureLayerImplTest, FarScrolledSolidColorQuadsShifted) {
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
+
+ gfx::Size layer_bounds(1000, 10000);
+ scoped_refptr<FakeRasterSource> active_raster_source =
+ FakeRasterSource::CreateFilled(layer_bounds);
+ SetupPendingTree(active_raster_source);
+ ActivateTree();
+
+ active_layer()->SetContentsOpaque(true);
+ active_layer()->draw_properties().visible_layer_rect =
+ gfx::Rect(0, 9000, 1000, 1000);
+ active_layer()->UpdateTiles();
+
+ auto* high_res_tiling = active_layer()->HighResTiling();
+ ASSERT_TRUE(high_res_tiling);
+ const std::vector<Tile*>& tiles = high_res_tiling->AllTilesForTesting();
+ ASSERT_GT(tiles.size(), 0u);
+
+ for (auto* tile : tiles)
+ tile->draw_info().SetSolidColorForTesting(SK_ColorBLUE);
+
+ AppendQuadsData data;
+ active_layer()->WillDraw(DRAW_MODE_HARDWARE, nullptr);
+ active_layer()->AppendQuads(render_pass.get(), &data);
+ active_layer()->DidDraw(nullptr);
+
+ EXPECT_EQ(20u, render_pass->quad_list.size());
+ int last_y = -1;
+ int last_height = -1;
+ int min_y = std::numeric_limits<int>::max();
+ float min_transformed_y = std::numeric_limits<float>::max();
+ float max_transformed_y = -1;
+ for (auto* draw_quad : render_pass->quad_list) {
+ if (last_y == -1) {
+ last_y = draw_quad->rect.y();
+ min_y = last_y;
+ last_height = draw_quad->rect.height();
+ }
+
+ if (last_y != draw_quad->rect.y()) {
+ EXPECT_EQ(last_y + last_height, draw_quad->rect.y());
+ last_y = draw_quad->rect.y();
+ min_y = std::min(min_y, last_y);
+ last_height = draw_quad->rect.height();
+ }
+ EXPECT_LT(last_y, 5000);
+ EXPECT_EQ(draw_quad->material, viz::DrawQuad::SOLID_COLOR);
+
+ auto transform = [draw_quad](const gfx::Rect& rect) {
+ gfx::RectF result(rect);
+ draw_quad->shared_quad_state->quad_to_target_transform.TransformRect(
+ &result);
+ return result;
+ };
+
+ gfx::RectF transformed_rect = transform(draw_quad->rect);
+ EXPECT_GT(transformed_rect.y(), 0);
+ if (transformed_rect.y() < min_transformed_y)
+ min_transformed_y = transformed_rect.y();
+ if (transformed_rect.bottom() > max_transformed_y)
+ max_transformed_y = transformed_rect.bottom();
+
+ gfx::RectF transformed_quad_layer_rect =
+ transform(draw_quad->shared_quad_state->quad_layer_rect);
+ EXPECT_RECTF_EQ(transformed_quad_layer_rect,
+ gfx::RectF(0.f, 0.f, 1000.f, 10000.f));
+
+ gfx::RectF transformed_visible_quad_layer_rect =
+ transform(draw_quad->shared_quad_state->visible_quad_layer_rect);
+ EXPECT_RECTF_EQ(transformed_visible_quad_layer_rect,
+ gfx::RectF(0.f, 9000.f, 1000.f, 1000.f));
+ }
+ EXPECT_EQ(min_y, 0);
+ EXPECT_FLOAT_EQ(min_transformed_y, 9000.f);
+ EXPECT_FLOAT_EQ(max_transformed_y, 10000.f);
+}
+
TEST_F(PictureLayerImplTest, SolidColorLayerHasVisibleFullCoverage) {
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
gfx::Size layer_bounds(1500, 1500);
gfx::Rect visible_rect(250, 250, 1000, 1000);
@@ -1743,7 +1905,7 @@ TEST_F(NoLowResPictureLayerImplTest,
host_impl()->active_tree()->UpdateDrawProperties();
active_layer()->draw_properties().visible_layer_rect = visible_layer_rect;
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
active_layer()->AppendQuads(render_pass.get(), &data);
@@ -1772,7 +1934,7 @@ TEST_F(PictureLayerImplTest, HighResTileIsComplete) {
active_layer()->tilings()->tiling_at(0)->AllTilesForTesting();
host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
active_layer()->AppendQuads(render_pass.get(), &data);
@@ -1796,7 +1958,7 @@ TEST_F(PictureLayerImplTest, HighResTileIsIncomplete) {
SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
ActivateTree();
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
active_layer()->AppendQuads(render_pass.get(), &data);
@@ -1824,7 +1986,7 @@ TEST_F(PictureLayerImplTest, HighResTileIsIncompleteLowResComplete) {
host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting(
low_tiles);
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
active_layer()->AppendQuads(render_pass.get(), &data);
@@ -1860,7 +2022,7 @@ TEST_F(PictureLayerImplTest, LowResTileIsIncomplete) {
host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting(
low_tiles);
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
active_layer()->AppendQuads(render_pass.get(), &data);
@@ -1915,7 +2077,7 @@ TEST_F(PictureLayerImplTest,
host_impl()->tile_manager()->InitializeTilesWithResourcesForTesting(
high_tiles);
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
active_layer()->AppendQuads(render_pass.get(), &data);
@@ -1925,12 +2087,12 @@ TEST_F(PictureLayerImplTest,
ASSERT_GT(render_pass->quad_list.size(), 9u);
EXPECT_EQ(gfx::Rect(0, 0, 99, 99), render_pass->quad_list.front()->rect);
EXPECT_EQ(gfx::RectF(0.f, 0.f, 99.f, 99.f),
- TileDrawQuad::MaterialCast(render_pass->quad_list.front())
+ viz::TileDrawQuad::MaterialCast(render_pass->quad_list.front())
->tex_coord_rect);
EXPECT_EQ(gfx::Rect(99, 0, 100, 99),
render_pass->quad_list.ElementAt(1)->rect);
EXPECT_EQ(gfx::RectF(49.5f, 0.f, 50.f, 49.5f),
- TileDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(1))
+ viz::TileDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(1))
->tex_coord_rect);
// Neither the high res nor the ideal tiles were considered as incomplete.
@@ -1951,7 +2113,7 @@ TEST_F(PictureLayerImplTest, AppendQuadsDataForCheckerboard) {
SetupPendingTreeWithFixedTileSize(pending_raster_source, tile_size, Region());
ActivateTree();
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
active_layer()->AppendQuads(render_pass.get(), &data);
@@ -3113,6 +3275,34 @@ TEST_F(PictureLayerImplTest, Occlusion) {
}
}
+TEST_F(PictureLayerImplTest, OcclusionOnSolidColorPictureLayer) {
+ gfx::Size layer_bounds(1000, 1000);
+ gfx::Size viewport_size(1000, 1000);
+
+ LayerTestCommon::LayerImplTest impl;
+ host_impl()->SetViewportSize(viewport_size);
+
+ scoped_refptr<FakeRasterSource> pending_raster_source =
+ FakeRasterSource::CreateFilledSolidColor(layer_bounds);
+ SetupPendingTree(pending_raster_source);
+ host_impl()->pending_tree()->SetDeviceScaleFactor(2.f);
+ ActivateTree();
+
+ {
+ SCOPED_TRACE("Scaled occlusion");
+ gfx::Rect occluded(150, 0, 200, 1000);
+ impl.AppendQuadsWithOcclusion(active_layer(), occluded);
+
+ size_t partial_occluded_count = 0;
+ LayerTestCommon::VerifyQuadsAreOccluded(impl.quad_list(), occluded,
+ &partial_occluded_count);
+ // None of the quads shall be occluded and half of them are partially
+ // occluded.
+ EXPECT_EQ(16u, impl.quad_list().size());
+ EXPECT_EQ(8u, partial_occluded_count);
+ }
+}
+
TEST_F(PictureLayerImplTest, RasterScaleChangeWithoutAnimation) {
gfx::Size tile_size(host_impl()->settings().default_tile_size);
SetupDefaultTrees(tile_size);
@@ -3560,7 +3750,7 @@ TEST_F(NoLowResPictureLayerImplTest, ReleaseTileResources) {
}
TEST_F(PictureLayerImplTest, SharedQuadStateContainsMaxTilingScale) {
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
gfx::Size layer_bounds(1000, 2000);
host_impl()->SetViewportSize(gfx::Size(10000, 20000));
@@ -3639,7 +3829,7 @@ TEST_F(PictureLayerImplTestWithDelegatingRenderer,
host_impl()->SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES);
host_impl()->PrepareTiles();
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
active_layer()->WillDraw(DRAW_MODE_HARDWARE, nullptr);
active_layer()->AppendQuads(render_pass.get(), &data);
@@ -3648,9 +3838,9 @@ TEST_F(PictureLayerImplTestWithDelegatingRenderer,
// Even when OOM, quads should be produced, and should be different material
// from quads with resource.
EXPECT_LT(max_tiles, render_pass->quad_list.size());
- EXPECT_EQ(DrawQuad::Material::TILED_CONTENT,
+ EXPECT_EQ(viz::DrawQuad::Material::TILED_CONTENT,
render_pass->quad_list.front()->material);
- EXPECT_EQ(DrawQuad::Material::SOLID_COLOR,
+ EXPECT_EQ(viz::DrawQuad::Material::SOLID_COLOR,
render_pass->quad_list.back()->material);
}
@@ -4357,7 +4547,7 @@ void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid,
}
}
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
active_layer()->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
active_layer()->AppendQuads(render_pass.get(), &data);
@@ -4367,9 +4557,9 @@ void PictureLayerImplTest::TestQuadsForSolidColor(bool test_for_solid,
if (partial_opaque)
EXPECT_EQ(4u, render_pass->quad_list.size());
- DrawQuad::Material expected = test_for_solid
- ? DrawQuad::Material::SOLID_COLOR
- : DrawQuad::Material::TILED_CONTENT;
+ viz::DrawQuad::Material expected =
+ test_for_solid ? viz::DrawQuad::Material::SOLID_COLOR
+ : viz::DrawQuad::Material::TILED_CONTENT;
EXPECT_EQ(expected, render_pass->quad_list.front()->material);
}
@@ -4989,14 +5179,15 @@ TEST_F(PictureLayerImplTest, CompositedImageIgnoreIdealContentsScale) {
active_layer->tilings()->tiling_at(0)->AllTilesForTesting());
// Draw.
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
active_layer->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
active_layer->AppendQuads(render_pass.get(), &data);
active_layer->DidDraw(nullptr);
ASSERT_FALSE(render_pass->quad_list.empty());
- EXPECT_EQ(DrawQuad::TILED_CONTENT, render_pass->quad_list.front()->material);
+ EXPECT_EQ(viz::DrawQuad::TILED_CONTENT,
+ render_pass->quad_list.front()->material);
// Tiles are ready at correct scale, so should not set had_incomplete_tile.
EXPECT_EQ(0, data.num_incomplete_tiles);
@@ -5194,5 +5385,59 @@ TEST_F(PictureLayerImplTest, ChangeRasterTranslationNukeActiveLayerTiles) {
}
}
+TEST_F(PictureLayerImplTest, AnimatedImages) {
+ gfx::Size layer_bounds(1000, 1000);
+
+ // Set up a raster source with 2 animated images.
+ auto recording_source = FakeRecordingSource::CreateRecordingSource(
+ gfx::Rect(layer_bounds), layer_bounds);
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(1)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(1))};
+ PaintImage image1 = CreateAnimatedImage(gfx::Size(200, 200), frames);
+ PaintImage image2 = CreateAnimatedImage(gfx::Size(200, 200), frames);
+ recording_source->add_draw_image(image1, gfx::Point(100, 100));
+ recording_source->add_draw_image(image2, gfx::Point(500, 500));
+ recording_source->Rerecord();
+ scoped_refptr<RasterSource> raster_source =
+ recording_source->CreateRasterSource();
+
+ // All images should be registered on the pending layer.
+ SetupPendingTree(raster_source, gfx::Size(), Region(gfx::Rect(layer_bounds)));
+ auto* controller = host_impl()->image_animation_controller();
+ EXPECT_EQ(controller->GetDriversForTesting(image1.stable_id())
+ .count(pending_layer()),
+ 1u);
+ EXPECT_EQ(controller->GetDriversForTesting(image2.stable_id())
+ .count(pending_layer()),
+ 1u);
+
+ // Make only the first image visible and verify that only this image is
+ // animated.
+ gfx::Rect visible_rect(0, 0, 300, 300);
+ pending_layer()->set_visible_layer_rect(visible_rect);
+ EXPECT_TRUE(pending_layer()->ShouldAnimate(image1.stable_id()));
+ EXPECT_FALSE(pending_layer()->ShouldAnimate(image2.stable_id()));
+
+ // Now activate and make sure the active layer is registered as well.
+ ActivateTree();
+ active_layer()->set_visible_layer_rect(visible_rect);
+ EXPECT_EQ(controller->GetDriversForTesting(image1.stable_id())
+ .count(active_layer()),
+ 1u);
+ EXPECT_EQ(controller->GetDriversForTesting(image2.stable_id())
+ .count(active_layer()),
+ 1u);
+
+ // Once activated, only the active layer should drive animations for these
+ // images. Since DrawProperties are not updated on the recycle tree, it has
+ // stale state for visibility of images.
+ ASSERT_EQ(old_pending_layer()->visible_layer_rect(), visible_rect);
+ EXPECT_FALSE(old_pending_layer()->ShouldAnimate(image1.stable_id()));
+ EXPECT_FALSE(old_pending_layer()->ShouldAnimate(image2.stable_id()));
+ EXPECT_TRUE(active_layer()->ShouldAnimate(image1.stable_id()));
+ EXPECT_FALSE(active_layer()->ShouldAnimate(image2.stable_id()));
+}
+
} // namespace
} // namespace cc
diff --git a/chromium/cc/layers/picture_layer_unittest.cc b/chromium/cc/layers/picture_layer_unittest.cc
index 793b7c50616..57fb4fde0f6 100644
--- a/chromium/cc/layers/picture_layer_unittest.cc
+++ b/chromium/cc/layers/picture_layer_unittest.cc
@@ -223,7 +223,7 @@ TEST(PictureLayerTest, ClearVisibleRectWhenNoTiling) {
host_impl.ActivateSyncTree();
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
host_impl.active_tree()->root_layer_for_testing()->WillDraw(
DRAW_MODE_SOFTWARE, nullptr);
diff --git a/chromium/cc/layers/recording_source.cc b/chromium/cc/layers/recording_source.cc
index 1fa1d7c02dc..21c0aff62d9 100644
--- a/chromium/cc/layers/recording_source.cc
+++ b/chromium/cc/layers/recording_source.cc
@@ -156,7 +156,8 @@ void RecordingSource::DetermineIfSolidColor() {
TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount",
display_list_->op_count());
is_solid_color_ = display_list_->GetColorIfSolidInRect(
- gfx::Rect(GetSize()), &solid_color_, kMaxOpsToAnalyzeForLayer);
+ gfx::ScaleToRoundedRect(gfx::Rect(GetSize()), recording_scale_factor_),
+ &solid_color_, kMaxOpsToAnalyzeForLayer);
}
} // namespace cc
diff --git a/chromium/cc/layers/recording_source_unittest.cc b/chromium/cc/layers/recording_source_unittest.cc
index 3431190eee6..82c424ff8ef 100644
--- a/chromium/cc/layers/recording_source_unittest.cc
+++ b/chromium/cc/layers/recording_source_unittest.cc
@@ -111,7 +111,8 @@ TEST(RecordingSourceTest, DiscardableImagesWithTransform) {
std::vector<const DrawImage*> images;
raster_source->GetDiscardableImagesInRect(gfx::Rect(130, 0, 128, 128),
&images);
- DrawImage image(*images[0], scale, DefaultColorSpace());
+ DrawImage image(*images[0], scale, PaintImage::kDefaultFrameIndex,
+ DefaultColorSpace());
EXPECT_EQ(1u, images.size());
EXPECT_FLOAT_EQ(scale, image.scale().width());
EXPECT_FLOAT_EQ(scale, image.scale().height());
@@ -338,5 +339,53 @@ TEST(RecordingSourceTest, DiscardableImagesBaseNonDiscardable) {
}
}
+TEST(RecordingSourceTest, AnalyzeIsSolid) {
+ gfx::Size layer_bounds(400, 400);
+ const std::vector<float> recording_scales = {1.f, 1.25f, 1.33f, 1.5f, 1.6f,
+ 1.66f, 2.f, 2.25f, 2.5f};
+ for (float recording_scale : recording_scales) {
+ std::unique_ptr<FakeRecordingSource> recording_source =
+ FakeRecordingSource::CreateFilledRecordingSource(layer_bounds);
+ recording_source->SetRecordingScaleFactor(recording_scale);
+
+ PaintFlags solid_flags;
+ SkColor solid_color = SkColorSetARGB(255, 12, 23, 34);
+ solid_flags.setColor(solid_color);
+
+ SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67);
+ PaintFlags non_solid_flags;
+ non_solid_flags.setColor(non_solid_color);
+
+ recording_source->add_draw_rect_with_flags(
+ gfx::ScaleToEnclosingRect(gfx::Rect(layer_bounds), recording_scale),
+ solid_flags);
+ recording_source->Rerecord();
+
+ scoped_refptr<RasterSource> raster = recording_source->CreateRasterSource();
+
+ EXPECT_TRUE(raster->IsSolidColor())
+ << " recording scale: " << recording_scale;
+ EXPECT_EQ(raster->GetSolidColor(), solid_color);
+
+ for (int y = 0; y < layer_bounds.height(); y += 50) {
+ for (int x = 0; x < layer_bounds.width(); x += 50) {
+ recording_source->reset_draws();
+ recording_source->add_draw_rect_with_flags(
+ gfx::ScaleToEnclosingRect(gfx::Rect(layer_bounds), recording_scale),
+ solid_flags);
+ recording_source->add_draw_rect_with_flags(
+ gfx::Rect(std::round(x * recording_scale),
+ std::round(y * recording_scale), 1, 1),
+ non_solid_flags);
+ recording_source->Rerecord();
+ raster = recording_source->CreateRasterSource();
+ EXPECT_FALSE(raster->IsSolidColor())
+ << " recording scale: " << recording_scale << " pixel at: (" << x
+ << ", " << y << ") was not solid.";
+ }
+ }
+ }
+}
+
} // namespace
} // namespace cc
diff --git a/chromium/cc/layers/render_surface_impl.cc b/chromium/cc/layers/render_surface_impl.cc
index 1929681bbe3..c1aa1132c61 100644
--- a/chromium/cc/layers/render_surface_impl.cc
+++ b/chromium/cc/layers/render_surface_impl.cc
@@ -14,18 +14,18 @@
#include "cc/base/math_util.h"
#include "cc/debug/debug_colors.h"
#include "cc/layers/append_quads_data.h"
-#include "cc/quads/content_draw_quad_base.h"
-#include "cc/quads/debug_border_draw_quad.h"
-#include "cc/quads/render_pass.h"
-#include "cc/quads/render_pass_draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
#include "cc/trees/damage_tracker.h"
#include "cc/trees/draw_property_utils.h"
#include "cc/trees/effect_node.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/occlusion.h"
#include "cc/trees/transform_node.h"
+#include "components/viz/common/quads/content_draw_quad_base.h"
+#include "components/viz/common/quads/debug_border_draw_quad.h"
+#include "components/viz/common/quads/render_pass.h"
+#include "components/viz/common/quads/render_pass_draw_quad.h"
#include "components/viz/common/quads/shared_quad_state.h"
+#include "components/viz/common/quads/solid_color_draw_quad.h"
#include "third_party/skia/include/core/SkImageFilter.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/transform.h"
@@ -129,6 +129,10 @@ bool RenderSurfaceImpl::HasMask() const {
return OwningEffectNode()->mask_layer_id != Layer::INVALID_ID;
}
+bool RenderSurfaceImpl::HasMaskingContributingSurface() const {
+ return OwningEffectNode()->has_masking_child;
+}
+
const FilterOperations& RenderSurfaceImpl::Filters() const {
return OwningEffectNode()->filters;
}
@@ -148,6 +152,10 @@ const FilterOperations& RenderSurfaceImpl::BackgroundFilters() const {
return OwningEffectNode()->background_filters;
}
+bool RenderSurfaceImpl::TrilinearFiltering() const {
+ return OwningEffectNode()->trilinear_filtering;
+}
+
bool RenderSurfaceImpl::HasCopyRequest() const {
return OwningEffectNode()->has_copy_request;
}
@@ -357,14 +365,16 @@ void RenderSurfaceImpl::ResetPropertyChangedFlags() {
ancestor_property_changed_ = false;
}
-std::unique_ptr<RenderPass> RenderSurfaceImpl::CreateRenderPass() {
- std::unique_ptr<RenderPass> pass = RenderPass::Create(num_contributors_);
+std::unique_ptr<viz::RenderPass> RenderSurfaceImpl::CreateRenderPass() {
+ std::unique_ptr<viz::RenderPass> pass =
+ viz::RenderPass::Create(num_contributors_);
gfx::Rect damage_rect = GetDamageRect();
damage_rect.Intersect(content_rect());
pass->SetNew(id(), content_rect(), damage_rect,
draw_properties_.screen_space_transform);
pass->filters = Filters();
pass->background_filters = BackgroundFilters();
+ pass->generate_mipmap = TrilinearFiltering();
pass->cache_render_pass = ShouldCacheRenderSurface();
pass->has_damage_from_contributing_content =
HasDamageFromeContributingContent();
@@ -372,7 +382,7 @@ std::unique_ptr<RenderPass> RenderSurfaceImpl::CreateRenderPass() {
}
void RenderSurfaceImpl::AppendQuads(DrawMode draw_mode,
- RenderPass* render_pass,
+ viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) {
gfx::Rect visible_layer_rect =
occlusion_in_content_space().GetUnoccludedContentRect(content_rect());
@@ -383,17 +393,18 @@ void RenderSurfaceImpl::AppendQuads(DrawMode draw_mode,
int sorting_context_id =
property_trees->transform_tree.Node(TransformTreeIndex())
->sorting_context_id;
+ bool contents_opaque = false;
viz::SharedQuadState* shared_quad_state =
render_pass->CreateAndAppendSharedQuadState();
shared_quad_state->SetAll(
draw_transform(), content_rect(), content_rect(),
- draw_properties_.clip_rect, draw_properties_.is_clipped,
+ draw_properties_.clip_rect, draw_properties_.is_clipped, contents_opaque,
draw_properties_.draw_opacity, BlendMode(), sorting_context_id);
if (layer_tree_impl_->debug_state().show_debug_borders.test(
DebugBorderType::RENDERPASS)) {
- DebugBorderDrawQuad* debug_border_quad =
- render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
+ auto* debug_border_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::DebugBorderDrawQuad>();
debug_border_quad->SetNew(shared_quad_state, content_rect(),
visible_layer_rect, GetDebugBorderColor(),
GetDebugBorderWidth());
@@ -436,14 +447,14 @@ void RenderSurfaceImpl::AppendQuads(DrawMode draw_mode,
}
gfx::RectF tex_coord_rect(gfx::Rect(content_rect().size()));
- RenderPassDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
+ auto* quad = render_pass->CreateAndAppendDrawQuad<viz::RenderPassDrawQuad>();
quad->SetNew(shared_quad_state, content_rect(), visible_layer_rect, id(),
mask_resource_id, mask_uv_rect, mask_texture_size,
- surface_contents_scale, FiltersOrigin(), tex_coord_rect);
+ surface_contents_scale, FiltersOrigin(), tex_coord_rect,
+ !layer_tree_impl_->settings().enable_edge_anti_aliasing);
}
-void RenderSurfaceImpl::TileMaskLayer(RenderPass* render_pass,
+void RenderSurfaceImpl::TileMaskLayer(viz::RenderPass* render_pass,
viz::SharedQuadState* shared_quad_state,
const gfx::Rect& visible_layer_rect) {
DCHECK(MaskLayer());
@@ -452,7 +463,7 @@ void RenderSurfaceImpl::TileMaskLayer(RenderPass* render_pass,
LayerImpl* mask_layer = MaskLayer();
gfx::Vector2dF owning_layer_to_surface_contents_scale =
OwningEffectNode()->surface_contents_scale;
- std::unique_ptr<RenderPass> temp_render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> temp_render_pass = viz::RenderPass::Create();
AppendQuadsData temp_append_quads_data;
mask_layer->AppendQuads(temp_render_pass.get(), &temp_append_quads_data);
@@ -504,12 +515,12 @@ void RenderSurfaceImpl::TileMaskLayer(RenderPass* render_pass,
-content_rect().OffsetFromOrigin());
switch (temp_quad->material) {
- case DrawQuad::TILED_CONTENT: {
+ case viz::DrawQuad::TILED_CONTENT: {
DCHECK_EQ(1U, temp_quad->resources.count);
gfx::Size mask_texture_size =
- static_cast<ContentDrawQuadBase*>(temp_quad)->texture_size;
+ static_cast<viz::ContentDrawQuadBase*>(temp_quad)->texture_size;
gfx::RectF temp_tex_coord_rect =
- static_cast<ContentDrawQuadBase*>(temp_quad)->tex_coord_rect;
+ static_cast<viz::ContentDrawQuadBase*>(temp_quad)->tex_coord_rect;
gfx::Transform coverage_to_non_normalized_mask =
gfx::Transform(SkMatrix44(SkMatrix::MakeRectToRect(
RectToSkRect(quad_rect), RectFToSkRect(temp_tex_coord_rect),
@@ -522,32 +533,32 @@ void RenderSurfaceImpl::TileMaskLayer(RenderPass* render_pass,
gfx::RectF mask_uv_rect = gfx::RectF(render_quad_rect);
coverage_to_normalized_mask.TransformRect(&mask_uv_rect);
- RenderPassDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
+ auto* quad =
+ render_pass->CreateAndAppendDrawQuad<viz::RenderPassDrawQuad>();
quad->SetNew(shared_quad_state, render_quad_rect,
quad_visible_rect_in_coverage_space, id(),
temp_quad->resources.ids[0], mask_uv_rect,
mask_texture_size, owning_layer_to_surface_contents_scale,
- FiltersOrigin(),
- quad_rect_in_non_normalized_texture_space);
+ FiltersOrigin(), quad_rect_in_non_normalized_texture_space,
+ !layer_tree_impl_->settings().enable_edge_anti_aliasing);
} break;
- case DrawQuad::SOLID_COLOR: {
- if (!static_cast<SolidColorDrawQuad*>(temp_quad)->color)
+ case viz::DrawQuad::SOLID_COLOR: {
+ if (!static_cast<viz::SolidColorDrawQuad*>(temp_quad)->color)
continue;
SkAlpha solid = SK_AlphaOPAQUE;
- DCHECK_EQ(
- SkColorGetA(static_cast<SolidColorDrawQuad*>(temp_quad)->color),
- solid);
+ DCHECK_EQ(SkColorGetA(
+ static_cast<viz::SolidColorDrawQuad*>(temp_quad)->color),
+ solid);
- RenderPassDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
+ auto* quad =
+ render_pass->CreateAndAppendDrawQuad<viz::RenderPassDrawQuad>();
quad->SetNew(shared_quad_state, render_quad_rect,
quad_visible_rect_in_coverage_space, id(), 0, gfx::RectF(),
gfx::Size(), owning_layer_to_surface_contents_scale,
- FiltersOrigin(),
- quad_rect_in_non_normalized_texture_space);
+ FiltersOrigin(), quad_rect_in_non_normalized_texture_space,
+ !layer_tree_impl_->settings().enable_edge_anti_aliasing);
} break;
- case DrawQuad::DEBUG_BORDER:
+ case viz::DrawQuad::DEBUG_BORDER:
NOTIMPLEMENTED();
break;
default:
diff --git a/chromium/cc/layers/render_surface_impl.h b/chromium/cc/layers/render_surface_impl.h
index 4964101444a..00b05df4860 100644
--- a/chromium/cc/layers/render_surface_impl.h
+++ b/chromium/cc/layers/render_surface_impl.h
@@ -15,9 +15,9 @@
#include "cc/cc_export.h"
#include "cc/layers/draw_mode.h"
#include "cc/layers/layer_collections.h"
-#include "cc/quads/render_pass.h"
#include "cc/trees/occlusion.h"
#include "cc/trees/property_tree.h"
+#include "components/viz/common/quads/render_pass.h"
#include "components/viz/common/quads/shared_quad_state.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
@@ -146,12 +146,15 @@ class CC_EXPORT RenderSurfaceImpl {
LayerImpl* MaskLayer();
bool HasMask() const;
+ bool HasMaskingContributingSurface() const;
const FilterOperations& Filters() const;
const FilterOperations& BackgroundFilters() const;
gfx::PointF FiltersOrigin() const;
gfx::Transform SurfaceScale() const;
+ bool TrilinearFiltering() const;
+
bool HasCopyRequest() const;
bool ShouldCacheRenderSurface() const;
@@ -166,9 +169,9 @@ class CC_EXPORT RenderSurfaceImpl {
DamageTracker* damage_tracker() const { return damage_tracker_.get(); }
gfx::Rect GetDamageRect() const;
- std::unique_ptr<RenderPass> CreateRenderPass();
+ std::unique_ptr<viz::RenderPass> CreateRenderPass();
void AppendQuads(DrawMode draw_mode,
- RenderPass* render_pass,
+ viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data);
int TransformTreeIndex() const;
@@ -184,7 +187,7 @@ class CC_EXPORT RenderSurfaceImpl {
gfx::Rect CalculateClippedAccumulatedContentRect();
gfx::Rect CalculateExpandedClipForFilters(
const gfx::Transform& target_to_surface);
- void TileMaskLayer(RenderPass* render_pass,
+ void TileMaskLayer(viz::RenderPass* render_pass,
viz::SharedQuadState* shared_quad_state,
const gfx::Rect& visible_layer_rect);
diff --git a/chromium/cc/layers/render_surface_impl_unittest.cc b/chromium/cc/layers/render_surface_impl_unittest.cc
index 0694b317079..0690231faea 100644
--- a/chromium/cc/layers/render_surface_impl_unittest.cc
+++ b/chromium/cc/layers/render_surface_impl_unittest.cc
@@ -7,10 +7,10 @@
#include <stddef.h>
#include "cc/layers/append_quads_data.h"
-#include "cc/quads/render_pass_draw_quad.h"
#include "cc/test/fake_mask_layer_impl.h"
#include "cc/test/fake_raster_source.h"
#include "cc/test/layer_test_common.h"
+#include "components/viz/common/quads/render_pass_draw_quad.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
@@ -65,8 +65,10 @@ TEST(RenderSurfaceLayerImplTest, Occlusion) {
}
}
-static std::unique_ptr<RenderPass> DoAppendQuadsWithScaledMask(
- DrawMode draw_mode) {
+static std::unique_ptr<viz::RenderPass> DoAppendQuadsWithScaledMask(
+ DrawMode draw_mode,
+ float device_scale_factor,
+ Layer::LayerMaskType mask_type) {
gfx::Size layer_size(1000, 1000);
gfx::Size viewport_size(1000, 1000);
float scale_factor = 2;
@@ -88,8 +90,7 @@ static std::unique_ptr<RenderPass> DoAppendQuadsWithScaledMask(
surface->test_properties()->transform = scale;
std::unique_ptr<FakeMaskLayerImpl> mask_layer = FakeMaskLayerImpl::Create(
- impl.host_impl()->active_tree(), 4, raster_source,
- Layer::LayerMaskType::SINGLE_TEXTURE_MASK);
+ impl.host_impl()->active_tree(), 4, raster_source, mask_type);
mask_layer->set_resource_size(
gfx::ScaleToCeiledSize(layer_size, scale_factor));
mask_layer->SetDrawsContent(true);
@@ -105,6 +106,7 @@ static std::unique_ptr<RenderPass> DoAppendQuadsWithScaledMask(
root->test_properties()->AddChild(std::move(surface));
impl.host_impl()->active_tree()->SetRootLayerForTesting(std::move(root));
+ impl.host_impl()->active_tree()->SetDeviceScaleFactor(device_scale_factor);
impl.host_impl()->SetViewportSize(viewport_size);
impl.host_impl()->active_tree()->BuildLayerListAndPropertyTreesForTesting();
impl.host_impl()->active_tree()->UpdateDrawProperties();
@@ -115,7 +117,7 @@ static std::unique_ptr<RenderPass> DoAppendQuadsWithScaledMask(
->test_properties()
->children[0];
RenderSurfaceImpl* render_surface_impl = GetRenderSurface(surface_raw);
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData append_quads_data;
render_surface_impl->AppendQuads(draw_mode, render_pass.get(),
&append_quads_data);
@@ -123,23 +125,37 @@ static std::unique_ptr<RenderPass> DoAppendQuadsWithScaledMask(
}
TEST(RenderSurfaceLayerImplTest, AppendQuadsWithScaledMask) {
- std::unique_ptr<RenderPass> render_pass =
- DoAppendQuadsWithScaledMask(DRAW_MODE_HARDWARE);
+ std::unique_ptr<viz::RenderPass> render_pass = DoAppendQuadsWithScaledMask(
+ DRAW_MODE_HARDWARE, 1.f, Layer::LayerMaskType::SINGLE_TEXTURE_MASK);
DCHECK(render_pass->quad_list.front());
- const RenderPassDrawQuad* quad =
- RenderPassDrawQuad::MaterialCast(render_pass->quad_list.front());
+ const viz::RenderPassDrawQuad* quad =
+ viz::RenderPassDrawQuad::MaterialCast(render_pass->quad_list.front());
EXPECT_EQ(gfx::RectF(0, 0, 1, 1), quad->mask_uv_rect);
EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), quad->filters_scale);
}
TEST(RenderSurfaceLayerImplTest, ResourcelessAppendQuadsSkipMask) {
- std::unique_ptr<RenderPass> render_pass =
- DoAppendQuadsWithScaledMask(DRAW_MODE_RESOURCELESS_SOFTWARE);
+ std::unique_ptr<viz::RenderPass> render_pass =
+ DoAppendQuadsWithScaledMask(DRAW_MODE_RESOURCELESS_SOFTWARE, 1.f,
+ Layer::LayerMaskType::SINGLE_TEXTURE_MASK);
DCHECK(render_pass->quad_list.front());
- const RenderPassDrawQuad* quad =
- RenderPassDrawQuad::MaterialCast(render_pass->quad_list.front());
+ const viz::RenderPassDrawQuad* quad =
+ viz::RenderPassDrawQuad::MaterialCast(render_pass->quad_list.front());
EXPECT_EQ(0u, quad->mask_resource_id());
}
+TEST(RenderSurfaceLayerImplTest,
+ AppendQuadsWithSolidColorMaskAndDeviceScaleFactor) {
+ std::unique_ptr<viz::RenderPass> render_pass = DoAppendQuadsWithScaledMask(
+ DRAW_MODE_HARDWARE, 2.f, Layer::LayerMaskType::MULTI_TEXTURE_MASK);
+ DCHECK(render_pass->quad_list.front());
+ const viz::RenderPassDrawQuad* quad =
+ viz::RenderPassDrawQuad::MaterialCast(render_pass->quad_list.front());
+ EXPECT_EQ(gfx::Transform(),
+ quad->shared_quad_state->quad_to_target_transform);
+ LayerTestCommon::VerifyQuadsExactlyCoverRect(
+ render_pass->quad_list, quad->shared_quad_state->quad_layer_rect);
+}
+
} // namespace
} // namespace cc
diff --git a/chromium/cc/layers/render_surface_unittest.cc b/chromium/cc/layers/render_surface_unittest.cc
index 0bfef291e97..8385acee844 100644
--- a/chromium/cc/layers/render_surface_unittest.cc
+++ b/chromium/cc/layers/render_surface_unittest.cc
@@ -5,7 +5,6 @@
#include "cc/layers/append_quads_data.h"
#include "cc/layers/layer_impl.h"
#include "cc/layers/render_surface_impl.h"
-#include "cc/quads/tile_draw_quad.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_frame_sink.h"
#include "cc/test/fake_layer_tree_host_impl.h"
@@ -17,6 +16,7 @@
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/single_thread_proxy.h"
#include "components/viz/common/quads/shared_quad_state.h"
+#include "components/viz/common/quads/tile_draw_quad.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/transform.h"
@@ -57,18 +57,18 @@ class FakePictureLayerImplForRenderSurfaceTest : public FakePictureLayerImpl {
bool HasValidTilePriorities() const override { return false; }
- void AppendQuads(RenderPass* render_pass,
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override {
viz::SharedQuadState* shared_quad_state =
render_pass->CreateAndAppendSharedQuadState();
float max_contents_scale = 1.f;
PopulateScaledSharedQuadState(shared_quad_state, max_contents_scale,
- max_contents_scale);
+ max_contents_scale, contents_opaque());
bool needs_blending = false;
for (const auto& rect : quad_rects_) {
- TileDrawQuad* quad = render_pass->CreateAndAppendDrawQuad<TileDrawQuad>();
+ auto* quad = render_pass->CreateAndAppendDrawQuad<viz::TileDrawQuad>();
quad->SetNew(shared_quad_state, rect, rect, needs_blending, 0,
- gfx::RectF(rect), bounds(), false, false);
+ gfx::RectF(rect), bounds(), false, false, false);
}
}
@@ -177,7 +177,7 @@ TEST(RenderSurfaceTest, SanityCheckSurfaceCreatesCorrectSharedQuadState) {
render_surface->SetDrawOpacity(1.f);
render_surface->SetDrawTransform(origin);
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData append_quads_data;
render_surface->AppendQuads(DRAW_MODE_HARDWARE, render_pass.get(),
@@ -287,7 +287,7 @@ TEST(RenderSurfaceTest, SanityCheckSurfaceDropsOccludedRenderPassDrawQuads) {
Occlusion(gfx::Transform(), SimpleEnclosedRegion(occluded),
SimpleEnclosedRegion(occluded)));
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData append_quads_data;
render_surface->AppendQuads(DRAW_MODE_HARDWARE, render_pass.get(),
@@ -357,7 +357,7 @@ TEST(RenderSurfaceTest, SanityCheckSurfaceIgnoreMaskLayerOcclusion) {
Occlusion(gfx::Transform(), SimpleEnclosedRegion(occluded),
SimpleEnclosedRegion(occluded));
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData append_quads_data;
render_surface->AppendQuads(DRAW_MODE_HARDWARE, render_pass.get(),
diff --git a/chromium/cc/layers/scrollbar_layer_unittest.cc b/chromium/cc/layers/scrollbar_layer_unittest.cc
index 14d03634c71..af1f017dc0f 100644
--- a/chromium/cc/layers/scrollbar_layer_unittest.cc
+++ b/chromium/cc/layers/scrollbar_layer_unittest.cc
@@ -17,7 +17,6 @@
#include "cc/layers/scrollbar_layer_interface.h"
#include "cc/layers/solid_color_scrollbar_layer.h"
#include "cc/layers/solid_color_scrollbar_layer_impl.h"
-#include "cc/quads/solid_color_draw_quad.h"
#include "cc/resources/ui_resource_manager.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_host.h"
@@ -40,6 +39,7 @@
#include "cc/trees/scroll_node.h"
#include "cc/trees/single_thread_proxy.h"
#include "cc/trees/tree_synchronizer.h"
+#include "components/viz/common/quads/solid_color_draw_quad.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -547,13 +547,13 @@ TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) {
// Thickness should be overridden to 3.
{
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
scrollbar_layer_impl->AppendQuads(render_pass.get(), &data);
- const QuadList& quads = render_pass->quad_list;
+ const auto& quads = render_pass->quad_list;
ASSERT_EQ(1u, quads.size());
- EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material);
+ EXPECT_EQ(viz::DrawQuad::SOLID_COLOR, quads.front()->material);
EXPECT_EQ(gfx::Rect(6, 0, 39, 3), quads.front()->rect);
}
@@ -562,13 +562,13 @@ TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) {
scrollbar_layer_impl->SetClipLayerLength(25.f);
scrollbar_layer_impl->SetScrollLayerLength(125.f);
{
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
scrollbar_layer_impl->AppendQuads(render_pass.get(), &data);
- const QuadList& quads = render_pass->quad_list;
+ const auto& quads = render_pass->quad_list;
ASSERT_EQ(1u, quads.size());
- EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material);
+ EXPECT_EQ(viz::DrawQuad::SOLID_COLOR, quads.front()->material);
EXPECT_EQ(gfx::Rect(8, 0, 19, 3), quads.front()->rect);
}
@@ -577,13 +577,13 @@ TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) {
scrollbar_layer_impl->SetClipLayerLength(125.f);
scrollbar_layer_impl->SetScrollLayerLength(125.f);
{
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
scrollbar_layer_impl->AppendQuads(render_pass.get(), &data);
- const QuadList& quads = render_pass->quad_list;
+ const auto& quads = render_pass->quad_list;
ASSERT_EQ(1u, quads.size());
- EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material);
+ EXPECT_EQ(viz::DrawQuad::SOLID_COLOR, quads.front()->material);
EXPECT_EQ(gfx::Rect(1, 0, 98, 3), quads.front()->rect);
}
}
@@ -633,14 +633,14 @@ TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) {
layer_tree_host_->active_tree()->UpdateScrollbarGeometries();
{
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
scrollbar_layer_impl->AppendQuads(render_pass.get(), &data);
- const QuadList& quads = render_pass->quad_list;
+ const auto& quads = render_pass->quad_list;
ASSERT_EQ(1u, quads.size());
- EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material);
+ EXPECT_EQ(viz::DrawQuad::SOLID_COLOR, quads.front()->material);
EXPECT_EQ(gfx::Rect(3, 0, 3, 3), quads.front()->rect);
}
}
diff --git a/chromium/cc/layers/solid_color_layer.cc b/chromium/cc/layers/solid_color_layer.cc
index 3f364a5b390..aa6dfa2ebb4 100644
--- a/chromium/cc/layers/solid_color_layer.cc
+++ b/chromium/cc/layers/solid_color_layer.cc
@@ -14,7 +14,7 @@ std::unique_ptr<LayerImpl> SolidColorLayer::CreateLayerImpl(
}
scoped_refptr<SolidColorLayer> SolidColorLayer::Create() {
- return make_scoped_refptr(new SolidColorLayer());
+ return base::WrapRefCounted(new SolidColorLayer());
}
SolidColorLayer::SolidColorLayer() {}
diff --git a/chromium/cc/layers/solid_color_layer_impl.cc b/chromium/cc/layers/solid_color_layer_impl.cc
index b6f881169f2..bfdc2322a13 100644
--- a/chromium/cc/layers/solid_color_layer_impl.cc
+++ b/chromium/cc/layers/solid_color_layer_impl.cc
@@ -7,8 +7,9 @@
#include <algorithm>
#include "cc/layers/append_quads_data.h"
-#include "cc/quads/solid_color_draw_quad.h"
+#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/occlusion.h"
+#include "components/viz/common/quads/solid_color_draw_quad.h"
namespace cc {
@@ -28,11 +29,12 @@ std::unique_ptr<LayerImpl> SolidColorLayerImpl::CreateLayerImpl(
}
void SolidColorLayerImpl::AppendSolidQuads(
- RenderPass* render_pass,
+ viz::RenderPass* render_pass,
const Occlusion& occlusion_in_layer_space,
viz::SharedQuadState* shared_quad_state,
const gfx::Rect& visible_layer_rect,
SkColor color,
+ bool force_anti_aliasing_off,
AppendQuadsData* append_quads_data) {
float alpha =
(SkColorGetA(color) * (1.0f / 255.0f)) * shared_quad_state->opacity;
@@ -59,28 +61,28 @@ void SolidColorLayerImpl::AppendSolidQuads(
append_quads_data->visible_layer_area +=
visible_quad_rect.width() * visible_quad_rect.height();
- SolidColorDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- quad->SetNew(
- shared_quad_state, quad_rect, visible_quad_rect, color, false);
+ auto* quad =
+ render_pass->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
+ quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, color,
+ force_anti_aliasing_off);
}
}
}
-void SolidColorLayerImpl::AppendQuads(
- RenderPass* render_pass,
- AppendQuadsData* append_quads_data) {
+void SolidColorLayerImpl::AppendQuads(viz::RenderPass* render_pass,
+ AppendQuadsData* append_quads_data) {
viz::SharedQuadState* shared_quad_state =
render_pass->CreateAndAppendSharedQuadState();
- PopulateSharedQuadState(shared_quad_state);
+ PopulateSharedQuadState(shared_quad_state, contents_opaque());
- AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state,
+ AppendDebugBorderQuad(render_pass, gfx::Rect(bounds()), shared_quad_state,
append_quads_data);
// TODO(hendrikw): We need to pass the visible content rect rather than
// |bounds()| here.
AppendSolidQuads(render_pass, draw_properties().occlusion_in_content_space,
shared_quad_state, gfx::Rect(bounds()), background_color(),
+ !layer_tree_impl()->settings().enable_edge_anti_aliasing,
append_quads_data);
}
diff --git a/chromium/cc/layers/solid_color_layer_impl.h b/chromium/cc/layers/solid_color_layer_impl.h
index a8bbbe17383..cb2c25f7d68 100644
--- a/chromium/cc/layers/solid_color_layer_impl.h
+++ b/chromium/cc/layers/solid_color_layer_impl.h
@@ -21,18 +21,19 @@ class CC_EXPORT SolidColorLayerImpl : public LayerImpl {
return base::WrapUnique(new SolidColorLayerImpl(tree_impl, id));
}
- static void AppendSolidQuads(RenderPass* render_pass,
+ static void AppendSolidQuads(viz::RenderPass* render_pass,
const Occlusion& occlusion_in_layer_space,
viz::SharedQuadState* shared_quad_state,
const gfx::Rect& visible_layer_rect,
SkColor color,
+ bool force_anti_aliasing_off,
AppendQuadsData* append_quads_data);
~SolidColorLayerImpl() override;
// LayerImpl overrides.
std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
- void AppendQuads(RenderPass* render_pass,
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override;
protected:
diff --git a/chromium/cc/layers/solid_color_layer_impl_unittest.cc b/chromium/cc/layers/solid_color_layer_impl_unittest.cc
index 7535ce2c4af..395533bae64 100644
--- a/chromium/cc/layers/solid_color_layer_impl_unittest.cc
+++ b/chromium/cc/layers/solid_color_layer_impl_unittest.cc
@@ -11,13 +11,13 @@
#include "cc/animation/animation_host.h"
#include "cc/layers/append_quads_data.h"
#include "cc/layers/solid_color_layer.h"
-#include "cc/quads/solid_color_draw_quad.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_host.h"
#include "cc/test/layer_test_common.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/trees/layer_tree_host_common.h"
#include "cc/trees/single_thread_proxy.h"
+#include "components/viz/common/quads/solid_color_draw_quad.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -25,7 +25,7 @@ namespace cc {
namespace {
TEST(SolidColorLayerImplTest, VerifyTilingCompleteAndNoOverlap) {
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
gfx::Size layer_size = gfx::Size(800, 600);
gfx::Rect visible_layer_rect = gfx::Rect(layer_size);
@@ -53,7 +53,7 @@ TEST(SolidColorLayerImplTest, VerifyTilingCompleteAndNoOverlap) {
TEST(SolidColorLayerImplTest, VerifyCorrectBackgroundColorInQuad) {
SkColor test_color = 0xFFA55AFF;
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
gfx::Size layer_size = gfx::Size(100, 100);
gfx::Rect visible_layer_rect = gfx::Rect(layer_size);
@@ -76,14 +76,15 @@ TEST(SolidColorLayerImplTest, VerifyCorrectBackgroundColorInQuad) {
ASSERT_EQ(render_pass->quad_list.size(), 1U);
EXPECT_EQ(
- SolidColorDrawQuad::MaterialCast(render_pass->quad_list.front())->color,
+ viz::SolidColorDrawQuad::MaterialCast(render_pass->quad_list.front())
+ ->color,
test_color);
}
TEST(SolidColorLayerImplTest, VerifyCorrectOpacityInQuad) {
const float opacity = 0.5f;
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
gfx::Size layer_size = gfx::Size(100, 100);
gfx::Rect visible_layer_rect = gfx::Rect(layer_size);
@@ -105,16 +106,16 @@ TEST(SolidColorLayerImplTest, VerifyCorrectOpacityInQuad) {
render_pass.get(), &data);
ASSERT_EQ(render_pass->quad_list.size(), 1U);
- EXPECT_EQ(opacity,
- SolidColorDrawQuad::MaterialCast(render_pass->quad_list.front())
- ->shared_quad_state->opacity);
+ EXPECT_EQ(opacity, viz::SolidColorDrawQuad::MaterialCast(
+ render_pass->quad_list.front())
+ ->shared_quad_state->opacity);
EXPECT_TRUE(render_pass->quad_list.front()->ShouldDrawWithBlending());
}
TEST(SolidColorLayerImplTest, VerifyEliminateTransparentAlpha) {
SkColor test_color = 0;
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
gfx::Size layer_size = gfx::Size(100, 100);
gfx::Rect visible_layer_rect = gfx::Rect(layer_size);
@@ -141,7 +142,7 @@ TEST(SolidColorLayerImplTest, VerifyEliminateTransparentAlpha) {
TEST(SolidColorLayerImplTest, VerifyEliminateTransparentOpacity) {
SkColor test_color = 0xFFA55AFF;
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
gfx::Size layer_size = gfx::Size(100, 100);
gfx::Rect visible_layer_rect = gfx::Rect(layer_size);
@@ -202,13 +203,15 @@ TEST(SolidColorLayerImplTest, VerifyNeedsBlending) {
// should be the false.
layer_impl->draw_properties().opacity = 1;
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
layer_impl->AppendQuads(render_pass.get(), &data);
ASSERT_EQ(render_pass->quad_list.size(), 1U);
EXPECT_FALSE(render_pass->quad_list.front()->needs_blending);
+ EXPECT_TRUE(
+ render_pass->quad_list.front()->shared_quad_state->are_contents_opaque);
}
EXPECT_TRUE(layer->contents_opaque());
@@ -227,13 +230,15 @@ TEST(SolidColorLayerImplTest, VerifyNeedsBlending) {
// needs_blending should be true.
layer_impl->draw_properties().opacity = 1;
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
layer_impl->AppendQuads(render_pass.get(), &data);
ASSERT_EQ(render_pass->quad_list.size(), 1U);
EXPECT_TRUE(render_pass->quad_list.front()->needs_blending);
+ EXPECT_FALSE(
+ render_pass->quad_list.front()->shared_quad_state->are_contents_opaque);
}
}
diff --git a/chromium/cc/layers/solid_color_scrollbar_layer.cc b/chromium/cc/layers/solid_color_scrollbar_layer.cc
index 3393a5b0c66..baf582dbc13 100644
--- a/chromium/cc/layers/solid_color_scrollbar_layer.cc
+++ b/chromium/cc/layers/solid_color_scrollbar_layer.cc
@@ -28,7 +28,7 @@ scoped_refptr<SolidColorScrollbarLayer> SolidColorScrollbarLayer::Create(
int track_start,
bool is_left_side_vertical_scrollbar,
ElementId scroll_element_id) {
- return make_scoped_refptr(new SolidColorScrollbarLayer(
+ return base::WrapRefCounted(new SolidColorScrollbarLayer(
orientation, thumb_thickness, track_start,
is_left_side_vertical_scrollbar, scroll_element_id));
}
diff --git a/chromium/cc/layers/solid_color_scrollbar_layer_impl.cc b/chromium/cc/layers/solid_color_scrollbar_layer_impl.cc
index 3ff4e32771a..2ab831c59dd 100644
--- a/chromium/cc/layers/solid_color_scrollbar_layer_impl.cc
+++ b/chromium/cc/layers/solid_color_scrollbar_layer_impl.cc
@@ -5,10 +5,10 @@
#include "cc/layers/solid_color_scrollbar_layer_impl.h"
#include "base/memory/ptr_util.h"
-#include "cc/quads/solid_color_draw_quad.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/layer_tree_settings.h"
#include "cc/trees/occlusion.h"
+#include "components/viz/common/quads/solid_color_draw_quad.h"
namespace cc {
@@ -25,7 +25,7 @@ SolidColorScrollbarLayerImpl::Create(LayerTreeImpl* tree_impl,
is_left_side_vertical_scrollbar, is_overlay));
}
-SolidColorScrollbarLayerImpl::~SolidColorScrollbarLayerImpl() {}
+SolidColorScrollbarLayerImpl::~SolidColorScrollbarLayerImpl() = default;
std::unique_ptr<LayerImpl> SolidColorScrollbarLayerImpl::CreateLayerImpl(
LayerTreeImpl* tree_impl) {
@@ -92,13 +92,13 @@ bool SolidColorScrollbarLayerImpl::IsThumbResizable() const {
}
void SolidColorScrollbarLayerImpl::AppendQuads(
- RenderPass* render_pass,
+ viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) {
viz::SharedQuadState* shared_quad_state =
render_pass->CreateAndAppendSharedQuadState();
- PopulateSharedQuadState(shared_quad_state);
+ PopulateSharedQuadState(shared_quad_state, contents_opaque());
- AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state,
+ AppendDebugBorderQuad(render_pass, gfx::Rect(bounds()), shared_quad_state,
append_quads_data);
gfx::Rect thumb_quad_rect(ComputeThumbQuadRect());
@@ -108,8 +108,7 @@ void SolidColorScrollbarLayerImpl::AppendQuads(
if (visible_quad_rect.IsEmpty())
return;
- SolidColorDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ auto* quad = render_pass->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
quad->SetNew(
shared_quad_state, thumb_quad_rect, visible_quad_rect, color_, false);
}
diff --git a/chromium/cc/layers/solid_color_scrollbar_layer_impl.h b/chromium/cc/layers/solid_color_scrollbar_layer_impl.h
index 1306391baa6..710b4d603b0 100644
--- a/chromium/cc/layers/solid_color_scrollbar_layer_impl.h
+++ b/chromium/cc/layers/solid_color_scrollbar_layer_impl.h
@@ -26,7 +26,7 @@ class CC_EXPORT SolidColorScrollbarLayerImpl : public ScrollbarLayerImplBase {
std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
void PushPropertiesTo(LayerImpl* layer) override;
- void AppendQuads(RenderPass* render_pass,
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override;
int ThumbThickness() const override;
diff --git a/chromium/cc/layers/surface_layer.cc b/chromium/cc/layers/surface_layer.cc
index ade8f040b89..75ac5b150d2 100644
--- a/chromium/cc/layers/surface_layer.cc
+++ b/chromium/cc/layers/surface_layer.cc
@@ -11,8 +11,8 @@
#include "base/single_thread_task_runner.h"
#include "base/trace_event/trace_event.h"
#include "cc/layers/surface_layer_impl.h"
-#include "cc/output/swap_promise.h"
#include "cc/trees/layer_tree_host.h"
+#include "cc/trees/swap_promise.h"
#include "cc/trees/swap_promise_manager.h"
#include "cc/trees/task_runner_provider.h"
#include "components/viz/common/surfaces/surface_sequence_generator.h"
@@ -32,7 +32,7 @@ class SatisfySwapPromise : public SwapPromise {
private:
void DidActivate() override {}
- void WillSwap(CompositorFrameMetadata* metadata) override {}
+ void WillSwap(viz::CompositorFrameMetadata* metadata) override {}
void DidSwap() override {
main_task_runner_->PostTask(FROM_HERE, reference_returner_);
@@ -53,7 +53,7 @@ class SatisfySwapPromise : public SwapPromise {
scoped_refptr<SurfaceLayer> SurfaceLayer::Create(
scoped_refptr<viz::SurfaceReferenceFactory> ref_factory) {
- return make_scoped_refptr(new SurfaceLayer(std::move(ref_factory)));
+ return base::WrapRefCounted(new SurfaceLayer(std::move(ref_factory)));
}
SurfaceLayer::SurfaceLayer(
@@ -86,6 +86,11 @@ void SurfaceLayer::SetFallbackSurfaceInfo(
SetNeedsCommit();
}
+void SurfaceLayer::SetDefaultBackgroundColor(SkColor background_color) {
+ default_background_color_ = background_color;
+ SetNeedsPushProperties();
+}
+
void SurfaceLayer::SetStretchContentToFillBounds(
bool stretch_content_to_fill_bounds) {
stretch_content_to_fill_bounds_ = stretch_content_to_fill_bounds;
@@ -126,6 +131,7 @@ void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) {
layer_impl->SetPrimarySurfaceInfo(primary_surface_info_);
layer_impl->SetFallbackSurfaceInfo(fallback_surface_info_);
layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_);
+ layer_impl->SetDefaultBackgroundColor(default_background_color_);
}
void SurfaceLayer::RemoveReference(base::Closure reference_returner) {
diff --git a/chromium/cc/layers/surface_layer.h b/chromium/cc/layers/surface_layer.h
index e43fcb34c2e..9f86edf33eb 100644
--- a/chromium/cc/layers/surface_layer.h
+++ b/chromium/cc/layers/surface_layer.h
@@ -10,6 +10,7 @@
#include "cc/layers/layer.h"
#include "components/viz/common/surfaces/surface_info.h"
#include "components/viz/common/surfaces/surface_reference_factory.h"
+#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/size.h"
namespace cc {
@@ -28,6 +29,10 @@ class CC_EXPORT SurfaceLayer : public Layer {
// surface is ignored and the content will be stretched to fill the bounds.
void SetStretchContentToFillBounds(bool stretch_content_to_fill_bounds);
+ // Specifies the |background_color| to use when a primary surface is
+ // specified, and a fallback surface is unavailable.
+ void SetDefaultBackgroundColor(SkColor background_color);
+
// Layer overrides.
std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
void SetLayerTreeHost(LayerTreeHost* host) override;
@@ -61,6 +66,7 @@ class CC_EXPORT SurfaceLayer : public Layer {
scoped_refptr<viz::SurfaceReferenceFactory> ref_factory_;
bool stretch_content_to_fill_bounds_ = false;
+ SkColor default_background_color_ = SK_ColorWHITE;
DISALLOW_COPY_AND_ASSIGN(SurfaceLayer);
};
diff --git a/chromium/cc/layers/surface_layer_impl.cc b/chromium/cc/layers/surface_layer_impl.cc
index 315fdf64f41..87b4bb47b42 100644
--- a/chromium/cc/layers/surface_layer_impl.cc
+++ b/chromium/cc/layers/surface_layer_impl.cc
@@ -9,10 +9,10 @@
#include "base/trace_event/trace_event_argument.h"
#include "cc/debug/debug_colors.h"
#include "cc/layers/append_quads_data.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/surface_draw_quad.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/occlusion.h"
+#include "components/viz/common/quads/solid_color_draw_quad.h"
+#include "components/viz/common/quads/surface_draw_quad.h"
namespace cc {
@@ -52,15 +52,24 @@ void SurfaceLayerImpl::SetStretchContentToFillBounds(bool stretch_content) {
NoteLayerPropertyChanged();
}
+void SurfaceLayerImpl::SetDefaultBackgroundColor(SkColor background_color) {
+ if (default_background_color_ == background_color)
+ return;
+
+ default_background_color_ = background_color;
+ NoteLayerPropertyChanged();
+}
+
void SurfaceLayerImpl::PushPropertiesTo(LayerImpl* layer) {
LayerImpl::PushPropertiesTo(layer);
SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer);
layer_impl->SetPrimarySurfaceInfo(primary_surface_info_);
layer_impl->SetFallbackSurfaceInfo(fallback_surface_info_);
layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_);
+ layer_impl->SetDefaultBackgroundColor(default_background_color_);
}
-void SurfaceLayerImpl::AppendQuads(RenderPass* render_pass,
+void SurfaceLayerImpl::AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) {
AppendRainbowDebugBorder(render_pass);
if (!primary_surface_info_.is_valid())
@@ -68,31 +77,32 @@ void SurfaceLayerImpl::AppendQuads(RenderPass* render_pass,
viz::SharedQuadState* common_shared_quad_state = nullptr;
auto* primary =
- CreateSurfaceDrawQuad(render_pass, SurfaceDrawQuadType::PRIMARY,
+ CreateSurfaceDrawQuad(render_pass, viz::SurfaceDrawQuadType::PRIMARY,
primary_surface_info_, &common_shared_quad_state);
- // Emitting a fallback SurfaceDrawQuad is unnecessary if the primary and
+ // Emitting a fallback viz::SurfaceDrawQuad is unnecessary if the primary and
// fallback surface Ids match.
if (primary && fallback_surface_info_.id() != primary_surface_info_.id()) {
// Add the primary surface ID as a dependency.
append_quads_data->activation_dependencies.push_back(
primary_surface_info_.id());
if (fallback_surface_info_.is_valid()) {
- // We can use the same SharedQuadState as the primary SurfaceDrawQuad if
- // we don't need a different transform on the fallback.
+ // We can use the same SharedQuadState as the primary viz::SurfaceDrawQuad
+ // if we don't need a different transform on the fallback.
bool use_common_shared_quad_state =
!stretch_content_to_fill_bounds_ &&
primary_surface_info_.device_scale_factor() ==
fallback_surface_info_.device_scale_factor();
primary->fallback_quad = CreateSurfaceDrawQuad(
- render_pass, SurfaceDrawQuadType::FALLBACK, fallback_surface_info_,
+ render_pass, viz::SurfaceDrawQuadType::FALLBACK,
+ fallback_surface_info_,
use_common_shared_quad_state ? &common_shared_quad_state : nullptr);
}
}
}
-SurfaceDrawQuad* SurfaceLayerImpl::CreateSurfaceDrawQuad(
- RenderPass* render_pass,
- SurfaceDrawQuadType surface_draw_quad_type,
+viz::SurfaceDrawQuad* SurfaceLayerImpl::CreateSurfaceDrawQuad(
+ viz::RenderPass* render_pass,
+ viz::SurfaceDrawQuadType surface_draw_quad_type,
const viz::SurfaceInfo& surface_info,
viz::SharedQuadState** common_shared_quad_state) {
DCHECK(surface_info.is_valid());
@@ -127,21 +137,22 @@ SurfaceDrawQuad* SurfaceLayerImpl::CreateSurfaceDrawQuad(
// If a |common_shared_quad_state| is provided then use that. Otherwise,
// allocate a new SharedQuadState. Assign the new SharedQuadState to
// *|common_shared_quad_state| so that it may be reused by another emitted
- // SurfaceDrawQuad.
+ // viz::SurfaceDrawQuad.
viz::SharedQuadState* shared_quad_state =
common_shared_quad_state ? *common_shared_quad_state : nullptr;
if (!shared_quad_state) {
shared_quad_state = render_pass->CreateAndAppendSharedQuadState();
PopulateScaledSharedQuadState(shared_quad_state, layer_to_content_scale_x,
- layer_to_content_scale_y);
+ layer_to_content_scale_y, contents_opaque());
}
if (common_shared_quad_state)
*common_shared_quad_state = shared_quad_state;
- SurfaceDrawQuad* surface_draw_quad =
- render_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
+ auto* surface_draw_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::SurfaceDrawQuad>();
surface_draw_quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect,
- surface_info.id(), surface_draw_quad_type, nullptr);
+ surface_info.id(), surface_draw_quad_type,
+ default_background_color_, nullptr);
return surface_draw_quad;
}
@@ -153,13 +164,13 @@ void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color,
layer_tree_impl() ? layer_tree_impl()->device_scale_factor() : 1);
}
-void SurfaceLayerImpl::AppendRainbowDebugBorder(RenderPass* render_pass) {
+void SurfaceLayerImpl::AppendRainbowDebugBorder(viz::RenderPass* render_pass) {
if (!ShowDebugBorders(DebugBorderType::SURFACE))
return;
viz::SharedQuadState* shared_quad_state =
render_pass->CreateAndAppendSharedQuadState();
- PopulateSharedQuadState(shared_quad_state);
+ PopulateSharedQuadState(shared_quad_state, contents_opaque());
SkColor color;
float border_width;
@@ -197,13 +208,13 @@ void SurfaceLayerImpl::AppendRainbowDebugBorder(RenderPass* render_pass) {
if (!top.IsEmpty()) {
bool force_anti_aliasing_off = false;
- SolidColorDrawQuad* top_quad =
- render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ auto* top_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
top_quad->SetNew(shared_quad_state, top, top, colors[i % kNumColors],
force_anti_aliasing_off);
- SolidColorDrawQuad* bottom_quad =
- render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ auto* bottom_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
bottom_quad->SetNew(shared_quad_state, bottom, bottom,
colors[kNumColors - 1 - (i % kNumColors)],
force_anti_aliasing_off);
@@ -211,8 +222,8 @@ void SurfaceLayerImpl::AppendRainbowDebugBorder(RenderPass* render_pass) {
if (contents_opaque()) {
// Draws a stripe filling the layer vertically with the same color and
// width as the horizontal stipes along the layer's top border.
- SolidColorDrawQuad* solid_quad =
- render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ auto* solid_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
// The inner fill is more transparent then the border.
static const float kFillOpacity = 0.1f;
SkColor fill_color = SkColorSetA(
@@ -226,14 +237,14 @@ void SurfaceLayerImpl::AppendRainbowDebugBorder(RenderPass* render_pass) {
}
if (!left.IsEmpty()) {
bool force_anti_aliasing_off = false;
- SolidColorDrawQuad* left_quad =
- render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ auto* left_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
left_quad->SetNew(shared_quad_state, left, left,
colors[kNumColors - 1 - (i % kNumColors)],
force_anti_aliasing_off);
- SolidColorDrawQuad* right_quad =
- render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ auto* right_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
right_quad->SetNew(shared_quad_state, right, right,
colors[i % kNumColors], force_anti_aliasing_off);
}
diff --git a/chromium/cc/layers/surface_layer_impl.h b/chromium/cc/layers/surface_layer_impl.h
index 1d97ea7631a..84e128033b9 100644
--- a/chromium/cc/layers/surface_layer_impl.h
+++ b/chromium/cc/layers/surface_layer_impl.h
@@ -11,7 +11,7 @@
#include "base/memory/ptr_util.h"
#include "cc/cc_export.h"
#include "cc/layers/layer_impl.h"
-#include "cc/quads/surface_draw_quad.h"
+#include "components/viz/common/quads/surface_draw_quad.h"
#include "components/viz/common/surfaces/surface_id.h"
#include "components/viz/common/surfaces/surface_info.h"
@@ -34,32 +34,38 @@ class CC_EXPORT SurfaceLayerImpl : public LayerImpl {
// display compositor. If surface synchronization is enabled, the display
// compositor will use the fallback if the primary surface is unavailable
// at the time of surface aggregation. If surface synchronization is not
- // enabled, then a fallback surface will not be specified.
+ // enabled, then the primary and fallback surfaces will always match.
void SetFallbackSurfaceInfo(const viz::SurfaceInfo& surface_info);
const viz::SurfaceInfo& fallback_surface_info() const {
return fallback_surface_info_;
}
void SetStretchContentToFillBounds(bool stretch_content);
+ bool stretch_content_to_fill_bounds() const {
+ return stretch_content_to_fill_bounds_;
+ }
+
+ void SetDefaultBackgroundColor(SkColor background_color);
+ SkColor default_background_color() const { return default_background_color_; }
// LayerImpl overrides.
std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
void PushPropertiesTo(LayerImpl* layer) override;
- void AppendQuads(RenderPass* render_pass,
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override;
protected:
SurfaceLayerImpl(LayerTreeImpl* tree_impl, int id);
private:
- SurfaceDrawQuad* CreateSurfaceDrawQuad(
- RenderPass* render_pass,
- SurfaceDrawQuadType surface_draw_quad_type,
+ viz::SurfaceDrawQuad* CreateSurfaceDrawQuad(
+ viz::RenderPass* render_pass,
+ viz::SurfaceDrawQuadType surface_draw_quad_type,
const viz::SurfaceInfo& surface_info,
viz::SharedQuadState** common_shared_quad_state);
void GetDebugBorderProperties(SkColor* color, float* width) const override;
- void AppendRainbowDebugBorder(RenderPass* render_pass);
+ void AppendRainbowDebugBorder(viz::RenderPass* render_pass);
void AsValueInto(base::trace_event::TracedValue* dict) const override;
const char* LayerTypeAsString() const override;
@@ -67,6 +73,7 @@ class CC_EXPORT SurfaceLayerImpl : public LayerImpl {
viz::SurfaceInfo fallback_surface_info_;
bool stretch_content_to_fill_bounds_ = false;
+ SkColor default_background_color_ = SK_ColorWHITE;
DISALLOW_COPY_AND_ASSIGN(SurfaceLayerImpl);
};
diff --git a/chromium/cc/layers/surface_layer_impl_unittest.cc b/chromium/cc/layers/surface_layer_impl_unittest.cc
index 654d7a53d36..decd35469cc 100644
--- a/chromium/cc/layers/surface_layer_impl_unittest.cc
+++ b/chromium/cc/layers/surface_layer_impl_unittest.cc
@@ -173,12 +173,12 @@ TEST(SurfaceLayerImplTest, SurfaceStretchedToLayerBounds) {
impl.CalcDrawProps(viewport_size);
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
surface_layer_impl->AppendQuads(render_pass.get(), &data);
EXPECT_THAT(data.activation_dependencies, UnorderedElementsAre(surface_id));
- const QuadList& quads = render_pass->quad_list;
+ const auto& quads = render_pass->quad_list;
ASSERT_EQ(2u, quads.size());
const viz::SharedQuadState* shared_quad_state =
quads.front()->shared_quad_state;
@@ -208,7 +208,7 @@ TEST(SurfaceLayerImplTest, SurfaceStretchedToLayerBounds) {
EXPECT_EQ(transformed_quad_rect, transformed_layer_rect);
}
-// This test verifies that two SurfaceDrawQuads are emitted if a
+// This test verifies that two viz::SurfaceDrawQuads are emitted if a
// SurfaceLayerImpl holds both a primary and fallback viz::SurfaceInfo.
TEST(SurfaceLayerImplTest, SurfaceLayerImplEmitsTwoDrawQuadsIfUniqueFallback) {
LayerTestCommon::LayerImplTest impl;
@@ -243,11 +243,12 @@ TEST(SurfaceLayerImplTest, SurfaceLayerImplEmitsTwoDrawQuadsIfUniqueFallback) {
surface_layer_impl->SetDrawsContent(true);
surface_layer_impl->SetPrimarySurfaceInfo(primary_surface_info);
surface_layer_impl->SetFallbackSurfaceInfo(fallback_surface_info);
+ surface_layer_impl->SetDefaultBackgroundColor(SK_ColorBLUE);
gfx::Size viewport_size(1000, 1000);
impl.CalcDrawProps(viewport_size);
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
{
AppendQuadsData data;
surface_layer_impl->AppendQuads(render_pass.get(), &data);
@@ -282,57 +283,62 @@ TEST(SurfaceLayerImplTest, SurfaceLayerImplEmitsTwoDrawQuadsIfUniqueFallback) {
}
ASSERT_EQ(5u, render_pass->quad_list.size());
- const SurfaceDrawQuad* surface_draw_quad1 =
- SurfaceDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(0));
+ const viz::SurfaceDrawQuad* surface_draw_quad1 =
+ viz::SurfaceDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(0));
ASSERT_TRUE(surface_draw_quad1);
- const SurfaceDrawQuad* surface_draw_quad2 =
- SurfaceDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(1));
+ const viz::SurfaceDrawQuad* surface_draw_quad2 =
+ viz::SurfaceDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(1));
ASSERT_TRUE(surface_draw_quad2);
- const SurfaceDrawQuad* surface_draw_quad3 =
- SurfaceDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(2));
+ const viz::SurfaceDrawQuad* surface_draw_quad3 =
+ viz::SurfaceDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(2));
ASSERT_TRUE(surface_draw_quad3);
- const SurfaceDrawQuad* surface_draw_quad4 =
- SurfaceDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(3));
+ const viz::SurfaceDrawQuad* surface_draw_quad4 =
+ viz::SurfaceDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(3));
ASSERT_TRUE(surface_draw_quad4);
- const SurfaceDrawQuad* surface_draw_quad5 =
- SurfaceDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(4));
+ const viz::SurfaceDrawQuad* surface_draw_quad5 =
+ viz::SurfaceDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(4));
ASSERT_TRUE(surface_draw_quad5);
- EXPECT_EQ(SurfaceDrawQuadType::PRIMARY,
+ EXPECT_EQ(viz::SurfaceDrawQuadType::PRIMARY,
surface_draw_quad1->surface_draw_quad_type);
EXPECT_EQ(surface_id1, surface_draw_quad1->surface_id);
EXPECT_EQ(surface_draw_quad2, surface_draw_quad1->fallback_quad);
- EXPECT_EQ(SurfaceDrawQuadType::FALLBACK,
+ EXPECT_EQ(SK_ColorBLUE, surface_draw_quad1->default_background_color);
+ EXPECT_EQ(viz::SurfaceDrawQuadType::FALLBACK,
surface_draw_quad2->surface_draw_quad_type);
EXPECT_EQ(surface_id2, surface_draw_quad2->surface_id);
+ EXPECT_EQ(SK_ColorBLUE, surface_draw_quad2->default_background_color);
// If the device scale factor of the primary and fallback are different then
// they do not share a SharedQuadState.
EXPECT_NE(surface_draw_quad1->shared_quad_state,
surface_draw_quad2->shared_quad_state);
- EXPECT_EQ(SurfaceDrawQuadType::PRIMARY,
+ EXPECT_EQ(viz::SurfaceDrawQuadType::PRIMARY,
surface_draw_quad3->surface_draw_quad_type);
EXPECT_EQ(surface_id1, surface_draw_quad3->surface_id);
EXPECT_EQ(nullptr, surface_draw_quad3->fallback_quad);
+ EXPECT_EQ(SK_ColorBLUE, surface_draw_quad3->default_background_color);
- EXPECT_EQ(SurfaceDrawQuadType::PRIMARY,
+ EXPECT_EQ(viz::SurfaceDrawQuadType::PRIMARY,
surface_draw_quad4->surface_draw_quad_type);
EXPECT_EQ(surface_id1, surface_draw_quad4->surface_id);
+ EXPECT_EQ(SK_ColorBLUE, surface_draw_quad4->default_background_color);
EXPECT_EQ(surface_draw_quad5, surface_draw_quad4->fallback_quad);
- EXPECT_EQ(SurfaceDrawQuadType::FALLBACK,
+ EXPECT_EQ(viz::SurfaceDrawQuadType::FALLBACK,
surface_draw_quad5->surface_draw_quad_type);
EXPECT_EQ(surface_id2, surface_draw_quad5->surface_id);
+ EXPECT_EQ(SK_ColorBLUE, surface_draw_quad5->default_background_color);
// If the device scale factor of the primary and fallback are the same then
// they share a SharedQuadState.
EXPECT_EQ(surface_draw_quad4->shared_quad_state,
surface_draw_quad5->shared_quad_state);
}
-// This test verifies that one SurfaceDrawQuad is emitted if a
+// This test verifies that one viz::SurfaceDrawQuad is emitted if a
// SurfaceLayerImpl holds the same surface ID for both the primary
// and fallback viz::SurfaceInfo.
TEST(SurfaceLayerImplTest,
- SurfaceLayerImplEmitsOneDrawQuadsIfPrimaryMatchesFallback) {
+ SurfaceLayerImplEmitsOneDrawQuadIfPrimaryMatchesFallback) {
LayerTestCommon::LayerImplTest impl;
SurfaceLayerImpl* surface_layer_impl =
impl.AddChildToRoot<SurfaceLayerImpl>();
@@ -354,11 +360,12 @@ TEST(SurfaceLayerImplTest,
surface_layer_impl->SetDrawsContent(true);
surface_layer_impl->SetPrimarySurfaceInfo(primary_surface_info);
surface_layer_impl->SetFallbackSurfaceInfo(primary_surface_info);
+ surface_layer_impl->SetDefaultBackgroundColor(SK_ColorBLUE);
gfx::Size viewport_size(1000, 1000);
impl.CalcDrawProps(viewport_size);
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
surface_layer_impl->AppendQuads(render_pass.get(), &data);
// As the primary and fallback SurfaceInfos match, there is no reason to
@@ -368,13 +375,14 @@ TEST(SurfaceLayerImplTest,
EXPECT_THAT(data.activation_dependencies, testing::IsEmpty());
ASSERT_EQ(1u, render_pass->quad_list.size());
- const SurfaceDrawQuad* surface_draw_quad1 =
- SurfaceDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(0));
+ const viz::SurfaceDrawQuad* surface_draw_quad1 =
+ viz::SurfaceDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(0));
ASSERT_TRUE(surface_draw_quad1);
- EXPECT_EQ(SurfaceDrawQuadType::PRIMARY,
+ EXPECT_EQ(viz::SurfaceDrawQuadType::PRIMARY,
surface_draw_quad1->surface_draw_quad_type);
EXPECT_EQ(surface_id1, surface_draw_quad1->surface_id);
+ EXPECT_EQ(SK_ColorBLUE, surface_draw_quad1->default_background_color);
EXPECT_FALSE(surface_draw_quad1->fallback_quad);
}
diff --git a/chromium/cc/layers/surface_layer_unittest.cc b/chromium/cc/layers/surface_layer_unittest.cc
index f5fa3bb95ad..7c40a809a3a 100644
--- a/chromium/cc/layers/surface_layer_unittest.cc
+++ b/chromium/cc/layers/surface_layer_unittest.cc
@@ -15,7 +15,6 @@
#include "cc/layers/solid_color_layer.h"
#include "cc/layers/surface_layer.h"
#include "cc/layers/surface_layer_impl.h"
-#include "cc/output/compositor_frame.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_host.h"
#include "cc/test/fake_layer_tree_host_client.h"
@@ -24,6 +23,7 @@
#include "cc/test/layer_tree_test.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/trees/layer_tree_host.h"
+#include "components/viz/common/quads/compositor_frame.h"
#include "components/viz/common/surfaces/sequence_surface_reference_factory.h"
#include "components/viz/common/surfaces/surface_info.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -157,9 +157,9 @@ TEST_F(SurfaceLayerTest, MultipleFramesOneSurface) {
testing::Mock::VerifyAndClearExpectations(ref_factory.get());
}
-// This test verifies that the primary and fallback viz::SurfaceInfo are pushed
-// across from SurfaceLayer to SurfaceLayerImpl.
-TEST_F(SurfaceLayerTest, SurfaceInfoPushProperties) {
+// This test verifies that SurfaceLayer properties are pushed across to
+// SurfaceLayerImpl.
+TEST_F(SurfaceLayerTest, PushProperties) {
// We use a nice mock here because we are not really interested in calls to
// MockSurfaceReferenceFactory and we don't want warnings printed.
scoped_refptr<viz::SurfaceReferenceFactory> ref_factory =
@@ -173,6 +173,8 @@ TEST_F(SurfaceLayerTest, SurfaceInfoPushProperties) {
1.f, gfx::Size(1, 1));
layer->SetPrimarySurfaceInfo(primary_info);
layer->SetFallbackSurfaceInfo(primary_info);
+ layer->SetDefaultBackgroundColor(SK_ColorBLUE);
+ layer->SetStretchContentToFillBounds(true);
EXPECT_TRUE(layer_tree_host_->needs_surface_ids_sync());
EXPECT_EQ(layer_tree_host_->SurfaceLayerIds().size(), 1u);
@@ -196,12 +198,16 @@ TEST_F(SurfaceLayerTest, SurfaceInfoPushProperties) {
// Verify that the primary and fallback SurfaceInfos are pushed through.
EXPECT_EQ(primary_info, layer_impl->primary_surface_info());
EXPECT_EQ(primary_info, layer_impl->fallback_surface_info());
+ EXPECT_EQ(SK_ColorBLUE, layer_impl->default_background_color());
+ EXPECT_TRUE(layer_impl->stretch_content_to_fill_bounds());
viz::SurfaceInfo fallback_info(
viz::SurfaceId(kArbitraryFrameSinkId,
viz::LocalSurfaceId(2, base::UnguessableToken::Create())),
2.f, gfx::Size(10, 10));
layer->SetFallbackSurfaceInfo(fallback_info);
+ layer->SetDefaultBackgroundColor(SK_ColorGREEN);
+ layer->SetStretchContentToFillBounds(false);
// Verify that fallback surface id is not recorded on the layer tree host as
// surface synchronization is not enabled.
@@ -216,6 +222,8 @@ TEST_F(SurfaceLayerTest, SurfaceInfoPushProperties) {
// fallback viz::SurfaceInfo is pushed through.
EXPECT_EQ(primary_info, layer_impl->primary_surface_info());
EXPECT_EQ(fallback_info, layer_impl->fallback_surface_info());
+ EXPECT_EQ(SK_ColorGREEN, layer_impl->default_background_color());
+ EXPECT_FALSE(layer_impl->stretch_content_to_fill_bounds());
}
// This test verifies the list of surface ids is correct when there are cloned
diff --git a/chromium/cc/layers/texture_layer.cc b/chromium/cc/layers/texture_layer.cc
index df6e6c1189b..403b781e49a 100644
--- a/chromium/cc/layers/texture_layer.cc
+++ b/chromium/cc/layers/texture_layer.cc
@@ -13,10 +13,8 @@
#include "cc/base/simple_enclosed_region.h"
#include "cc/layers/texture_layer_client.h"
#include "cc/layers/texture_layer_impl.h"
-#include "cc/resources/single_release_callback_impl.h"
-#include "cc/trees/blocking_task_runner.h"
#include "cc/trees/layer_tree_host.h"
-#include "components/viz/common/quads/single_release_callback.h"
+#include "components/viz/common/resources/single_release_callback.h"
namespace cc {
@@ -25,23 +23,9 @@ scoped_refptr<TextureLayer> TextureLayer::CreateForMailbox(
return scoped_refptr<TextureLayer>(new TextureLayer(client));
}
-TextureLayer::TextureLayer(TextureLayerClient* client)
- : client_(client),
- flipped_(true),
- nearest_neighbor_(false),
- uv_top_left_(0.f, 0.f),
- uv_bottom_right_(1.f, 1.f),
- premultiplied_alpha_(true),
- blend_background_color_(false),
- needs_set_mailbox_(false) {
- vertex_opacity_[0] = 1.0f;
- vertex_opacity_[1] = 1.0f;
- vertex_opacity_[2] = 1.0f;
- vertex_opacity_[3] = 1.0f;
-}
+TextureLayer::TextureLayer(TextureLayerClient* client) : client_(client) {}
-TextureLayer::~TextureLayer() {
-}
+TextureLayer::~TextureLayer() = default;
void TextureLayer::ClearClient() {
client_ = nullptr;
@@ -219,14 +203,15 @@ void TextureLayer::PushPropertiesTo(LayerImpl* layer) {
texture_layer->SetBlendBackgroundColor(blend_background_color_);
if (needs_set_mailbox_) {
viz::TextureMailbox texture_mailbox;
- std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl;
+ std::unique_ptr<viz::SingleReleaseCallback> release_callback;
if (holder_ref_) {
TextureMailboxHolder* holder = holder_ref_->holder();
texture_mailbox = holder->mailbox();
- release_callback_impl = holder->GetCallbackForImplThread();
+ release_callback = holder->GetCallbackForImplThread(
+ layer_tree_host()->GetTaskRunnerProvider()->MainThreadTaskRunner());
}
texture_layer->SetTextureMailbox(texture_mailbox,
- std::move(release_callback_impl));
+ std::move(release_callback));
needs_set_mailbox_ = false;
}
}
@@ -271,14 +256,16 @@ void TextureLayer::TextureMailboxHolder::Return(
is_lost_ = is_lost;
}
-std::unique_ptr<SingleReleaseCallbackImpl>
-TextureLayer::TextureMailboxHolder::GetCallbackForImplThread() {
+std::unique_ptr<viz::SingleReleaseCallback>
+TextureLayer::TextureMailboxHolder::GetCallbackForImplThread(
+ scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner) {
// We can't call GetCallbackForImplThread if we released the main thread
// reference.
DCHECK_GT(internal_references_, 0u);
InternalAddRef();
- return SingleReleaseCallbackImpl::Create(
- base::Bind(&TextureMailboxHolder::ReturnAndReleaseOnImplThread, this));
+ return viz::SingleReleaseCallback::Create(
+ base::Bind(&TextureMailboxHolder::ReturnAndReleaseOnImplThread, this,
+ std::move(main_thread_task_runner)));
}
void TextureLayer::TextureMailboxHolder::InternalAddRef() {
@@ -295,9 +282,9 @@ void TextureLayer::TextureMailboxHolder::InternalRelease() {
}
void TextureLayer::TextureMailboxHolder::ReturnAndReleaseOnImplThread(
+ const scoped_refptr<base::SequencedTaskRunner>& main_thread_task_runner,
const gpu::SyncToken& sync_token,
- bool is_lost,
- BlockingTaskRunner* main_thread_task_runner) {
+ bool is_lost) {
Return(sync_token, is_lost);
main_thread_task_runner->PostTask(
FROM_HERE, base::Bind(&TextureMailboxHolder::InternalRelease, this));
diff --git a/chromium/cc/layers/texture_layer.h b/chromium/cc/layers/texture_layer.h
index c13f47b6c25..0b3cc407df6 100644
--- a/chromium/cc/layers/texture_layer.h
+++ b/chromium/cc/layers/texture_layer.h
@@ -24,8 +24,7 @@ class SingleReleaseCallback;
}
namespace cc {
-class BlockingTaskRunner;
-class SingleReleaseCallbackImpl;
+class SingleReleaseCallback;
class TextureLayerClient;
// A Layer containing a the rendered output of a plugin instance.
@@ -50,7 +49,8 @@ class CC_EXPORT TextureLayer : public Layer {
// Gets a viz::ReleaseCallback that can be called from another thread. Note:
// the caller must ensure the callback is called.
- std::unique_ptr<SingleReleaseCallbackImpl> GetCallbackForImplThread();
+ std::unique_ptr<viz::SingleReleaseCallback> GetCallbackForImplThread(
+ scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner);
protected:
friend class TextureLayer;
@@ -71,9 +71,9 @@ class CC_EXPORT TextureLayer : public Layer {
void InternalAddRef();
void InternalRelease();
void ReturnAndReleaseOnImplThread(
+ const scoped_refptr<base::SequencedTaskRunner>& main_thread_task_runner,
const gpu::SyncToken& sync_token,
- bool is_lost,
- BlockingTaskRunner* main_thread_task_runner);
+ bool is_lost);
// These members are only accessed on the main thread, or on the impl thread
// during commit where the main thread is blocked.
@@ -157,17 +157,17 @@ class CC_EXPORT TextureLayer : public Layer {
TextureLayerClient* client_;
- bool flipped_;
- bool nearest_neighbor_;
- gfx::PointF uv_top_left_;
- gfx::PointF uv_bottom_right_;
+ bool flipped_ = true;
+ bool nearest_neighbor_ = false;
+ gfx::PointF uv_top_left_ = gfx::PointF();
+ gfx::PointF uv_bottom_right_ = gfx::PointF(1.f, 1.f);
// [bottom left, top left, top right, bottom right]
- float vertex_opacity_[4];
- bool premultiplied_alpha_;
- bool blend_background_color_;
+ float vertex_opacity_[4] = {1.f, 1.f, 1.f, 1.f};
+ bool premultiplied_alpha_ = true;
+ bool blend_background_color_ = false;
std::unique_ptr<TextureMailboxHolder::MainThreadReference> holder_ref_;
- bool needs_set_mailbox_;
+ bool needs_set_mailbox_ = false;
DISALLOW_COPY_AND_ASSIGN(TextureLayer);
};
diff --git a/chromium/cc/layers/texture_layer_client.h b/chromium/cc/layers/texture_layer_client.h
index fe2bd3b5096..8fe8d96b8ef 100644
--- a/chromium/cc/layers/texture_layer_client.h
+++ b/chromium/cc/layers/texture_layer_client.h
@@ -5,7 +5,7 @@
#ifndef CC_LAYERS_TEXTURE_LAYER_CLIENT_H_
#define CC_LAYERS_TEXTURE_LAYER_CLIENT_H_
-#include "components/viz/common/quads/single_release_callback.h"
+#include "components/viz/common/resources/single_release_callback.h"
namespace viz {
class TextureMailbox;
diff --git a/chromium/cc/layers/texture_layer_impl.cc b/chromium/cc/layers/texture_layer_impl.cc
index 15d999ed569..57632a5ccb9 100644
--- a/chromium/cc/layers/texture_layer_impl.cc
+++ b/chromium/cc/layers/texture_layer_impl.cc
@@ -10,39 +10,24 @@
#include <vector>
#include "base/strings/stringprintf.h"
-#include "cc/output/output_surface.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
#include "cc/resources/scoped_resource.h"
-#include "cc/resources/single_release_callback_impl.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/occlusion.h"
+#include "components/viz/common/quads/solid_color_draw_quad.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
#include "components/viz/common/resources/platform_color.h"
+#include "components/viz/common/resources/single_release_callback.h"
namespace cc {
TextureLayerImpl::TextureLayerImpl(LayerTreeImpl* tree_impl, int id)
- : LayerImpl(tree_impl, id),
- external_texture_resource_(0),
- premultiplied_alpha_(true),
- blend_background_color_(false),
- flipped_(true),
- nearest_neighbor_(false),
- uv_top_left_(0.f, 0.f),
- uv_bottom_right_(1.f, 1.f),
- own_mailbox_(false),
- valid_texture_copy_(false) {
- vertex_opacity_[0] = 1.0f;
- vertex_opacity_[1] = 1.0f;
- vertex_opacity_[2] = 1.0f;
- vertex_opacity_[3] = 1.0f;
-}
+ : LayerImpl(tree_impl, id) {}
TextureLayerImpl::~TextureLayerImpl() { FreeTextureMailbox(); }
void TextureLayerImpl::SetTextureMailbox(
const viz::TextureMailbox& mailbox,
- std::unique_ptr<SingleReleaseCallbackImpl> release_callback) {
+ std::unique_ptr<viz::SingleReleaseCallback> release_callback) {
DCHECK_EQ(mailbox.IsValid(), !!release_callback);
FreeTextureMailbox();
texture_mailbox_ = mailbox;
@@ -63,7 +48,6 @@ bool TextureLayerImpl::IsSnapped() {
void TextureLayerImpl::PushPropertiesTo(LayerImpl* layer) {
LayerImpl::PushPropertiesTo(layer);
-
TextureLayerImpl* texture_layer = static_cast<TextureLayerImpl*>(layer);
texture_layer->SetFlipped(flipped_);
texture_layer->SetUVTopLeft(uv_top_left_);
@@ -80,7 +64,7 @@ void TextureLayerImpl::PushPropertiesTo(LayerImpl* layer) {
}
bool TextureLayerImpl::WillDraw(DrawMode draw_mode,
- ResourceProvider* resource_provider) {
+ LayerTreeResourceProvider* resource_provider) {
if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE)
return false;
@@ -113,7 +97,7 @@ bool TextureLayerImpl::WillDraw(DrawMode draw_mode,
if (!texture_copy_->id()) {
texture_copy_->Allocate(texture_mailbox_.size_in_pixels(),
- ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ ResourceProvider::TEXTURE_HINT_DEFAULT,
resource_provider->best_texture_format(),
gfx::ColorSpace());
}
@@ -144,26 +128,27 @@ bool TextureLayerImpl::WillDraw(DrawMode draw_mode,
LayerImpl::WillDraw(draw_mode, resource_provider);
}
-void TextureLayerImpl::AppendQuads(RenderPass* render_pass,
+void TextureLayerImpl::AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) {
DCHECK(external_texture_resource_ || valid_texture_copy_);
+ SkColor bg_color =
+ blend_background_color_ ? background_color() : SK_ColorTRANSPARENT;
+ bool are_contents_opaque =
+ contents_opaque() || (SkColorGetA(bg_color) == 0xFF);
+
viz::SharedQuadState* shared_quad_state =
render_pass->CreateAndAppendSharedQuadState();
- PopulateSharedQuadState(shared_quad_state);
+ PopulateSharedQuadState(shared_quad_state, are_contents_opaque);
- AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state,
+ AppendDebugBorderQuad(render_pass, gfx::Rect(bounds()), shared_quad_state,
append_quads_data);
- SkColor bg_color = blend_background_color_ ?
- background_color() : SK_ColorTRANSPARENT;
- bool opaque = contents_opaque() || (SkColorGetA(bg_color) == 0xFF);
-
gfx::Rect quad_rect(bounds());
gfx::Rect visible_quad_rect =
draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
quad_rect);
- bool needs_blending = !opaque;
+ bool needs_blending = !are_contents_opaque;
if (visible_quad_rect.IsEmpty())
return;
@@ -171,14 +156,12 @@ void TextureLayerImpl::AppendQuads(RenderPass* render_pass,
!vertex_opacity_[3])
return;
- TextureDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
+ auto* quad = render_pass->CreateAndAppendDrawQuad<viz::TextureDrawQuad>();
viz::ResourceId id =
valid_texture_copy_ ? texture_copy_->id() : external_texture_resource_;
quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, needs_blending,
id, premultiplied_alpha_, uv_top_left_, uv_bottom_right_,
- bg_color, vertex_opacity_, flipped_, nearest_neighbor_,
- texture_mailbox_.secure_output_only());
+ bg_color, vertex_opacity_, flipped_, nearest_neighbor_, false);
if (!valid_texture_copy_) {
quad->set_resource_size_in_pixels(texture_mailbox_.size_in_pixels());
}
@@ -250,12 +233,8 @@ const char* TextureLayerImpl::LayerTypeAsString() const {
void TextureLayerImpl::FreeTextureMailbox() {
if (own_mailbox_) {
DCHECK(!external_texture_resource_);
- if (release_callback_) {
- release_callback_->Run(texture_mailbox_.sync_token(), false,
- layer_tree_impl()
- ->task_runner_provider()
- ->blocking_main_thread_task_runner());
- }
+ if (release_callback_)
+ release_callback_->Run(texture_mailbox_.sync_token(), false);
texture_mailbox_ = viz::TextureMailbox();
release_callback_ = nullptr;
} else if (external_texture_resource_) {
diff --git a/chromium/cc/layers/texture_layer_impl.h b/chromium/cc/layers/texture_layer_impl.h
index 134d43d1d3c..64f2c21523d 100644
--- a/chromium/cc/layers/texture_layer_impl.h
+++ b/chromium/cc/layers/texture_layer_impl.h
@@ -12,9 +12,13 @@
#include "base/memory/ptr_util.h"
#include "cc/cc_export.h"
#include "cc/layers/layer_impl.h"
+#include "components/viz/common/quads/texture_mailbox.h"
+
+namespace viz {
+class SingleReleaseCallback;
+}
namespace cc {
-class SingleReleaseCallbackImpl;
class ScopedResource;
class CC_EXPORT TextureLayerImpl : public LayerImpl {
@@ -31,8 +35,8 @@ class CC_EXPORT TextureLayerImpl : public LayerImpl {
void PushPropertiesTo(LayerImpl* layer) override;
bool WillDraw(DrawMode draw_mode,
- ResourceProvider* resource_provider) override;
- void AppendQuads(RenderPass* render_pass,
+ LayerTreeResourceProvider* resource_provider) override;
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override;
SimpleEnclosedRegion VisibleOpaqueRegion() const override;
void ReleaseResources() override;
@@ -55,7 +59,7 @@ class CC_EXPORT TextureLayerImpl : public LayerImpl {
void SetTextureMailbox(
const viz::TextureMailbox& mailbox,
- std::unique_ptr<SingleReleaseCallbackImpl> release_callback);
+ std::unique_ptr<viz::SingleReleaseCallback> release_callback);
private:
TextureLayerImpl(LayerTreeImpl* tree_impl, int id);
@@ -63,21 +67,21 @@ class CC_EXPORT TextureLayerImpl : public LayerImpl {
const char* LayerTypeAsString() const override;
void FreeTextureMailbox();
- viz::ResourceId external_texture_resource_;
- bool premultiplied_alpha_;
- bool blend_background_color_;
- bool flipped_;
- bool nearest_neighbor_;
- gfx::PointF uv_top_left_;
- gfx::PointF uv_bottom_right_;
- float vertex_opacity_[4];
+ viz::ResourceId external_texture_resource_ = 0;
+ bool premultiplied_alpha_ = true;
+ bool blend_background_color_ = false;
+ bool flipped_ = true;
+ bool nearest_neighbor_ = false;
+ gfx::PointF uv_top_left_ = gfx::PointF();
+ gfx::PointF uv_bottom_right_ = gfx::PointF(1.f, 1.f);
+ float vertex_opacity_[4] = {1.f, 1.f, 1.f, 1.f};
// This is a resource that's a GL copy of a software texture mailbox.
std::unique_ptr<ScopedResource> texture_copy_;
viz::TextureMailbox texture_mailbox_;
- std::unique_ptr<SingleReleaseCallbackImpl> release_callback_;
- bool own_mailbox_;
- bool valid_texture_copy_;
+ std::unique_ptr<viz::SingleReleaseCallback> release_callback_;
+ bool own_mailbox_ = false;
+ bool valid_texture_copy_ = false;
DISALLOW_COPY_AND_ASSIGN(TextureLayerImpl);
};
diff --git a/chromium/cc/layers/texture_layer_impl_unittest.cc b/chromium/cc/layers/texture_layer_impl_unittest.cc
index 0dc3a8cbf5a..e95f5575d5a 100644
--- a/chromium/cc/layers/texture_layer_impl_unittest.cc
+++ b/chromium/cc/layers/texture_layer_impl_unittest.cc
@@ -6,21 +6,19 @@
#include <stddef.h>
-#include "cc/output/layer_tree_frame_sink.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
#include "cc/test/fake_layer_tree_frame_sink.h"
#include "cc/test/layer_test_common.h"
+#include "cc/trees/layer_tree_frame_sink.h"
#include "components/viz/common/gpu/context_provider.h"
+#include "components/viz/common/quads/draw_quad.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
namespace {
-void IgnoreCallback(const gpu::SyncToken& sync_token,
- bool lost,
- BlockingTaskRunner* main_thread_task_runner) {}
+void IgnoreCallback(const gpu::SyncToken& sync_token, bool lost) {}
TEST(TextureLayerImplTest, VisibleOpaqueRegion) {
const gfx::Size layer_bounds(100, 100);
@@ -71,7 +69,7 @@ TEST(TextureLayerImplTest, Occlusion) {
texture_layer_impl->SetDrawsContent(true);
texture_layer_impl->SetTextureMailbox(
texture_mailbox,
- SingleReleaseCallbackImpl::Create(base::Bind(&IgnoreCallback)));
+ viz::SingleReleaseCallback::Create(base::Bind(&IgnoreCallback)));
impl.CalcDrawProps(viewport_size);
@@ -108,46 +106,6 @@ TEST(TextureLayerImplTest, Occlusion) {
}
}
-TEST(TextureLayerImplTest, OutputIsSecure) {
- gfx::Size layer_size(1000, 1000);
- gfx::Size viewport_size(1000, 1000);
-
- LayerTestCommon::LayerImplTest impl;
-
- gpu::Mailbox mailbox;
- impl.layer_tree_frame_sink()
- ->context_provider()
- ->ContextGL()
- ->GenMailboxCHROMIUM(mailbox.name);
- viz::TextureMailbox texture_mailbox(
- mailbox,
- gpu::SyncToken(gpu::CommandBufferNamespace::GPU_IO, 0x123,
- gpu::CommandBufferId::FromUnsafeValue(0x234), 0x456),
- GL_TEXTURE_2D, layer_size, false, true);
-
- TextureLayerImpl* texture_layer_impl =
- impl.AddChildToRoot<TextureLayerImpl>();
- texture_layer_impl->SetBounds(layer_size);
- texture_layer_impl->SetDrawsContent(true);
- texture_layer_impl->SetTextureMailbox(
- texture_mailbox,
- SingleReleaseCallbackImpl::Create(base::Bind(&IgnoreCallback)));
-
- impl.CalcDrawProps(viewport_size);
-
- {
- gfx::Rect occluded;
- impl.AppendQuadsWithOcclusion(texture_layer_impl, occluded);
-
- EXPECT_EQ(1u, impl.quad_list().size());
- ASSERT_EQ(DrawQuad::Material::TEXTURE_CONTENT,
- impl.quad_list().front()->material);
- const TextureDrawQuad* quad =
- TextureDrawQuad::MaterialCast(impl.quad_list().front());
- EXPECT_TRUE(quad->secure_output_only);
- }
-}
-
TEST(TextureLayerImplTest, ResourceNotFreedOnGpuRasterToggle) {
bool released = false;
LayerTestCommon::LayerImplTest impl(
@@ -173,11 +131,10 @@ TEST(TextureLayerImplTest, ResourceNotFreedOnGpuRasterToggle) {
texture_layer_impl->SetBounds(layer_size);
texture_layer_impl->SetDrawsContent(true);
texture_layer_impl->SetTextureMailbox(
- texture_mailbox,
- SingleReleaseCallbackImpl::Create(base::Bind(
- [](bool* released, const gpu::SyncToken& sync_token, bool lost,
- BlockingTaskRunner* main_thread_task_runner) { *released = true; },
- base::Unretained(&released))));
+ texture_mailbox, viz::SingleReleaseCallback::Create(base::Bind(
+ [](bool* released, const gpu::SyncToken& sync_token,
+ bool lost) { *released = true; },
+ base::Unretained(&released))));
impl.CalcDrawProps(viewport_size);
diff --git a/chromium/cc/layers/texture_layer_unittest.cc b/chromium/cc/layers/texture_layer_unittest.cc
index ed4de24d946..78262ddc334 100644
--- a/chromium/cc/layers/texture_layer_unittest.cc
+++ b/chromium/cc/layers/texture_layer_unittest.cc
@@ -34,7 +34,6 @@
#include "cc/test/stub_layer_tree_host_single_thread_client.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/test/test_web_graphics_context_3d.h"
-#include "cc/trees/blocking_task_runner.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/single_thread_proxy.h"
@@ -81,7 +80,6 @@ class MockLayerTreeHost : public LayerTreeHost {
}
MOCK_METHOD0(SetNeedsCommit, void());
- MOCK_METHOD0(SetNeedsUpdateLayers, void());
MOCK_METHOD0(StartRateLimiter, void());
MOCK_METHOD0(StopRateLimiter, void());
@@ -136,16 +134,6 @@ class MockMailboxCallback {
void(viz::SharedBitmap* shared_bitmap,
const gpu::SyncToken& sync_token,
bool lost_resource));
- MOCK_METHOD4(ReleaseImpl,
- void(const gpu::Mailbox& mailbox,
- const gpu::SyncToken& sync_token,
- bool lost_resource,
- BlockingTaskRunner* main_thread_task_runner));
- MOCK_METHOD4(ReleaseImpl2,
- void(viz::SharedBitmap* shared_bitmap,
- const gpu::SyncToken& sync_token,
- bool lost_resource,
- BlockingTaskRunner* main_thread_task_runner));
};
struct CommonMailboxObjects {
@@ -166,12 +154,6 @@ struct CommonMailboxObjects {
release_mailbox2_ = base::Bind(&MockMailboxCallback::Release,
base::Unretained(&mock_callback_),
mailbox_name2_);
- release_mailbox1_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl,
- base::Unretained(&mock_callback_),
- mailbox_name1_);
- release_mailbox2_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl,
- base::Unretained(&mock_callback_),
- mailbox_name2_);
const uint32_t arbitrary_target1 = GL_TEXTURE_2D;
const uint32_t arbitrary_target2 = GL_TEXTURE_EXTERNAL_OES;
mailbox1_ =
@@ -184,9 +166,6 @@ struct CommonMailboxObjects {
release_mailbox3_ =
base::Bind(&MockMailboxCallback::Release2,
base::Unretained(&mock_callback_), shared_bitmap_.get());
- release_mailbox3_impl_ =
- base::Bind(&MockMailboxCallback::ReleaseImpl2,
- base::Unretained(&mock_callback_), shared_bitmap_.get());
mailbox3_ = viz::TextureMailbox(shared_bitmap_.get(), size);
}
@@ -196,9 +175,6 @@ struct CommonMailboxObjects {
viz::ReleaseCallback release_mailbox1_;
viz::ReleaseCallback release_mailbox2_;
viz::ReleaseCallback release_mailbox3_;
- ReleaseCallbackImpl release_mailbox1_impl_;
- ReleaseCallbackImpl release_mailbox2_impl_;
- ReleaseCallbackImpl release_mailbox3_impl_;
viz::TextureMailbox mailbox1_;
viz::TextureMailbox mailbox2_;
viz::TextureMailbox mailbox3_;
@@ -344,11 +320,6 @@ class TextureLayerMailboxHolderTest : public TextureLayerTest {
TextureLayerMailboxHolderTest()
: main_thread_("MAIN") {
main_thread_.Start();
- main_thread_.task_runner()->PostTask(
- FROM_HERE,
- base::BindOnce(&TextureLayerMailboxHolderTest::InitializeOnMain,
- base::Unretained(this)));
- Wait(main_thread_);
}
void Wait(const base::Thread& thread) {
@@ -368,29 +339,16 @@ class TextureLayerMailboxHolderTest : public TextureLayerTest {
void ReleaseMainRef() { main_ref_ = nullptr; }
- void CreateImplRef(std::unique_ptr<SingleReleaseCallbackImpl>* impl_ref) {
- *impl_ref = main_ref_->holder()->GetCallbackForImplThread();
- }
-
- void CapturePostTasksAndWait(base::WaitableEvent* begin_capture,
- base::WaitableEvent* wait_for_capture,
- base::WaitableEvent* stop_capture) {
- begin_capture->Wait();
- BlockingTaskRunner::CapturePostTasks capture(
- main_thread_task_runner_.get());
- wait_for_capture->Signal();
- stop_capture->Wait();
+ void CreateImplRef(
+ std::unique_ptr<viz::SingleReleaseCallback>* impl_ref,
+ scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner) {
+ *impl_ref = main_ref_->holder()->GetCallbackForImplThread(
+ std::move(main_thread_task_runner));
}
protected:
- void InitializeOnMain() {
- main_thread_task_runner_ =
- BlockingTaskRunner::Create(main_thread_.task_runner());
- }
-
std::unique_ptr<TestMailboxHolder::MainThreadReference> main_ref_;
base::Thread main_thread_;
- std::unique_ptr<BlockingTaskRunner> main_thread_task_runner_;
};
TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) {
@@ -406,27 +364,27 @@ TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) {
// The texture layer is attached to compositor1, and passes a reference to its
// impl tree.
- std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
+ std::unique_ptr<viz::SingleReleaseCallback> compositor1;
main_thread_.task_runner()->PostTask(
FROM_HERE, base::BindOnce(&TextureLayerMailboxHolderTest::CreateImplRef,
- base::Unretained(this), &compositor1));
+ base::Unretained(this), &compositor1,
+ main_thread_.task_runner()));
// Then the texture layer is removed and attached to compositor2, and passes a
// reference to its impl tree.
- std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
+ std::unique_ptr<viz::SingleReleaseCallback> compositor2;
main_thread_.task_runner()->PostTask(
FROM_HERE, base::BindOnce(&TextureLayerMailboxHolderTest::CreateImplRef,
- base::Unretained(this), &compositor2));
+ base::Unretained(this), &compositor2,
+ main_thread_.task_runner()));
Wait(main_thread_);
Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
// The compositors both destroy their impl trees before the main thread layer
// is destroyed.
- compositor1->Run(SyncTokenFromUInt(100), false,
- main_thread_task_runner_.get());
- compositor2->Run(SyncTokenFromUInt(200), false,
- main_thread_task_runner_.get());
+ compositor1->Run(SyncTokenFromUInt(100), false);
+ compositor2->Run(SyncTokenFromUInt(200), false);
Wait(main_thread_);
@@ -459,24 +417,25 @@ TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleaseBetween) {
// The texture layer is attached to compositor1, and passes a reference to its
// impl tree.
- std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
+ std::unique_ptr<viz::SingleReleaseCallback> compositor1;
main_thread_.task_runner()->PostTask(
FROM_HERE, base::BindOnce(&TextureLayerMailboxHolderTest::CreateImplRef,
- base::Unretained(this), &compositor1));
+ base::Unretained(this), &compositor1,
+ main_thread_.task_runner()));
// Then the texture layer is removed and attached to compositor2, and passes a
// reference to its impl tree.
- std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
+ std::unique_ptr<viz::SingleReleaseCallback> compositor2;
main_thread_.task_runner()->PostTask(
FROM_HERE, base::BindOnce(&TextureLayerMailboxHolderTest::CreateImplRef,
- base::Unretained(this), &compositor2));
+ base::Unretained(this), &compositor2,
+ main_thread_.task_runner()));
Wait(main_thread_);
Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
// One compositor destroys their impl tree.
- compositor1->Run(SyncTokenFromUInt(100), false,
- main_thread_task_runner_.get());
+ compositor1->Run(SyncTokenFromUInt(100), false);
// Then the main thread reference is destroyed.
main_thread_.task_runner()->PostTask(
@@ -494,8 +453,7 @@ TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleaseBetween) {
Release(test_data_.mailbox_name1_, SyncTokenFromUInt(200), true))
.Times(1);
- compositor2->Run(SyncTokenFromUInt(200), true,
- main_thread_task_runner_.get());
+ compositor2->Run(SyncTokenFromUInt(200), true);
Wait(main_thread_);
Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
}
@@ -513,17 +471,19 @@ TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) {
// The texture layer is attached to compositor1, and passes a reference to its
// impl tree.
- std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
+ std::unique_ptr<viz::SingleReleaseCallback> compositor1;
main_thread_.task_runner()->PostTask(
FROM_HERE, base::BindOnce(&TextureLayerMailboxHolderTest::CreateImplRef,
- base::Unretained(this), &compositor1));
+ base::Unretained(this), &compositor1,
+ main_thread_.task_runner()));
// Then the texture layer is removed and attached to compositor2, and passes a
// reference to its impl tree.
- std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
+ std::unique_ptr<viz::SingleReleaseCallback> compositor2;
main_thread_.task_runner()->PostTask(
FROM_HERE, base::BindOnce(&TextureLayerMailboxHolderTest::CreateImplRef,
- base::Unretained(this), &compositor2));
+ base::Unretained(this), &compositor2,
+ main_thread_.task_runner()));
Wait(main_thread_);
Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
@@ -534,8 +494,7 @@ TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) {
base::Unretained(this)));
// One compositor destroys their impl tree.
- compositor2->Run(SyncTokenFromUInt(200), false,
- main_thread_task_runner_.get());
+ compositor2->Run(SyncTokenFromUInt(200), false);
Wait(main_thread_);
@@ -548,88 +507,8 @@ TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) {
Release(test_data_.mailbox_name1_, SyncTokenFromUInt(100), true))
.Times(1);
- compositor1->Run(SyncTokenFromUInt(100), true,
- main_thread_task_runner_.get());
- Wait(main_thread_);
- Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
-}
-
-TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_SecondImplRefShortcut) {
- scoped_refptr<TextureLayer> test_layer =
- TextureLayer::CreateForMailbox(nullptr);
- ASSERT_TRUE(test_layer.get());
-
- main_thread_.task_runner()->PostTask(
- FROM_HERE, base::BindOnce(&TextureLayerMailboxHolderTest::CreateMainRef,
- base::Unretained(this)));
-
- Wait(main_thread_);
-
- // The texture layer is attached to compositor1, and passes a reference to its
- // impl tree.
- std::unique_ptr<SingleReleaseCallbackImpl> compositor1;
- main_thread_.task_runner()->PostTask(
- FROM_HERE, base::BindOnce(&TextureLayerMailboxHolderTest::CreateImplRef,
- base::Unretained(this), &compositor1));
-
- // Then the texture layer is removed and attached to compositor2, and passes a
- // reference to its impl tree.
- std::unique_ptr<SingleReleaseCallbackImpl> compositor2;
- main_thread_.task_runner()->PostTask(
- FROM_HERE, base::BindOnce(&TextureLayerMailboxHolderTest::CreateImplRef,
- base::Unretained(this), &compositor2));
-
- Wait(main_thread_);
- Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
-
- // The main thread reference is destroyed first.
- main_thread_.task_runner()->PostTask(
- FROM_HERE, base::BindOnce(&TextureLayerMailboxHolderTest::ReleaseMainRef,
- base::Unretained(this)));
-
- EXPECT_CALL(test_data_.mock_callback_,
- Release(test_data_.mailbox_name1_, SyncTokenFromUInt(200), true))
- .Times(1);
-
- base::WaitableEvent begin_capture(
- base::WaitableEvent::ResetPolicy::AUTOMATIC,
- base::WaitableEvent::InitialState::NOT_SIGNALED);
- base::WaitableEvent wait_for_capture(
- base::WaitableEvent::ResetPolicy::AUTOMATIC,
- base::WaitableEvent::InitialState::NOT_SIGNALED);
- base::WaitableEvent stop_capture(
- base::WaitableEvent::ResetPolicy::AUTOMATIC,
- base::WaitableEvent::InitialState::NOT_SIGNALED);
-
- // Post a task to start capturing tasks on the main thread. This will block
- // the main thread until we signal the |stop_capture| event.
- main_thread_.task_runner()->PostTask(
- FROM_HERE,
- base::BindOnce(&TextureLayerMailboxHolderTest::CapturePostTasksAndWait,
- base::Unretained(this), &begin_capture, &wait_for_capture,
- &stop_capture));
-
- // Before the main thread capturing starts, one compositor destroys their
- // impl reference. Since capturing did not start, this gets post-tasked to
- // the main thread.
- compositor1->Run(SyncTokenFromUInt(100), false,
- main_thread_task_runner_.get());
-
- // Start capturing on the main thread.
- begin_capture.Signal();
- wait_for_capture.Wait();
-
- // Meanwhile, the second compositor released its impl reference, but this task
- // gets shortcutted directly to the main thread. This means the reference is
- // released before compositor1, whose reference will be released later when
- // the post-task is serviced. But since it was destroyed _on the impl thread_
- // last, its sync point values should be used.
- compositor2->Run(SyncTokenFromUInt(200), true,
- main_thread_task_runner_.get());
-
- stop_capture.Signal();
+ compositor1->Run(SyncTokenFromUInt(100), true);
Wait(main_thread_);
-
Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
}
@@ -705,8 +584,16 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest {
break;
case 7:
EXPECT_EQ(4, callback_count_);
- // Resetting the mailbox will call the callback now.
+ // Resetting the mailbox will call the callback now, before another
+ // commit is needed, as the ReleaseCallback is already in flight from
+ // RemoveFromParent().
layer_->SetTextureMailbox(viz::TextureMailbox(), nullptr);
+ pending_callback_ = true;
+ frame_number_ = layer_tree_host()->SourceFrameNumber();
+ break;
+ case 8:
+ // A commit wasn't needed, the ReleaseCallback was already in flight.
+ EXPECT_EQ(frame_number_, layer_tree_host()->SourceFrameNumber());
EXPECT_EQ(5, callback_count_);
EndTest();
break;
@@ -779,6 +666,7 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest {
base::ThreadChecker main_thread_;
int callback_count_ = 0;
int test_case_ = 0;
+ int frame_number_ = 0;
// Whether we are waiting on a callback to advance the test case.
bool pending_callback_ = false;
scoped_refptr<Layer> root_;
@@ -913,11 +801,11 @@ class TextureLayerImplWithMailboxTest : public TextureLayerTest {
TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) {
EXPECT_CALL(
test_data_.mock_callback_,
- ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
+ Release(test_data_.mailbox_name1_, test_data_.sync_token1_, false))
.Times(AnyNumber());
EXPECT_CALL(
test_data_.mock_callback_,
- ReleaseImpl2(test_data_.shared_bitmap_.get(), gpu::SyncToken(), false, _))
+ Release2(test_data_.shared_bitmap_.get(), gpu::SyncToken(), false))
.Times(AnyNumber());
// Hardware mode.
{
@@ -925,7 +813,7 @@ TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) {
TextureLayerImpl::Create(host_impl_.active_tree(), 1);
impl_layer->SetTextureMailbox(
test_data_.mailbox1_,
- SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
+ viz::SingleReleaseCallback::Create(test_data_.release_mailbox1_));
EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
}
@@ -942,7 +830,7 @@ TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) {
TextureLayerImpl::Create(host_impl_.active_tree(), 1);
impl_layer->SetTextureMailbox(
test_data_.mailbox3_,
- SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_));
+ viz::SingleReleaseCallback::Create(test_data_.release_mailbox3_));
EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE));
}
@@ -952,7 +840,7 @@ TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) {
TextureLayerImpl::Create(host_impl_.active_tree(), 1);
impl_layer->SetTextureMailbox(
test_data_.mailbox1_,
- SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
+ viz::SingleReleaseCallback::Create(test_data_.release_mailbox1_));
EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
}
@@ -969,7 +857,7 @@ TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) {
TextureLayerImpl::Create(host_impl_.active_tree(), 1);
impl_layer->SetTextureMailbox(
test_data_.mailbox3_,
- SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_));
+ viz::SingleReleaseCallback::Create(test_data_.release_mailbox3_));
EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE));
}
@@ -979,7 +867,7 @@ TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) {
TextureLayerImpl::Create(host_impl_.active_tree(), 1);
impl_layer->SetTextureMailbox(
test_data_.mailbox1_,
- SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
+ viz::SingleReleaseCallback::Create(test_data_.release_mailbox1_));
EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE));
}
}
@@ -996,37 +884,39 @@ TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) {
pending_layer->SetTextureMailbox(
test_data_.mailbox1_,
- SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
+ viz::SingleReleaseCallback::Create(test_data_.release_mailbox1_));
// Test multiple commits without an activation.
EXPECT_CALL(
test_data_.mock_callback_,
- ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
+ Release(test_data_.mailbox_name1_, test_data_.sync_token1_, false))
.Times(1);
pending_layer->SetTextureMailbox(
test_data_.mailbox2_,
- SingleReleaseCallbackImpl::Create(test_data_.release_mailbox2_impl_));
+ viz::SingleReleaseCallback::Create(test_data_.release_mailbox2_));
Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
// Test callback after activation.
pending_layer->PushPropertiesTo(active_layer.get());
active_layer->DidBecomeActive();
- EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0);
+ EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0);
pending_layer->SetTextureMailbox(
test_data_.mailbox1_,
- SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
+ viz::SingleReleaseCallback::Create(test_data_.release_mailbox1_));
Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
EXPECT_CALL(test_data_.mock_callback_,
- ReleaseImpl(test_data_.mailbox_name2_, _, false, _)).Times(1);
+ Release(test_data_.mailbox_name2_, _, false))
+ .Times(1);
pending_layer->PushPropertiesTo(active_layer.get());
active_layer->DidBecomeActive();
Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
// Test resetting the mailbox.
EXPECT_CALL(test_data_.mock_callback_,
- ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
+ Release(test_data_.mailbox_name1_, _, false))
+ .Times(1);
pending_layer->SetTextureMailbox(viz::TextureMailbox(), nullptr);
pending_layer->PushPropertiesTo(active_layer.get());
active_layer->DidBecomeActive();
@@ -1035,11 +925,11 @@ TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) {
// Test destructor.
EXPECT_CALL(
test_data_.mock_callback_,
- ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_token1_, false, _))
+ Release(test_data_.mailbox_name1_, test_data_.sync_token1_, false))
.Times(1);
pending_layer->SetTextureMailbox(
test_data_.mailbox1_,
- SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
+ viz::SingleReleaseCallback::Create(test_data_.release_mailbox1_));
}
TEST_F(TextureLayerImplWithMailboxTest,
@@ -1049,10 +939,11 @@ TEST_F(TextureLayerImplWithMailboxTest,
ASSERT_TRUE(impl_layer);
EXPECT_CALL(test_data_.mock_callback_,
- ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
+ Release(test_data_.mailbox_name1_, _, false))
+ .Times(1);
impl_layer->SetTextureMailbox(
test_data_.mailbox1_,
- SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
+ viz::SingleReleaseCallback::Create(test_data_.release_mailbox1_));
impl_layer->DidBecomeActive();
EXPECT_TRUE(impl_layer->WillDraw(
DRAW_MODE_HARDWARE, host_impl_.active_tree()->resource_provider()));
@@ -1065,7 +956,7 @@ TEST_F(TextureLayerImplWithMailboxTest, TestCallbackOnInUseResource) {
host_impl_.active_tree()->resource_provider();
viz::ResourceId id = provider->CreateResourceFromTextureMailbox(
test_data_.mailbox1_,
- SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_));
+ viz::SingleReleaseCallback::Create(test_data_.release_mailbox1_));
provider->AllocateForTesting(id);
// Transfer some resources to the parent.
@@ -1074,11 +965,12 @@ TEST_F(TextureLayerImplWithMailboxTest, TestCallbackOnInUseResource) {
std::vector<viz::TransferableResource> list;
provider->PrepareSendToParent(resource_ids_to_transfer, &list);
EXPECT_TRUE(provider->InUseByConsumer(id));
- EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0);
+ EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0);
provider->DeleteResource(id);
Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
EXPECT_CALL(test_data_.mock_callback_,
- ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1);
+ Release(test_data_.mailbox_name1_, _, false))
+ .Times(1);
std::vector<viz::ReturnedResource> returned =
viz::TransferableResource::ReturnResources(list);
provider->ReceiveReturnsFromParent(returned);
diff --git a/chromium/cc/layers/ui_resource_layer.cc b/chromium/cc/layers/ui_resource_layer.cc
index c2ed2147727..150422afe69 100644
--- a/chromium/cc/layers/ui_resource_layer.cc
+++ b/chromium/cc/layers/ui_resource_layer.cc
@@ -15,7 +15,7 @@
namespace cc {
scoped_refptr<UIResourceLayer> UIResourceLayer::Create() {
- return make_scoped_refptr(new UIResourceLayer());
+ return base::WrapRefCounted(new UIResourceLayer());
}
UIResourceLayer::UIResourceLayer()
diff --git a/chromium/cc/layers/ui_resource_layer_impl.cc b/chromium/cc/layers/ui_resource_layer_impl.cc
index 33ed81d8475..e0f125207a2 100644
--- a/chromium/cc/layers/ui_resource_layer_impl.cc
+++ b/chromium/cc/layers/ui_resource_layer_impl.cc
@@ -7,9 +7,9 @@
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "cc/base/math_util.h"
-#include "cc/quads/texture_draw_quad.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/occlusion.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
#include "ui/gfx/geometry/rect_f.h"
namespace cc {
@@ -84,28 +84,32 @@ void UIResourceLayerImpl::SetVertexOpacity(const float vertex_opacity[4]) {
NoteLayerPropertyChanged();
}
-bool UIResourceLayerImpl::WillDraw(DrawMode draw_mode,
- ResourceProvider* resource_provider) {
+bool UIResourceLayerImpl::WillDraw(
+ DrawMode draw_mode,
+ LayerTreeResourceProvider* resource_provider) {
if (!ui_resource_id_ || draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE)
return false;
return LayerImpl::WillDraw(draw_mode, resource_provider);
}
-void UIResourceLayerImpl::AppendQuads(
- RenderPass* render_pass,
- AppendQuadsData* append_quads_data) {
+void UIResourceLayerImpl::AppendQuads(viz::RenderPass* render_pass,
+ AppendQuadsData* append_quads_data) {
+ DCHECK(!bounds().IsEmpty());
+
viz::SharedQuadState* shared_quad_state =
render_pass->CreateAndAppendSharedQuadState();
- PopulateSharedQuadState(shared_quad_state);
-
- AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state,
- append_quads_data);
-
- if (!ui_resource_id_)
- return;
viz::ResourceId resource =
- layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_);
+ ui_resource_id_
+ ? layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_)
+ : 0;
+ bool are_contents_opaque =
+ resource ? (layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_) ||
+ contents_opaque())
+ : false;
+ PopulateSharedQuadState(shared_quad_state, are_contents_opaque);
+ AppendDebugBorderQuad(render_pass, gfx::Rect(bounds()), shared_quad_state,
+ append_quads_data);
if (!resource)
return;
@@ -114,21 +118,15 @@ void UIResourceLayerImpl::AppendQuads(
static const bool nearest_neighbor = false;
static const bool premultiplied_alpha = true;
- DCHECK(!bounds().IsEmpty());
-
- bool opaque = layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_) ||
- contents_opaque();
-
gfx::Rect quad_rect(bounds());
- bool needs_blending = opaque ? false : true;
+ bool needs_blending = are_contents_opaque ? false : true;
gfx::Rect visible_quad_rect =
draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
quad_rect);
if (visible_quad_rect.IsEmpty())
return;
- TextureDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
+ auto* quad = render_pass->CreateAndAppendDrawQuad<viz::TextureDrawQuad>();
quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, needs_blending,
resource, premultiplied_alpha, uv_top_left_, uv_bottom_right_,
SK_ColorTRANSPARENT, vertex_opacity_, flipped, nearest_neighbor,
@@ -140,8 +138,8 @@ const char* UIResourceLayerImpl::LayerTypeAsString() const {
return "cc::UIResourceLayerImpl";
}
-std::unique_ptr<base::DictionaryValue> UIResourceLayerImpl::LayerTreeAsJson() {
- std::unique_ptr<base::DictionaryValue> result = LayerImpl::LayerTreeAsJson();
+std::unique_ptr<base::DictionaryValue> UIResourceLayerImpl::LayerAsJson() {
+ std::unique_ptr<base::DictionaryValue> result = LayerImpl::LayerAsJson();
result->Set("ImageBounds", MathUtil::AsValue(image_bounds_));
diff --git a/chromium/cc/layers/ui_resource_layer_impl.h b/chromium/cc/layers/ui_resource_layer_impl.h
index e7d8b6f91f5..8660ab7a913 100644
--- a/chromium/cc/layers/ui_resource_layer_impl.h
+++ b/chromium/cc/layers/ui_resource_layer_impl.h
@@ -45,11 +45,11 @@ class CC_EXPORT UIResourceLayerImpl : public LayerImpl {
void PushPropertiesTo(LayerImpl* layer) override;
bool WillDraw(DrawMode draw_mode,
- ResourceProvider* resource_provider) override;
- void AppendQuads(RenderPass* render_pass,
+ LayerTreeResourceProvider* resource_provider) override;
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override;
- std::unique_ptr<base::DictionaryValue> LayerTreeAsJson() override;
+ std::unique_ptr<base::DictionaryValue> LayerAsJson() override;
protected:
UIResourceLayerImpl(LayerTreeImpl* tree_impl, int id);
diff --git a/chromium/cc/layers/ui_resource_layer_impl_unittest.cc b/chromium/cc/layers/ui_resource_layer_impl_unittest.cc
index cb702946c47..b248d3da78e 100644
--- a/chromium/cc/layers/ui_resource_layer_impl_unittest.cc
+++ b/chromium/cc/layers/ui_resource_layer_impl_unittest.cc
@@ -6,7 +6,6 @@
#include "cc/layers/append_quads_data.h"
#include "cc/layers/ui_resource_layer_impl.h"
-#include "cc/quads/draw_quad.h"
#include "cc/resources/ui_resource_bitmap.h"
#include "cc/resources/ui_resource_client.h"
#include "cc/test/fake_impl_task_runner_provider.h"
@@ -16,6 +15,7 @@
#include "cc/test/layer_test_common.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/trees/single_thread_proxy.h"
+#include "components/viz/common/quads/draw_quad.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/transform.h"
@@ -50,14 +50,14 @@ void QuadSizeTest(FakeUIResourceLayerTreeHostImpl* host_impl,
host_impl->active_tree()->SetRootLayerForTesting(std::move(layer));
host_impl->active_tree()->BuildPropertyTreesForTesting();
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
host_impl->active_tree()->root_layer_for_testing()->AppendQuads(
render_pass.get(), &data);
// Verify quad rects
- const QuadList& quads = render_pass->quad_list;
+ const viz::QuadList& quads = render_pass->quad_list;
EXPECT_EQ(expected_quad_size, quads.size());
host_impl->active_tree()->DetachLayers();
@@ -100,16 +100,18 @@ void NeedsBlendingTest(FakeUIResourceLayerTreeHostImpl* host_impl,
host_impl->active_tree()->SetRootLayerForTesting(std::move(layer));
host_impl->active_tree()->BuildPropertyTreesForTesting();
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
+ std::unique_ptr<viz::RenderPass> render_pass = viz::RenderPass::Create();
AppendQuadsData data;
host_impl->active_tree()->root_layer_for_testing()->AppendQuads(
render_pass.get(), &data);
// Verify needs_blending is set appropriately.
- const QuadList& quads = render_pass->quad_list;
+ const viz::QuadList& quads = render_pass->quad_list;
EXPECT_GE(quads.size(), (size_t)0);
EXPECT_EQ(needs_blending, quads.front()->needs_blending);
+ EXPECT_EQ(quads.front()->needs_blending,
+ !quads.front()->shared_quad_state->are_contents_opaque);
host_impl->active_tree()->DetachLayers();
}
diff --git a/chromium/cc/layers/ui_resource_layer_unittest.cc b/chromium/cc/layers/ui_resource_layer_unittest.cc
index 6c05ec16246..b7b23fa7a89 100644
--- a/chromium/cc/layers/ui_resource_layer_unittest.cc
+++ b/chromium/cc/layers/ui_resource_layer_unittest.cc
@@ -28,7 +28,7 @@ namespace {
class TestUIResourceLayer : public UIResourceLayer {
public:
static scoped_refptr<TestUIResourceLayer> Create() {
- return make_scoped_refptr(new TestUIResourceLayer());
+ return base::WrapRefCounted(new TestUIResourceLayer());
}
using UIResourceLayer::resource_id;
diff --git a/chromium/cc/layers/video_frame_provider_client_impl.cc b/chromium/cc/layers/video_frame_provider_client_impl.cc
index 770c4bc5b96..ea4499cfebf 100644
--- a/chromium/cc/layers/video_frame_provider_client_impl.cc
+++ b/chromium/cc/layers/video_frame_provider_client_impl.cc
@@ -15,7 +15,8 @@ namespace cc {
scoped_refptr<VideoFrameProviderClientImpl>
VideoFrameProviderClientImpl::Create(VideoFrameProvider* provider,
VideoFrameControllerClient* client) {
- return make_scoped_refptr(new VideoFrameProviderClientImpl(provider, client));
+ return base::WrapRefCounted(
+ new VideoFrameProviderClientImpl(provider, client));
}
VideoFrameProviderClientImpl::VideoFrameProviderClientImpl(
diff --git a/chromium/cc/layers/video_layer.cc b/chromium/cc/layers/video_layer.cc
index 13b5b8fbff3..8f442809317 100644
--- a/chromium/cc/layers/video_layer.cc
+++ b/chromium/cc/layers/video_layer.cc
@@ -11,7 +11,7 @@ namespace cc {
scoped_refptr<VideoLayer> VideoLayer::Create(
VideoFrameProvider* provider,
media::VideoRotation video_rotation) {
- return make_scoped_refptr(new VideoLayer(provider, video_rotation));
+ return base::WrapRefCounted(new VideoLayer(provider, video_rotation));
}
VideoLayer::VideoLayer(VideoFrameProvider* provider,
diff --git a/chromium/cc/layers/video_layer_impl.cc b/chromium/cc/layers/video_layer_impl.cc
index ce3a483cf45..d1ee805651f 100644
--- a/chromium/cc/layers/video_layer_impl.cc
+++ b/chromium/cc/layers/video_layer_impl.cc
@@ -10,14 +10,14 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "cc/layers/video_frame_provider_client_impl.h"
-#include "cc/quads/stream_video_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
-#include "cc/quads/yuv_video_draw_quad.h"
#include "cc/resources/resource_provider.h"
-#include "cc/resources/single_release_callback_impl.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/occlusion.h"
#include "cc/trees/task_runner_provider.h"
+#include "components/viz/common/quads/stream_video_draw_quad.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
+#include "components/viz/common/quads/yuv_video_draw_quad.h"
+#include "components/viz/common/resources/single_release_callback.h"
#include "media/base/video_frame.h"
#include "ui/gfx/color_space.h"
@@ -76,7 +76,7 @@ void VideoLayerImpl::DidBecomeActive() {
}
bool VideoLayerImpl::WillDraw(DrawMode draw_mode,
- ResourceProvider* resource_provider) {
+ LayerTreeResourceProvider* resource_provider) {
if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE)
return false;
@@ -129,7 +129,7 @@ bool VideoLayerImpl::WillDraw(DrawMode draw_mode,
for (size_t i = 0; i < external_resources.mailboxes.size(); ++i) {
unsigned resource_id = resource_provider->CreateResourceFromTextureMailbox(
external_resources.mailboxes[i],
- SingleReleaseCallbackImpl::Create(
+ viz::SingleReleaseCallback::Create(
external_resources.release_callbacks[i]),
external_resources.read_lock_fences_enabled,
external_resources.buffer_format);
@@ -142,7 +142,7 @@ bool VideoLayerImpl::WillDraw(DrawMode draw_mode,
return true;
}
-void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
+void VideoLayerImpl::AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) {
DCHECK(frame_.get());
@@ -169,13 +169,14 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
viz::SharedQuadState* shared_quad_state =
render_pass->CreateAndAppendSharedQuadState();
- shared_quad_state->SetAll(transform, gfx::Rect(rotated_size),
- visible_layer_rect(), clip_rect(), is_clipped(),
+ gfx::Rect rotated_size_rect(rotated_size);
+ shared_quad_state->SetAll(transform, rotated_size_rect, visible_layer_rect(),
+ clip_rect(), is_clipped(), contents_opaque(),
draw_opacity(), SkBlendMode::kSrcOver,
GetSortingContextId());
- AppendDebugBorderQuad(
- render_pass, rotated_size, shared_quad_state, append_quads_data);
+ AppendDebugBorderQuad(render_pass, rotated_size_rect, shared_quad_state,
+ append_quads_data);
gfx::Rect quad_rect(rotated_size);
gfx::Rect visible_rect = frame_->visible_rect();
@@ -209,8 +210,8 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
bool flipped = false;
bool nearest_neighbor = false;
- TextureDrawQuad* texture_quad =
- render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
+ auto* texture_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::TextureDrawQuad>();
texture_quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect,
needs_blending, software_resources_[0],
premultiplied_alpha, uv_top_left, uv_bottom_right,
@@ -220,20 +221,24 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
break;
}
case VideoFrameExternalResources::YUV_RESOURCE: {
- YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::REC_601;
+ auto color_space = viz::YUVVideoDrawQuad::REC_601;
int videoframe_color_space;
if (frame_->metadata()->GetInteger(media::VideoFrameMetadata::COLOR_SPACE,
&videoframe_color_space)) {
if (videoframe_color_space == media::COLOR_SPACE_JPEG) {
- color_space = YUVVideoDrawQuad::JPEG;
+ color_space = viz::YUVVideoDrawQuad::JPEG;
} else if (videoframe_color_space == media::COLOR_SPACE_HD_REC709) {
- color_space = YUVVideoDrawQuad::REC_709;
+ color_space = viz::YUVVideoDrawQuad::REC_709;
}
}
const gfx::Size ya_tex_size = coded_size;
- gfx::Size uv_tex_size = media::VideoFrame::PlaneSize(
- frame_->format(), media::VideoFrame::kUPlane, coded_size);
+
+ int u_width = media::VideoFrame::Columns(
+ media::VideoFrame::kUPlane, frame_->format(), coded_size.width());
+ int u_height = media::VideoFrame::Rows(
+ media::VideoFrame::kUPlane, frame_->format(), coded_size.height());
+ gfx::Size uv_tex_size(u_width, u_height);
if (frame_->HasTextures()) {
if (frame_->format() == media::PIXEL_FORMAT_NV12) {
@@ -244,9 +249,6 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
frame_resources_.size()); // Alpha is not supported yet.
}
} else {
- DCHECK(uv_tex_size ==
- media::VideoFrame::PlaneSize(
- frame_->format(), media::VideoFrame::kVPlane, coded_size));
DCHECK_GE(frame_resources_.size(), 3u);
DCHECK(frame_resources_.size() <= 3 ||
ya_tex_size == media::VideoFrame::PlaneSize(
@@ -267,8 +269,8 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
visible_rect.width() / uv_subsampling_factor_x,
visible_rect.height() / uv_subsampling_factor_y);
- YUVVideoDrawQuad* yuv_video_quad =
- render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>();
+ auto* yuv_video_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::YUVVideoDrawQuad>();
yuv_video_quad->SetNew(
shared_quad_state, quad_rect, visible_quad_rect, needs_blending,
ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size, uv_tex_size,
@@ -297,8 +299,8 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
bool flipped = false;
bool nearest_neighbor = false;
- TextureDrawQuad* texture_quad =
- render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
+ auto* texture_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::TextureDrawQuad>();
texture_quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect,
needs_blending, frame_resources_[0].id,
premultiplied_alpha, uv_top_left, uv_bottom_right,
@@ -314,8 +316,8 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
break;
gfx::Transform scale;
scale.Scale(tex_width_scale, tex_height_scale);
- StreamVideoDrawQuad* stream_video_quad =
- render_pass->CreateAndAppendDrawQuad<StreamVideoDrawQuad>();
+ auto* stream_video_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::StreamVideoDrawQuad>();
stream_video_quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect,
needs_blending, frame_resources_[0].id,
frame_resources_[0].size_in_pixels, scale);
@@ -328,7 +330,7 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
}
}
-void VideoLayerImpl::DidDraw(ResourceProvider* resource_provider) {
+void VideoLayerImpl::DidDraw(LayerTreeResourceProvider* resource_provider) {
LayerImpl::DidDraw(resource_provider);
DCHECK(frame_.get());
@@ -336,10 +338,7 @@ void VideoLayerImpl::DidDraw(ResourceProvider* resource_provider) {
if (frame_resource_type_ ==
VideoFrameExternalResources::SOFTWARE_RESOURCE) {
for (size_t i = 0; i < software_resources_.size(); ++i) {
- software_release_callback_.Run(gpu::SyncToken(), false,
- layer_tree_impl()
- ->task_runner_provider()
- ->blocking_main_thread_task_runner());
+ software_release_callback_.Run(gpu::SyncToken(), false);
}
software_resources_.clear();
diff --git a/chromium/cc/layers/video_layer_impl.h b/chromium/cc/layers/video_layer_impl.h
index 391e6c362df..5510189cada 100644
--- a/chromium/cc/layers/video_layer_impl.h
+++ b/chromium/cc/layers/video_layer_impl.h
@@ -10,8 +10,8 @@
#include "base/macros.h"
#include "cc/cc_export.h"
#include "cc/layers/layer_impl.h"
-#include "cc/resources/release_callback_impl.h"
#include "cc/resources/video_resource_updater.h"
+#include "components/viz/common/resources/release_callback.h"
#include "media/base/video_rotation.h"
namespace media {
@@ -36,10 +36,10 @@ class CC_EXPORT VideoLayerImpl : public LayerImpl {
// LayerImpl implementation.
std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
bool WillDraw(DrawMode draw_mode,
- ResourceProvider* resource_provider) override;
- void AppendQuads(RenderPass* render_pass,
+ LayerTreeResourceProvider* resource_provider) override;
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override;
- void DidDraw(ResourceProvider* resource_provider) override;
+ void DidDraw(LayerTreeResourceProvider* resource_provider) override;
SimpleEnclosedRegion VisibleOpaqueRegion() const override;
void DidBecomeActive() override;
void ReleaseResources() override;
@@ -85,7 +85,7 @@ class CC_EXPORT VideoLayerImpl : public LayerImpl {
// ExternalResource (aka TextureMailbox) classes.
std::vector<unsigned> software_resources_;
// Called once for each software resource.
- ReleaseCallbackImpl software_release_callback_;
+ viz::ReleaseCallback software_release_callback_;
DISALLOW_COPY_AND_ASSIGN(VideoLayerImpl);
};
diff --git a/chromium/cc/layers/video_layer_impl_unittest.cc b/chromium/cc/layers/video_layer_impl_unittest.cc
index 7f0adc3d69d..04057aabc77 100644
--- a/chromium/cc/layers/video_layer_impl_unittest.cc
+++ b/chromium/cc/layers/video_layer_impl_unittest.cc
@@ -7,15 +7,15 @@
#include <stddef.h>
#include "cc/layers/video_frame_provider_client_impl.h"
-#include "cc/output/output_surface.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/stream_video_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
-#include "cc/quads/yuv_video_draw_quad.h"
#include "cc/test/fake_video_frame_provider.h"
#include "cc/test/layer_test_common.h"
#include "cc/trees/single_thread_proxy.h"
#include "components/viz/common/gpu/context_provider.h"
+#include "components/viz/common/quads/draw_quad.h"
+#include "components/viz/common/quads/stream_video_draw_quad.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
+#include "components/viz/common/quads/yuv_video_draw_quad.h"
+#include "components/viz/service/display/output_surface.h"
#include "media/base/video_frame.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -320,17 +320,53 @@ TEST(VideoLayerImplTest, SoftwareVideoFrameGeneratesYUVQuad) {
impl.AppendQuadsWithOcclusion(video_layer_impl, occluded);
EXPECT_EQ(1u, impl.quad_list().size());
- const DrawQuad* draw_quad = impl.quad_list().ElementAt(0);
- ASSERT_EQ(DrawQuad::YUV_VIDEO_CONTENT, draw_quad->material);
+ const viz::DrawQuad* draw_quad = impl.quad_list().ElementAt(0);
+ ASSERT_EQ(viz::DrawQuad::YUV_VIDEO_CONTENT, draw_quad->material);
- const YUVVideoDrawQuad* yuv_draw_quad =
- static_cast<const YUVVideoDrawQuad*>(draw_quad);
+ const auto* yuv_draw_quad =
+ static_cast<const viz::YUVVideoDrawQuad*>(draw_quad);
EXPECT_EQ(yuv_draw_quad->uv_tex_size.height(),
(yuv_draw_quad->ya_tex_size.height() + 1) / 2);
EXPECT_EQ(yuv_draw_quad->uv_tex_size.width(),
(yuv_draw_quad->ya_tex_size.width() + 1) / 2);
}
+TEST(VideoLayerImplTest, HibitSoftwareVideoFrameGeneratesYUVQuad) {
+ gfx::Size layer_size(1000, 1000);
+ gfx::Size viewport_size(1000, 1000);
+
+ LayerTestCommon::LayerImplTest impl;
+ DebugSetImplThreadAndMainThreadBlocked(impl.task_runner_provider());
+
+ gpu::MailboxHolder mailbox_holder;
+ mailbox_holder.mailbox.name[0] = 1;
+
+ scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame(
+ media::PIXEL_FORMAT_YUV420P10, gfx::Size(20, 10), gfx::Rect(20, 10),
+ gfx::Size(20, 10), base::TimeDelta());
+
+ FakeVideoFrameProvider provider;
+ provider.set_frame(video_frame);
+
+ VideoLayerImpl* video_layer_impl =
+ impl.AddChildToRoot<VideoLayerImpl>(&provider, media::VIDEO_ROTATION_0);
+ video_layer_impl->SetBounds(layer_size);
+ video_layer_impl->SetDrawsContent(true);
+ impl.host_impl()->active_tree()->BuildLayerListAndPropertyTreesForTesting();
+
+ gfx::Rect occluded;
+ impl.AppendQuadsWithOcclusion(video_layer_impl, occluded);
+
+ EXPECT_EQ(1u, impl.quad_list().size());
+ const viz::DrawQuad* draw_quad = impl.quad_list().ElementAt(0);
+ ASSERT_EQ(viz::DrawQuad::YUV_VIDEO_CONTENT, draw_quad->material);
+
+ const auto* yuv_draw_quad =
+ static_cast<const viz::YUVVideoDrawQuad*>(draw_quad);
+ EXPECT_EQ(5, yuv_draw_quad->uv_tex_size.height());
+ EXPECT_EQ(10, yuv_draw_quad->uv_tex_size.width());
+}
+
TEST(VideoLayerImplTest, NativeYUVFrameGeneratesYUVQuad) {
gfx::Size layer_size(1000, 1000);
gfx::Size viewport_size(1000, 1000);
@@ -366,11 +402,11 @@ TEST(VideoLayerImplTest, NativeYUVFrameGeneratesYUVQuad) {
impl.AppendQuadsWithOcclusion(video_layer_impl, occluded);
EXPECT_EQ(1u, impl.quad_list().size());
- const DrawQuad* draw_quad = impl.quad_list().ElementAt(0);
- ASSERT_EQ(DrawQuad::YUV_VIDEO_CONTENT, draw_quad->material);
+ const viz::DrawQuad* draw_quad = impl.quad_list().ElementAt(0);
+ ASSERT_EQ(viz::DrawQuad::YUV_VIDEO_CONTENT, draw_quad->material);
- const YUVVideoDrawQuad* yuv_draw_quad =
- static_cast<const YUVVideoDrawQuad*>(draw_quad);
+ const auto* yuv_draw_quad =
+ static_cast<const viz::YUVVideoDrawQuad*>(draw_quad);
EXPECT_EQ(yuv_draw_quad->uv_tex_size.height(),
(yuv_draw_quad->ya_tex_size.height() + 1) / 2);
EXPECT_EQ(yuv_draw_quad->uv_tex_size.width(),
@@ -410,11 +446,11 @@ TEST(VideoLayerImplTest, NativeARGBFrameGeneratesTextureQuad) {
impl.AppendQuadsWithOcclusion(video_layer_impl, occluded);
EXPECT_EQ(1u, impl.quad_list().size());
- const DrawQuad* draw_quad = impl.quad_list().ElementAt(0);
- ASSERT_EQ(DrawQuad::TEXTURE_CONTENT, draw_quad->material);
+ const viz::DrawQuad* draw_quad = impl.quad_list().ElementAt(0);
+ ASSERT_EQ(viz::DrawQuad::TEXTURE_CONTENT, draw_quad->material);
- const TextureDrawQuad* texture_draw_quad =
- TextureDrawQuad::MaterialCast(draw_quad);
+ const viz::TextureDrawQuad* texture_draw_quad =
+ viz::TextureDrawQuad::MaterialCast(draw_quad);
EXPECT_EQ(texture_draw_quad->resource_size_in_pixels(), resource_size);
}
diff --git a/chromium/cc/output/DEPS b/chromium/cc/output/DEPS
deleted file mode 100644
index a9f67a56bf9..00000000000
--- a/chromium/cc/output/DEPS
+++ /dev/null
@@ -1,9 +0,0 @@
-include_rules = [
- "+mojo/public/cpp/bindings/struct_traits.h",
-]
-
-specific_include_rules = {
- ".*_(unit|pixel)test\.cc": [
- "+components/viz/service/display",
- ]
-}
diff --git a/chromium/cc/output/bsp_compare_result.h b/chromium/cc/output/bsp_compare_result.h
deleted file mode 100644
index cdd251fbc81..00000000000
--- a/chromium/cc/output/bsp_compare_result.h
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_BSP_COMPARE_RESULT_H_
-#define CC_OUTPUT_BSP_COMPARE_RESULT_H_
-
-namespace cc {
-
-enum BspCompareResult {
- BSP_FRONT,
- BSP_BACK,
- BSP_SPLIT,
- BSP_COPLANAR_FRONT,
- BSP_COPLANAR_BACK,
- BSP_COPLANAR,
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_BSP_COMPARE_RESULT_H_
diff --git a/chromium/cc/output/bsp_tree.cc b/chromium/cc/output/bsp_tree.cc
deleted file mode 100644
index 964b4881cb4..00000000000
--- a/chromium/cc/output/bsp_tree.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/bsp_tree.h"
-
-#include <memory>
-#include <vector>
-
-#include "base/memory/ptr_util.h"
-#include "cc/base/container_util.h"
-#include "cc/output/bsp_compare_result.h"
-#include "cc/quads/draw_polygon.h"
-
-namespace cc {
-
-BspNode::BspNode(std::unique_ptr<DrawPolygon> data)
- : node_data(std::move(data)) {}
-
-BspNode::~BspNode() {
-}
-
-BspTree::BspTree(std::deque<std::unique_ptr<DrawPolygon>>* list) {
- if (list->size() == 0)
- return;
-
- root_ = std::make_unique<BspNode>(PopFront(list));
- BuildTree(root_.get(), list);
-}
-
-// The idea behind using a deque for BuildTree's input is that we want to be
-// able to place polygons that we've decided aren't splitting plane candidates
-// at the back of the queue while moving the candidate splitting planes to the
-// front when the heuristic decides that they're a better choice. This way we
-// can always simply just take from the front of the deque for our node's
-// data.
-void BspTree::BuildTree(
- BspNode* node,
- std::deque<std::unique_ptr<DrawPolygon>>* polygon_list) {
- std::deque<std::unique_ptr<DrawPolygon>> front_list;
- std::deque<std::unique_ptr<DrawPolygon>> back_list;
-
- // We take in a list of polygons at this level of the tree, and have to
- // find a splitting plane, then classify polygons as either in front of
- // or behind that splitting plane.
- while (!polygon_list->empty()) {
- std::unique_ptr<DrawPolygon> polygon;
- std::unique_ptr<DrawPolygon> new_front;
- std::unique_ptr<DrawPolygon> new_back;
- // Time to split this geometry, *it needs to be split by node_data.
- polygon = PopFront(polygon_list);
- bool is_coplanar;
- node->node_data->SplitPolygon(std::move(polygon), &new_front, &new_back,
- &is_coplanar);
- if (is_coplanar) {
- if (new_front)
- node->coplanars_front.push_back(std::move(new_front));
- if (new_back)
- node->coplanars_back.push_back(std::move(new_back));
- } else {
- if (new_front)
- front_list.push_back(std::move(new_front));
- if (new_back)
- back_list.push_back(std::move(new_back));
- }
- }
-
- // Build the back subtree using the front of the back_list as our splitter.
- if (back_list.size() > 0) {
- node->back_child = std::make_unique<BspNode>(PopFront(&back_list));
- BuildTree(node->back_child.get(), &back_list);
- }
-
- // Build the front subtree using the front of the front_list as our splitter.
- if (front_list.size() > 0) {
- node->front_child = std::make_unique<BspNode>(PopFront(&front_list));
- BuildTree(node->front_child.get(), &front_list);
- }
-}
-
-// The base comparer with 0,0,0 as camera position facing forward
-BspCompareResult BspTree::GetCameraPositionRelative(const DrawPolygon& node) {
- if (node.normal().z() > 0.0f) {
- return BSP_FRONT;
- }
- return BSP_BACK;
-}
-
-BspTree::~BspTree() {
-}
-
-} // namespace cc
diff --git a/chromium/cc/output/bsp_tree.h b/chromium/cc/output/bsp_tree.h
deleted file mode 100644
index 65c601b4a94..00000000000
--- a/chromium/cc/output/bsp_tree.h
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_BSP_TREE_H_
-#define CC_OUTPUT_BSP_TREE_H_
-
-#include <stddef.h>
-
-#include <deque>
-#include <memory>
-#include <vector>
-
-#include "cc/output/bsp_compare_result.h"
-#include "cc/quads/draw_polygon.h"
-
-namespace cc {
-
-struct BspNode {
- // This represents the splitting plane.
- std::unique_ptr<DrawPolygon> node_data;
- // This represents any coplanar geometry we found while building the BSP.
- std::vector<std::unique_ptr<DrawPolygon>> coplanars_front;
- std::vector<std::unique_ptr<DrawPolygon>> coplanars_back;
-
- std::unique_ptr<BspNode> back_child;
- std::unique_ptr<BspNode> front_child;
-
- explicit BspNode(std::unique_ptr<DrawPolygon> data);
- ~BspNode();
-};
-
-class CC_EXPORT BspTree {
- public:
- explicit BspTree(std::deque<std::unique_ptr<DrawPolygon>>* list);
- std::unique_ptr<BspNode>& root() { return root_; }
-
- template <typename ActionHandlerType>
- void TraverseWithActionHandler(ActionHandlerType* action_handler) const {
- if (root_) {
- WalkInOrderRecursion<ActionHandlerType>(action_handler, root_.get());
- }
- }
-
- ~BspTree();
-
- private:
- std::unique_ptr<BspNode> root_;
-
- void FromList(std::vector<std::unique_ptr<DrawPolygon>>* list);
- void BuildTree(BspNode* node, std::deque<std::unique_ptr<DrawPolygon>>* data);
-
- template <typename ActionHandlerType>
- void WalkInOrderAction(ActionHandlerType* action_handler,
- DrawPolygon* item) const {
- (*action_handler)(item);
- }
-
- template <typename ActionHandlerType>
- void WalkInOrderVisitNodes(
- ActionHandlerType* action_handler,
- const BspNode* node,
- const BspNode* first_child,
- const BspNode* second_child,
- const std::vector<std::unique_ptr<DrawPolygon>>& first_coplanars,
- const std::vector<std::unique_ptr<DrawPolygon>>& second_coplanars) const {
- if (first_child) {
- WalkInOrderRecursion(action_handler, first_child);
- }
- for (size_t i = 0; i < first_coplanars.size(); i++) {
- WalkInOrderAction(action_handler, first_coplanars[i].get());
- }
- WalkInOrderAction(action_handler, node->node_data.get());
- for (size_t i = 0; i < second_coplanars.size(); i++) {
- WalkInOrderAction(action_handler, second_coplanars[i].get());
- }
- if (second_child) {
- WalkInOrderRecursion(action_handler, second_child);
- }
- }
-
- template <typename ActionHandlerType>
- void WalkInOrderRecursion(ActionHandlerType* action_handler,
- const BspNode* node) const {
- // If our view is in front of the the polygon
- // in this node then walk back then front.
- if (GetCameraPositionRelative(*(node->node_data)) == BSP_FRONT) {
- WalkInOrderVisitNodes<ActionHandlerType>(action_handler,
- node,
- node->back_child.get(),
- node->front_child.get(),
- node->coplanars_front,
- node->coplanars_back);
- } else {
- WalkInOrderVisitNodes<ActionHandlerType>(action_handler,
- node,
- node->front_child.get(),
- node->back_child.get(),
- node->coplanars_back,
- node->coplanars_front);
- }
- }
-
- // Returns whether or not our viewer is in front of or behind the plane
- // defined by this polygon/node
- static BspCompareResult GetCameraPositionRelative(const DrawPolygon& node);
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_BSP_TREE_H_
diff --git a/chromium/cc/output/bsp_tree_perftest.cc b/chromium/cc/output/bsp_tree_perftest.cc
deleted file mode 100644
index d297eb0094f..00000000000
--- a/chromium/cc/output/bsp_tree_perftest.cc
+++ /dev/null
@@ -1,188 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <stddef.h>
-
-#include <deque>
-#include <memory>
-#include <sstream>
-
-#include "base/files/file_path.h"
-#include "base/files/file_util.h"
-#include "base/path_service.h"
-#include "base/strings/string_piece.h"
-#include "base/threading/thread.h"
-#include "base/time/time.h"
-#include "cc/base/lap_timer.h"
-#include "cc/layers/layer.h"
-#include "cc/output/bsp_tree.h"
-#include "cc/quads/draw_polygon.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/test/fake_content_layer_client.h"
-#include "cc/test/fake_layer_tree_host_client.h"
-#include "cc/test/layer_tree_json_parser.h"
-#include "cc/test/layer_tree_test.h"
-#include "cc/trees/layer_tree_host_common.h"
-#include "cc/trees/layer_tree_impl.h"
-#include "components/viz/test/paths.h"
-#include "testing/perf/perf_test.h"
-
-namespace cc {
-namespace {
-
-static const int kTimeLimitMillis = 2000;
-static const int kWarmupRuns = 5;
-static const int kTimeCheckInterval = 10;
-
-class BspTreePerfTest : public LayerTreeTest {
- public:
- BspTreePerfTest()
- : timer_(kWarmupRuns,
- base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
- kTimeCheckInterval) {}
-
- void SetupTree() override {
- gfx::Size viewport = gfx::Size(720, 1038);
- layer_tree_host()->SetViewportSize(viewport);
- scoped_refptr<Layer> root =
- ParseTreeFromJson(json_, &content_layer_client_);
- ASSERT_TRUE(root.get());
- layer_tree_host()->SetRootLayer(root);
- content_layer_client_.set_bounds(viewport);
- }
-
- void SetTestName(const std::string& name) { test_name_ = name; }
-
- void SetNumberOfDuplicates(int num_duplicates) {
- num_duplicates_ = num_duplicates;
- }
-
- void ReadTestFile(const std::string& name) {
- base::FilePath test_data_dir;
- ASSERT_TRUE(PathService::Get(viz::Paths::DIR_TEST_DATA, &test_data_dir));
- base::FilePath json_file = test_data_dir.AppendASCII(name + ".json");
- ASSERT_TRUE(base::ReadFileToString(json_file, &json_));
- }
-
- void BeginTest() override { PostSetNeedsCommitToMainThread(); }
-
- void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
- LayerTreeImpl* active_tree = host_impl->active_tree();
- // First build the tree and then we'll start running tests on layersorter
- // itself
- int max_texture_size = 8096;
- DoCalcDrawPropertiesImpl(max_texture_size, active_tree, host_impl);
-
- LayerImplList base_list;
- BuildLayerImplList(active_tree->root_layer_for_testing(), &base_list);
-
- int polygon_counter = 0;
- std::vector<std::unique_ptr<DrawPolygon>> polygon_list;
- for (LayerImplList::iterator it = base_list.begin(); it != base_list.end();
- ++it) {
- DrawPolygon* draw_polygon = new DrawPolygon(
- NULL, gfx::RectF(gfx::SizeF((*it)->bounds())),
- (*it)->draw_properties().target_space_transform, polygon_counter++);
- polygon_list.push_back(std::unique_ptr<DrawPolygon>(draw_polygon));
- }
-
- timer_.Reset();
- do {
- std::deque<std::unique_ptr<DrawPolygon>> test_list;
- for (int i = 0; i < num_duplicates_; i++) {
- for (size_t i = 0; i < polygon_list.size(); i++) {
- test_list.push_back(polygon_list[i]->CreateCopy());
- }
- }
- BspTree bsp_tree(&test_list);
- timer_.NextLap();
- } while (!timer_.HasTimeLimitExpired());
-
- EndTest();
- }
-
- void DoCalcDrawPropertiesImpl(int max_texture_size,
- LayerTreeImpl* active_tree,
- LayerTreeHostImpl* host_impl) {
- RenderSurfaceList update_list;
- LayerTreeHostCommon::CalcDrawPropsImplInputs inputs(
- active_tree->root_layer_for_testing(),
- active_tree->DeviceViewport().size(), host_impl->DrawTransform(),
- active_tree->device_scale_factor(),
- active_tree->current_page_scale_factor(),
- active_tree->InnerViewportContainerLayer(),
- active_tree->InnerViewportScrollLayer(),
- active_tree->OuterViewportScrollLayer(),
- active_tree->elastic_overscroll()->Current(active_tree->IsActiveTree()),
- active_tree->OverscrollElasticityLayer(), max_texture_size,
- host_impl->settings().layer_transforms_should_scale_layer_contents,
- &update_list, active_tree->property_trees());
- LayerTreeHostCommon::CalculateDrawProperties(&inputs);
- }
-
- void BuildLayerImplList(LayerImpl* layer, LayerImplList* list) {
- for (auto* layer_impl : *layer->layer_tree_impl()) {
- if (layer_impl->Is3dSorted() && !layer_impl->bounds().IsEmpty()) {
- list->push_back(layer_impl);
- }
- }
- }
-
- void AfterTest() override {
- CHECK(!test_name_.empty()) << "Must SetTestName() before TearDown().";
- perf_test::PrintResult("calc_draw_props_time", "", test_name_,
- 1000 * timer_.MsPerLap(), "us", true);
- }
-
- private:
- FakeContentLayerClient content_layer_client_;
- LapTimer timer_;
- std::string test_name_;
- std::string json_;
- LayerImplList base_list_;
- int num_duplicates_ = 1;
-};
-
-TEST_F(BspTreePerfTest, LayerSorterCubes) {
- SetTestName("layer_sort_cubes");
- ReadTestFile("layer_sort_cubes");
- RunTest(CompositorMode::SINGLE_THREADED);
-}
-
-TEST_F(BspTreePerfTest, LayerSorterRubik) {
- SetTestName("layer_sort_rubik");
- ReadTestFile("layer_sort_rubik");
- RunTest(CompositorMode::SINGLE_THREADED);
-}
-
-TEST_F(BspTreePerfTest, BspTreeCubes) {
- SetTestName("bsp_tree_cubes");
- SetNumberOfDuplicates(1);
- ReadTestFile("layer_sort_cubes");
- RunTest(CompositorMode::SINGLE_THREADED);
-}
-
-TEST_F(BspTreePerfTest, BspTreeRubik) {
- SetTestName("bsp_tree_rubik");
- SetNumberOfDuplicates(1);
- ReadTestFile("layer_sort_rubik");
- RunTest(CompositorMode::SINGLE_THREADED);
-}
-
-TEST_F(BspTreePerfTest, BspTreeCubes_2) {
- SetTestName("bsp_tree_cubes_2");
- SetNumberOfDuplicates(2);
- ReadTestFile("layer_sort_cubes");
- RunTest(CompositorMode::SINGLE_THREADED);
-}
-
-TEST_F(BspTreePerfTest, BspTreeCubes_4) {
- SetTestName("bsp_tree_cubes_4");
- SetNumberOfDuplicates(4);
- ReadTestFile("layer_sort_cubes");
- RunTest(CompositorMode::SINGLE_THREADED);
-}
-
-} // namespace
-} // namespace cc
diff --git a/chromium/cc/output/bsp_tree_unittest.cc b/chromium/cc/output/bsp_tree_unittest.cc
deleted file mode 100644
index c787d3e7c49..00000000000
--- a/chromium/cc/output/bsp_tree_unittest.cc
+++ /dev/null
@@ -1,377 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/bsp_tree.h"
-
-#include <stddef.h>
-
-#include <deque>
-#include <memory>
-
-#include "base/macros.h"
-#include "cc/output/bsp_walk_action.h"
-#include "cc/quads/draw_polygon.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace cc {
-namespace {
-
-#define EXPECT_SORTED_LISTS_EQ(polygon_list, compare_list) \
- do { \
- EXPECT_EQ(polygon_list.size(), compare_list.size()); \
- for (unsigned int i = 0; i < polygon_list.size(); i++) { \
- EXPECT_EQ(polygon_list[i]->order_index(), compare_list[i]); \
- } \
- } while (false);
-
-#define INT_VECTOR_FROM_ARRAY(array) \
- std::vector<int>(array, array + arraysize(array))
-
-#define CREATE_DRAW_POLYGON(vertex_vector, normal, polygon_id) \
- new DrawPolygon(NULL, vertex_vector, normal, polygon_id)
-
-class BspTreeTest {
- public:
- static void RunTest(std::deque<std::unique_ptr<DrawPolygon>>* test_polygons,
- const std::vector<int>& compare_list) {
- BspTree bsp_tree(test_polygons);
-
- std::vector<DrawPolygon*> sorted_list;
- BspWalkActionToVector action_handler(&sorted_list);
- bsp_tree.TraverseWithActionHandler(&action_handler);
-
- EXPECT_SORTED_LISTS_EQ(sorted_list, compare_list);
- EXPECT_TRUE(VerifySidedness(bsp_tree.root()));
- }
-
- static BspCompareResult SideCompare(const DrawPolygon& a,
- const DrawPolygon& b) {
- const float split_threshold = 0.05f;
- bool pos = false;
- bool neg = false;
- for (const auto& pt : a.points()) {
- float dist = b.SignedPointDistance(pt);
- neg |= dist < -split_threshold;
- pos |= dist > split_threshold;
- }
- if (pos && neg)
- return BSP_SPLIT;
- if (neg)
- return BSP_BACK;
- if (pos)
- return BSP_FRONT;
- double dot = gfx::DotProduct(a.normal(), b.normal());
- if ((dot >= 0.0f && a.order_index() >= b.order_index()) ||
- (dot <= 0.0f && a.order_index() <= b.order_index())) {
- // The sign of the dot product of the normals along with document order
- // determine which side it goes on, the vertices are ambiguous.
- return BSP_COPLANAR_BACK;
- }
- return BSP_COPLANAR_FRONT;
- }
-
- static bool VerifySidedness(const std::unique_ptr<BspNode>& node) {
- // We check if both the front and back child nodes have geometry that is
- // completely on the expected side of the current node.
- bool front_ok = true;
- bool back_ok = true;
- if (node->back_child) {
- // Make sure the back child lies entirely behind this node.
- BspCompareResult result =
- SideCompare(*(node->back_child->node_data), *(node->node_data));
- if (result != BSP_BACK) {
- return false;
- }
- back_ok = VerifySidedness(node->back_child);
- }
- // Make sure the front child lies entirely in front of this node.
- if (node->front_child) {
- BspCompareResult result =
- SideCompare(*(node->front_child->node_data), *(node->node_data));
- if (result != BSP_FRONT) {
- return false;
- }
- front_ok = VerifySidedness(node->front_child);
- }
- if (!back_ok || !front_ok) {
- return false;
- }
-
- // Now we need to make sure our coplanar geometry is all actually coplanar.
- for (size_t i = 0; i < node->coplanars_front.size(); i++) {
- BspCompareResult result =
- SideCompare(*(node->coplanars_front[i]), *(node->node_data));
- if (result != BSP_COPLANAR_FRONT) {
- return false;
- }
- }
- for (size_t i = 0; i < node->coplanars_back.size(); i++) {
- BspCompareResult result =
- SideCompare(*(node->coplanars_back[i]), *(node->node_data));
- if (result != BSP_COPLANAR_BACK) {
- return false;
- }
- }
- return true;
- }
-};
-
-// Simple standing quads all parallel with each other, causing no splits.
-TEST(BspTreeTest, NoSplit) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(0.0f, 10.0f, -5.0f));
- vertices_b.push_back(gfx::Point3F(0.0f, 0.0f, -5.0f));
- vertices_b.push_back(gfx::Point3F(10.0f, 0.0f, -5.0f));
- vertices_b.push_back(gfx::Point3F(10.0f, 10.0f, -5.0f));
- std::vector<gfx::Point3F> vertices_c;
- vertices_c.push_back(gfx::Point3F(0.0f, 10.0f, 5.0f));
- vertices_c.push_back(gfx::Point3F(0.0f, 0.0f, 5.0f));
- vertices_c.push_back(gfx::Point3F(10.0f, 0.0f, 5.0f));
- vertices_c.push_back(gfx::Point3F(10.0f, 10.0f, 5.0f));
-
- std::unique_ptr<DrawPolygon> polygon_a(
- CREATE_DRAW_POLYGON(vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0));
- std::unique_ptr<DrawPolygon> polygon_b(
- CREATE_DRAW_POLYGON(vertices_b, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 1));
- std::unique_ptr<DrawPolygon> polygon_c(
- CREATE_DRAW_POLYGON(vertices_c, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 2));
-
- std::deque<std::unique_ptr<DrawPolygon>> polygon_list;
- polygon_list.push_back(std::move(polygon_a));
- polygon_list.push_back(std::move(polygon_b));
- polygon_list.push_back(std::move(polygon_c));
-
- int compare_ids[] = {1, 0, 2};
- std::vector<int> compare_list = INT_VECTOR_FROM_ARRAY(compare_ids);
- BspTreeTest::RunTest(&polygon_list, compare_list);
-}
-
-// Basic two polygon split, can be viewed as a + from above.
-TEST(BspTreeTest, BasicSplit) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(-5.0f, -5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(-5.0f, 5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(5.0f, 5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(5.0f, -5.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(0.0f, -5.0f, -5.0f));
- vertices_b.push_back(gfx::Point3F(0.0f, 5.0f, -5.0f));
- vertices_b.push_back(gfx::Point3F(0.0f, 5.0f, 5.0f));
- vertices_b.push_back(gfx::Point3F(0.0f, -5.0f, 5.0f));
-
- std::unique_ptr<DrawPolygon> polygon_a(
- CREATE_DRAW_POLYGON(vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0));
- std::unique_ptr<DrawPolygon> polygon_b(
- CREATE_DRAW_POLYGON(vertices_b, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1));
-
- std::deque<std::unique_ptr<DrawPolygon>> polygon_list;
- polygon_list.push_back(std::move(polygon_a));
- polygon_list.push_back(std::move(polygon_b));
-
- int compare_ids[] = {1, 0, 1};
- std::vector<int> compare_list = INT_VECTOR_FROM_ARRAY(compare_ids);
- BspTreeTest::RunTest(&polygon_list, compare_list);
-}
-
-// Same as above with the second quad offset so it doesn't intersect. One quad
-// should be very clearly on one side of the other, and no splitting should
-// occur.
-TEST(BspTreeTest, QuadOffset) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(-5.0f, -5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(-5.0f, 5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(5.0f, 5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(5.0f, -5.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(0.0f, 5.0f, -15.0f));
- vertices_b.push_back(gfx::Point3F(0.0f, -5.0f, -15.0f));
- vertices_b.push_back(gfx::Point3F(0.0f, -5.0f, -10.0f));
- vertices_b.push_back(gfx::Point3F(0.0f, 5.0f, -10.0f));
-
- std::unique_ptr<DrawPolygon> polygon_a(
- CREATE_DRAW_POLYGON(vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0));
- std::unique_ptr<DrawPolygon> polygon_b(
- CREATE_DRAW_POLYGON(vertices_b, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1));
-
- std::deque<std::unique_ptr<DrawPolygon>> polygon_list;
- polygon_list.push_back(std::move(polygon_a));
- polygon_list.push_back(std::move(polygon_b));
-
- int compare_ids[] = {1, 0};
- std::vector<int> compare_list = INT_VECTOR_FROM_ARRAY(compare_ids);
- BspTreeTest::RunTest(&polygon_list, compare_list);
-}
-
-// Same as above, but this time we change the order in which the quads are
-// inserted into the tree, causing one to actually cross the plane of the other
-// and cause a split.
-TEST(BspTreeTest, QuadOffsetSplit) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(-5.0f, -5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(-5.0f, 5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(5.0f, 5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(5.0f, -5.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(0.0f, -5.0f, -15.0f));
- vertices_b.push_back(gfx::Point3F(0.0f, 5.0f, -15.0f));
- vertices_b.push_back(gfx::Point3F(0.0f, 5.0f, -10.0f));
- vertices_b.push_back(gfx::Point3F(0.0f, -5.0f, -10.0f));
-
- std::unique_ptr<DrawPolygon> polygon_a(
- CREATE_DRAW_POLYGON(vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0));
- std::unique_ptr<DrawPolygon> polygon_b(
- CREATE_DRAW_POLYGON(vertices_b, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1));
-
- std::deque<std::unique_ptr<DrawPolygon>> polygon_list;
- polygon_list.push_back(std::move(polygon_b));
- polygon_list.push_back(std::move(polygon_a));
-
- int compare_ids[] = {0, 1, 0};
- std::vector<int> compare_list = INT_VECTOR_FROM_ARRAY(compare_ids);
- BspTreeTest::RunTest(&polygon_list, compare_list);
-}
-
-// In addition to what can be viewed as a + from above, another piece of
-// geometry is inserted to cut these pieces right in the middle, viewed as
-// a quad from overhead.
-TEST(BspTreeTest, ThreeWaySplit) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(-5.0f, -5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(-5.0f, 5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(5.0f, 5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(5.0f, -5.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(0.0f, -5.0f, -5.0f));
- vertices_b.push_back(gfx::Point3F(0.0f, 5.0f, -5.0f));
- vertices_b.push_back(gfx::Point3F(0.0f, 5.0f, 5.0f));
- vertices_b.push_back(gfx::Point3F(0.0f, -5.0f, 5.0f));
- std::vector<gfx::Point3F> vertices_c;
- vertices_c.push_back(gfx::Point3F(-5.0f, 0.0f, -5.0f));
- vertices_c.push_back(gfx::Point3F(-5.0f, 0.0f, 5.0f));
- vertices_c.push_back(gfx::Point3F(5.0f, 0.0f, 5.0f));
- vertices_c.push_back(gfx::Point3F(5.0f, 0.0f, -5.0f));
-
- std::unique_ptr<DrawPolygon> polygon_a(
- CREATE_DRAW_POLYGON(vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0));
- std::unique_ptr<DrawPolygon> polygon_b(
- CREATE_DRAW_POLYGON(vertices_b, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1));
- std::unique_ptr<DrawPolygon> polygon_c(
- CREATE_DRAW_POLYGON(vertices_c, gfx::Vector3dF(0.0f, 1.0f, 0.0f), 2));
-
- std::deque<std::unique_ptr<DrawPolygon>> polygon_list;
- polygon_list.push_back(std::move(polygon_a));
- polygon_list.push_back(std::move(polygon_b));
- polygon_list.push_back(std::move(polygon_c));
-
- int compare_ids[] = {2, 1, 2, 0, 2, 1, 2};
- std::vector<int> compare_list = INT_VECTOR_FROM_ARRAY(compare_ids);
- BspTreeTest::RunTest(&polygon_list, compare_list);
-}
-
-// This test checks whether coplanar geometry, when inserted into the tree in
-// order, comes back in the same order as it should.
-TEST(BspTreeTest, Coplanar) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(-5.0f, -5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(-5.0f, 5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(5.0f, 5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(5.0f, -5.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(-4.0f, -4.0f, 0.0f));
- vertices_b.push_back(gfx::Point3F(-4.0f, 4.0f, 0.0f));
- vertices_b.push_back(gfx::Point3F(4.0f, 4.0f, 0.0f));
- vertices_b.push_back(gfx::Point3F(4.0f, -4.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_c;
- vertices_c.push_back(gfx::Point3F(-3.0f, -3.0f, 0.0f));
- vertices_c.push_back(gfx::Point3F(-3.0f, 3.0f, 0.0f));
- vertices_c.push_back(gfx::Point3F(3.0f, 3.0f, 0.0f));
- vertices_c.push_back(gfx::Point3F(3.0f, -3.0f, 0.0f));
-
- std::unique_ptr<DrawPolygon> polygon_a(
- CREATE_DRAW_POLYGON(vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0));
- std::unique_ptr<DrawPolygon> polygon_b(
- CREATE_DRAW_POLYGON(vertices_b, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 1));
- std::unique_ptr<DrawPolygon> polygon_c(
- CREATE_DRAW_POLYGON(vertices_c, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 2));
-
- std::unique_ptr<DrawPolygon> polygon_d = polygon_a->CreateCopy();
- std::unique_ptr<DrawPolygon> polygon_e = polygon_b->CreateCopy();
- std::unique_ptr<DrawPolygon> polygon_f = polygon_c->CreateCopy();
-
- {
- std::deque<std::unique_ptr<DrawPolygon>> polygon_list;
- polygon_list.push_back(std::move(polygon_a));
- polygon_list.push_back(std::move(polygon_b));
- polygon_list.push_back(std::move(polygon_c));
-
- int compare_ids[] = {0, 1, 2};
- std::vector<int> compare_list = INT_VECTOR_FROM_ARRAY(compare_ids);
- BspTreeTest::RunTest(&polygon_list, compare_list);
- }
-
- // Now check a different order and ensure we get that back as well
- {
- std::deque<std::unique_ptr<DrawPolygon>> polygon_list;
- polygon_list.push_back(std::move(polygon_f));
- polygon_list.push_back(std::move(polygon_d));
- polygon_list.push_back(std::move(polygon_e));
-
- int compare_ids[] = {0, 1, 2};
- std::vector<int> compare_list = INT_VECTOR_FROM_ARRAY(compare_ids);
- BspTreeTest::RunTest(&polygon_list, compare_list);
- }
-}
-
-// A bunch of coplanar geometry should end up sharing a single node, and
-// result in the final piece of geometry splitting into just two pieces on
-// either side of the shared plane.
-TEST(BspTreeTest, CoplanarSplit) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(-5.0f, -5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(-5.0f, 5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(5.0f, 5.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(5.0f, -5.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(-4.0f, -4.0f, 0.0f));
- vertices_b.push_back(gfx::Point3F(-4.0f, 4.0f, 0.0f));
- vertices_b.push_back(gfx::Point3F(4.0f, 4.0f, 0.0f));
- vertices_b.push_back(gfx::Point3F(4.0f, -4.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_c;
- vertices_c.push_back(gfx::Point3F(-3.0f, -3.0f, 0.0f));
- vertices_c.push_back(gfx::Point3F(-3.0f, 3.0f, 0.0f));
- vertices_c.push_back(gfx::Point3F(3.0f, 3.0f, 0.0f));
- vertices_c.push_back(gfx::Point3F(3.0f, -3.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_d;
- vertices_d.push_back(gfx::Point3F(0.0f, -15.0f, -15.0f));
- vertices_d.push_back(gfx::Point3F(0.0f, 15.0f, -15.0f));
- vertices_d.push_back(gfx::Point3F(0.0f, 15.0f, 15.0f));
- vertices_d.push_back(gfx::Point3F(0.0f, -15.0f, 15.0f));
-
- std::unique_ptr<DrawPolygon> polygon_a(
- CREATE_DRAW_POLYGON(vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0));
- std::unique_ptr<DrawPolygon> polygon_b(
- CREATE_DRAW_POLYGON(vertices_b, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 1));
- std::unique_ptr<DrawPolygon> polygon_c(
- CREATE_DRAW_POLYGON(vertices_c, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 2));
- std::unique_ptr<DrawPolygon> polygon_d(
- CREATE_DRAW_POLYGON(vertices_d, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 3));
-
- std::deque<std::unique_ptr<DrawPolygon>> polygon_list;
- polygon_list.push_back(std::move(polygon_a));
- polygon_list.push_back(std::move(polygon_b));
- polygon_list.push_back(std::move(polygon_c));
- polygon_list.push_back(std::move(polygon_d));
-
- int compare_ids[] = {3, 0, 1, 2, 3};
- std::vector<int> compare_list = INT_VECTOR_FROM_ARRAY(compare_ids);
- BspTreeTest::RunTest(&polygon_list, compare_list);
-}
-
-} // namespace
-} // namespace cc
diff --git a/chromium/cc/output/bsp_walk_action.cc b/chromium/cc/output/bsp_walk_action.cc
deleted file mode 100644
index 5acbc500445..00000000000
--- a/chromium/cc/output/bsp_walk_action.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/bsp_walk_action.h"
-
-#include <memory>
-#include <vector>
-
-#include "cc/output/direct_renderer.h"
-#include "cc/quads/draw_polygon.h"
-#include "cc/quads/draw_quad.h"
-
-namespace cc {
-
-BspWalkActionDrawPolygon::BspWalkActionDrawPolygon(
- DirectRenderer* renderer,
- const gfx::Rect& render_pass_scissor,
- bool using_scissor_as_optimization)
- : renderer_(renderer),
- render_pass_scissor_(render_pass_scissor),
- using_scissor_as_optimization_(using_scissor_as_optimization) {
-}
-
-void BspWalkActionDrawPolygon::operator()(DrawPolygon* item) {
- gfx::Transform inverse_transform;
- bool invertible =
- item->original_ref()
- ->shared_quad_state->quad_to_target_transform.GetInverse(
- &inverse_transform);
- DCHECK(invertible);
- item->TransformToLayerSpace(inverse_transform);
- renderer_->DoDrawPolygon(*item, render_pass_scissor_,
- using_scissor_as_optimization_);
-}
-
-BspWalkActionToVector::BspWalkActionToVector(std::vector<DrawPolygon*>* in_list)
- : list_(in_list) {
-}
-
-void BspWalkActionToVector::operator()(DrawPolygon* item) {
- list_->push_back(item);
-}
-
-} // namespace cc
diff --git a/chromium/cc/output/bsp_walk_action.h b/chromium/cc/output/bsp_walk_action.h
deleted file mode 100644
index a3d26a57b06..00000000000
--- a/chromium/cc/output/bsp_walk_action.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_BSP_WALK_ACTION_H_
-#define CC_OUTPUT_BSP_WALK_ACTION_H_
-
-#include <memory>
-#include <vector>
-
-#include "cc/output/direct_renderer.h"
-#include "cc/quads/draw_polygon.h"
-
-namespace cc {
-
-class CC_EXPORT BspWalkAction {
- public:
- virtual void operator()(DrawPolygon* item) = 0;
-};
-
-// The BspTree class takes ownership of all the DrawPolygons returned in list_
-// so the BspTree must be preserved while elements in that vector are in use.
-class CC_EXPORT BspWalkActionDrawPolygon : public BspWalkAction {
- public:
- void operator()(DrawPolygon* item) override;
-
- BspWalkActionDrawPolygon(DirectRenderer* renderer,
- const gfx::Rect& render_pass_scissor,
- bool using_scissor_as_optimization);
-
- private:
- DirectRenderer* renderer_;
- const gfx::Rect& render_pass_scissor_;
- bool using_scissor_as_optimization_;
-};
-
-class CC_EXPORT BspWalkActionToVector : public BspWalkAction {
- public:
- explicit BspWalkActionToVector(std::vector<DrawPolygon*>* in_list);
- void operator()(DrawPolygon* item) override;
-
- private:
- std::vector<DrawPolygon*>* list_;
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_BSP_WALK_ACTION_H_
diff --git a/chromium/cc/output/ca_layer_overlay.cc b/chromium/cc/output/ca_layer_overlay.cc
deleted file mode 100644
index d9943f8f402..00000000000
--- a/chromium/cc/output/ca_layer_overlay.cc
+++ /dev/null
@@ -1,344 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/ca_layer_overlay.h"
-
-#include <algorithm>
-
-#include "base/metrics/histogram_macros.h"
-#include "cc/quads/render_pass_draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/stream_video_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
-#include "cc/quads/tile_draw_quad.h"
-#include "cc/resources/resource_provider.h"
-#include "gpu/GLES2/gl2extchromium.h"
-
-namespace cc {
-
-namespace {
-
-// If there are too many RenderPassDrawQuads, we shouldn't use Core Animation to
-// present them as individual layers, since that potentially doubles the amount
-// of work needed to present them. cc has to blit them into an IOSurface, and
-// then Core Animation has to blit them to the final surface.
-// https://crbug.com/636884.
-const int kTooManyRenderPassDrawQuads = 30;
-
-// This enum is used for histogram states and should only have new values added
-// to the end before COUNT.
-enum CALayerResult {
- CA_LAYER_SUCCESS = 0,
- CA_LAYER_FAILED_UNKNOWN,
- CA_LAYER_FAILED_IO_SURFACE_NOT_CANDIDATE,
- CA_LAYER_FAILED_STREAM_VIDEO_NOT_CANDIDATE,
- CA_LAYER_FAILED_STREAM_VIDEO_TRANSFORM,
- CA_LAYER_FAILED_TEXTURE_NOT_CANDIDATE,
- CA_LAYER_FAILED_TEXTURE_Y_FLIPPED,
- CA_LAYER_FAILED_TILE_NOT_CANDIDATE,
- CA_LAYER_FAILED_QUAD_BLEND_MODE,
- CA_LAYER_FAILED_QUAD_TRANSFORM,
- CA_LAYER_FAILED_QUAD_CLIPPING,
- CA_LAYER_FAILED_DEBUG_BORDER,
- CA_LAYER_FAILED_PICTURE_CONTENT,
- CA_LAYER_FAILED_RENDER_PASS,
- CA_LAYER_FAILED_SURFACE_CONTENT,
- CA_LAYER_FAILED_YUV_VIDEO_CONTENT,
- CA_LAYER_FAILED_DIFFERENT_CLIP_SETTINGS,
- CA_LAYER_FAILED_DIFFERENT_VERTEX_OPACITIES,
- CA_LAYER_FAILED_RENDER_PASS_FILTER_SCALE,
- CA_LAYER_FAILED_RENDER_PASS_BACKGROUND_FILTERS,
- CA_LAYER_FAILED_RENDER_PASS_MASK,
- CA_LAYER_FAILED_RENDER_PASS_FILTER_OPERATION,
- CA_LAYER_FAILED_RENDER_PASS_SORTING_CONTEXT_ID,
- CA_LAYER_FAILED_TOO_MANY_RENDER_PASS_DRAW_QUADS,
- CA_LAYER_FAILED_COUNT,
-};
-
-bool FilterOperationSupported(const FilterOperation& operation) {
- switch (operation.type()) {
- case FilterOperation::GRAYSCALE:
- case FilterOperation::SEPIA:
- case FilterOperation::SATURATE:
- case FilterOperation::HUE_ROTATE:
- case FilterOperation::INVERT:
- case FilterOperation::BRIGHTNESS:
- case FilterOperation::CONTRAST:
- case FilterOperation::OPACITY:
- case FilterOperation::BLUR:
- case FilterOperation::DROP_SHADOW:
- return true;
- default:
- return false;
- }
-}
-
-CALayerResult FromRenderPassQuad(
- ResourceProvider* resource_provider,
- const RenderPassDrawQuad* quad,
- const base::flat_map<RenderPassId, FilterOperations*>& render_pass_filters,
- const base::flat_map<RenderPassId, FilterOperations*>&
- render_pass_background_filters,
- CALayerOverlay* ca_layer_overlay) {
- if (render_pass_background_filters.count(quad->render_pass_id)) {
- return CA_LAYER_FAILED_RENDER_PASS_BACKGROUND_FILTERS;
- }
-
- if (quad->shared_quad_state->sorting_context_id != 0)
- return CA_LAYER_FAILED_RENDER_PASS_SORTING_CONTEXT_ID;
-
- auto it = render_pass_filters.find(quad->render_pass_id);
- if (it != render_pass_filters.end()) {
- for (const FilterOperation& operation : it->second->operations()) {
- bool success = FilterOperationSupported(operation);
- if (!success)
- return CA_LAYER_FAILED_RENDER_PASS_FILTER_OPERATION;
- }
- }
-
- ca_layer_overlay->rpdq = quad;
- ca_layer_overlay->contents_rect = gfx::RectF(0, 0, 1, 1);
-
- return CA_LAYER_SUCCESS;
-}
-
-CALayerResult FromStreamVideoQuad(ResourceProvider* resource_provider,
- const StreamVideoDrawQuad* quad,
- CALayerOverlay* ca_layer_overlay) {
- unsigned resource_id = quad->resource_id();
- if (!resource_provider->IsOverlayCandidate(resource_id))
- return CA_LAYER_FAILED_STREAM_VIDEO_NOT_CANDIDATE;
- ca_layer_overlay->contents_resource_id = resource_id;
- // TODO(ccameron): Support merging at least some basic transforms into the
- // layer transform.
- if (!quad->matrix.IsIdentity())
- return CA_LAYER_FAILED_STREAM_VIDEO_TRANSFORM;
- ca_layer_overlay->contents_rect = gfx::RectF(0, 0, 1, 1);
- return CA_LAYER_SUCCESS;
-}
-
-CALayerResult FromSolidColorDrawQuad(const SolidColorDrawQuad* quad,
- CALayerOverlay* ca_layer_overlay,
- bool* skip) {
- // Do not generate quads that are completely transparent.
- if (SkColorGetA(quad->color) == 0) {
- *skip = true;
- return CA_LAYER_SUCCESS;
- }
- ca_layer_overlay->background_color = quad->color;
- return CA_LAYER_SUCCESS;
-}
-
-CALayerResult FromTextureQuad(ResourceProvider* resource_provider,
- const TextureDrawQuad* quad,
- CALayerOverlay* ca_layer_overlay) {
- unsigned resource_id = quad->resource_id();
- if (!resource_provider->IsOverlayCandidate(resource_id))
- return CA_LAYER_FAILED_TEXTURE_NOT_CANDIDATE;
- if (quad->y_flipped) {
- // The anchor point is at the bottom-left corner of the CALayer. The
- // transformation that flips the contents of the layer without changing its
- // frame is the composition of a vertical flip about the anchor point, and a
- // translation by the height of the layer.
- ca_layer_overlay->shared_state->transform.preTranslate(
- 0, ca_layer_overlay->bounds_rect.height(), 0);
- ca_layer_overlay->shared_state->transform.preScale(1, -1, 1);
- }
- ca_layer_overlay->contents_resource_id = resource_id;
- ca_layer_overlay->contents_rect =
- BoundingRect(quad->uv_top_left, quad->uv_bottom_right);
- ca_layer_overlay->background_color = quad->background_color;
- for (int i = 1; i < 4; ++i) {
- if (quad->vertex_opacity[i] != quad->vertex_opacity[0])
- return CA_LAYER_FAILED_DIFFERENT_VERTEX_OPACITIES;
- }
- ca_layer_overlay->shared_state->opacity *= quad->vertex_opacity[0];
- ca_layer_overlay->filter = quad->nearest_neighbor ? GL_NEAREST : GL_LINEAR;
- return CA_LAYER_SUCCESS;
-}
-
-CALayerResult FromTileQuad(ResourceProvider* resource_provider,
- const TileDrawQuad* quad,
- CALayerOverlay* ca_layer_overlay) {
- unsigned resource_id = quad->resource_id();
- if (!resource_provider->IsOverlayCandidate(resource_id))
- return CA_LAYER_FAILED_TILE_NOT_CANDIDATE;
- ca_layer_overlay->contents_resource_id = resource_id;
- ca_layer_overlay->contents_rect = quad->tex_coord_rect;
- ca_layer_overlay->contents_rect.Scale(1.f / quad->texture_size.width(),
- 1.f / quad->texture_size.height());
- ca_layer_overlay->filter = quad->nearest_neighbor ? GL_NEAREST : GL_LINEAR;
- return CA_LAYER_SUCCESS;
-}
-
-class CALayerOverlayProcessor {
- public:
- CALayerResult FromDrawQuad(
- ResourceProvider* resource_provider,
- const gfx::RectF& display_rect,
- const DrawQuad* quad,
- const base::flat_map<RenderPassId, FilterOperations*>&
- render_pass_filters,
- const base::flat_map<RenderPassId, FilterOperations*>&
- render_pass_background_filters,
- CALayerOverlay* ca_layer_overlay,
- bool* skip,
- bool* render_pass_draw_quad) {
- if (quad->shared_quad_state->blend_mode != SkBlendMode::kSrcOver)
- return CA_LAYER_FAILED_QUAD_BLEND_MODE;
-
- // Early-out for invisible quads.
- if (quad->shared_quad_state->opacity == 0.f) {
- *skip = true;
- return CA_LAYER_SUCCESS;
- }
-
- // Enable edge anti-aliasing only on layer boundaries.
- ca_layer_overlay->edge_aa_mask = 0;
- if (quad->IsLeftEdge())
- ca_layer_overlay->edge_aa_mask |= GL_CA_LAYER_EDGE_LEFT_CHROMIUM;
- if (quad->IsRightEdge())
- ca_layer_overlay->edge_aa_mask |= GL_CA_LAYER_EDGE_RIGHT_CHROMIUM;
- if (quad->IsBottomEdge())
- ca_layer_overlay->edge_aa_mask |= GL_CA_LAYER_EDGE_BOTTOM_CHROMIUM;
- if (quad->IsTopEdge())
- ca_layer_overlay->edge_aa_mask |= GL_CA_LAYER_EDGE_TOP_CHROMIUM;
-
- if (most_recent_shared_quad_state_ != quad->shared_quad_state) {
- most_recent_shared_quad_state_ = quad->shared_quad_state;
- most_recent_overlay_shared_state_ = new CALayerOverlaySharedState;
- // Set rect clipping and sorting context ID.
- most_recent_overlay_shared_state_->sorting_context_id =
- quad->shared_quad_state->sorting_context_id;
- most_recent_overlay_shared_state_->is_clipped =
- quad->shared_quad_state->is_clipped;
- most_recent_overlay_shared_state_->clip_rect =
- gfx::RectF(quad->shared_quad_state->clip_rect);
-
- most_recent_overlay_shared_state_->opacity =
- quad->shared_quad_state->opacity;
- most_recent_overlay_shared_state_->transform =
- quad->shared_quad_state->quad_to_target_transform.matrix();
- }
- ca_layer_overlay->shared_state = most_recent_overlay_shared_state_;
-
- ca_layer_overlay->bounds_rect = gfx::RectF(quad->rect);
-
- *render_pass_draw_quad = quad->material == DrawQuad::RENDER_PASS;
- switch (quad->material) {
- case DrawQuad::TEXTURE_CONTENT:
- return FromTextureQuad(resource_provider,
- TextureDrawQuad::MaterialCast(quad),
- ca_layer_overlay);
- case DrawQuad::TILED_CONTENT:
- return FromTileQuad(resource_provider, TileDrawQuad::MaterialCast(quad),
- ca_layer_overlay);
- case DrawQuad::SOLID_COLOR:
- return FromSolidColorDrawQuad(SolidColorDrawQuad::MaterialCast(quad),
- ca_layer_overlay, skip);
- case DrawQuad::STREAM_VIDEO_CONTENT:
- return FromStreamVideoQuad(resource_provider,
- StreamVideoDrawQuad::MaterialCast(quad),
- ca_layer_overlay);
- case DrawQuad::DEBUG_BORDER:
- return CA_LAYER_FAILED_DEBUG_BORDER;
- case DrawQuad::PICTURE_CONTENT:
- return CA_LAYER_FAILED_PICTURE_CONTENT;
- case DrawQuad::RENDER_PASS:
- return FromRenderPassQuad(
- resource_provider, RenderPassDrawQuad::MaterialCast(quad),
- render_pass_filters, render_pass_background_filters,
- ca_layer_overlay);
- case DrawQuad::SURFACE_CONTENT:
- return CA_LAYER_FAILED_SURFACE_CONTENT;
- case DrawQuad::YUV_VIDEO_CONTENT:
- return CA_LAYER_FAILED_YUV_VIDEO_CONTENT;
- default:
- break;
- }
-
- return CA_LAYER_FAILED_UNKNOWN;
- }
-
- private:
- const viz::SharedQuadState* most_recent_shared_quad_state_ = nullptr;
- scoped_refptr<CALayerOverlaySharedState> most_recent_overlay_shared_state_;
-};
-
-} // namespace
-
-CALayerOverlay::CALayerOverlay() : filter(GL_LINEAR) {}
-
-CALayerOverlay::CALayerOverlay(const CALayerOverlay& other) = default;
-
-CALayerOverlay::~CALayerOverlay() {}
-
-bool ProcessForCALayerOverlays(
- ResourceProvider* resource_provider,
- const gfx::RectF& display_rect,
- const QuadList& quad_list,
- const base::flat_map<RenderPassId, FilterOperations*>& render_pass_filters,
- const base::flat_map<RenderPassId, FilterOperations*>&
- render_pass_background_filters,
- CALayerOverlayList* ca_layer_overlays) {
- CALayerResult result = CA_LAYER_SUCCESS;
- ca_layer_overlays->reserve(quad_list.size());
-
- int render_pass_draw_quad_count = 0;
- CALayerOverlayProcessor processor;
- for (auto it = quad_list.BackToFrontBegin(); it != quad_list.BackToFrontEnd();
- ++it) {
- const DrawQuad* quad = *it;
- CALayerOverlay ca_layer;
- bool skip = false;
- bool render_pass_draw_quad = false;
- result = processor.FromDrawQuad(resource_provider, display_rect, quad,
- render_pass_filters,
- render_pass_background_filters, &ca_layer,
- &skip, &render_pass_draw_quad);
- if (result != CA_LAYER_SUCCESS)
- break;
-
- if (render_pass_draw_quad) {
- ++render_pass_draw_quad_count;
- if (render_pass_draw_quad_count > kTooManyRenderPassDrawQuads) {
- result = CA_LAYER_FAILED_TOO_MANY_RENDER_PASS_DRAW_QUADS;
- break;
- }
- }
-
- if (skip)
- continue;
-
- // It is not possible to correctly represent two different clipping settings
- // within one sorting context.
- if (!ca_layer_overlays->empty()) {
- const CALayerOverlay& previous_ca_layer = ca_layer_overlays->back();
- if (ca_layer.shared_state->sorting_context_id &&
- previous_ca_layer.shared_state->sorting_context_id ==
- ca_layer.shared_state->sorting_context_id) {
- if (previous_ca_layer.shared_state->is_clipped !=
- ca_layer.shared_state->is_clipped ||
- previous_ca_layer.shared_state->clip_rect !=
- ca_layer.shared_state->clip_rect) {
- result = CA_LAYER_FAILED_DIFFERENT_CLIP_SETTINGS;
- break;
- }
- }
- }
-
- ca_layer_overlays->push_back(ca_layer);
- }
-
- UMA_HISTOGRAM_ENUMERATION("Compositing.Renderer.CALayerResult", result,
- CA_LAYER_FAILED_COUNT);
-
- if (result != CA_LAYER_SUCCESS) {
- ca_layer_overlays->clear();
- return false;
- }
- return true;
-}
-
-} // namespace cc
diff --git a/chromium/cc/output/ca_layer_overlay.h b/chromium/cc/output/ca_layer_overlay.h
deleted file mode 100644
index aa60b546ac5..00000000000
--- a/chromium/cc/output/ca_layer_overlay.h
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_CA_LAYER_OVERLAY_H_
-#define CC_OUTPUT_CA_LAYER_OVERLAY_H_
-
-#include "base/containers/flat_map.h"
-#include "base/memory/ref_counted.h"
-#include "cc/quads/render_pass.h"
-#include "third_party/skia/include/core/SkColor.h"
-#include "third_party/skia/include/core/SkMatrix44.h"
-#include "ui/gfx/geometry/rect_f.h"
-#include "ui/gl/ca_renderer_layer_params.h"
-
-namespace cc {
-
-class DrawQuad;
-class RenderPassDrawQuad;
-class ResourceProvider;
-
-// Holds information that is frequently shared between consecutive
-// CALayerOverlays.
-class CC_EXPORT CALayerOverlaySharedState
- : public base::RefCounted<CALayerOverlaySharedState> {
- public:
- CALayerOverlaySharedState() {}
- // Layers in a non-zero sorting context exist in the same 3D space and should
- // intersect.
- unsigned sorting_context_id = 0;
- // If |is_clipped| is true, then clip to |clip_rect| in the target space.
- bool is_clipped = false;
- gfx::RectF clip_rect;
- // The opacity property for the CAayer.
- float opacity = 1;
- // The transform to apply to the CALayer.
- SkMatrix44 transform = SkMatrix44(SkMatrix44::kIdentity_Constructor);
-
- private:
- friend class base::RefCounted<CALayerOverlaySharedState>;
- ~CALayerOverlaySharedState() {}
-};
-
-// Holds all information necessary to construct a CALayer from a DrawQuad.
-class CC_EXPORT CALayerOverlay {
- public:
- CALayerOverlay();
- CALayerOverlay(const CALayerOverlay& other);
- ~CALayerOverlay();
-
- // State that is frequently shared between consecutive CALayerOverlays.
- scoped_refptr<CALayerOverlaySharedState> shared_state;
-
- // Texture that corresponds to an IOSurface to set as the content of the
- // CALayer. If this is 0 then the CALayer is a solid color.
- unsigned contents_resource_id = 0;
- // The contents rect property for the CALayer.
- gfx::RectF contents_rect;
- // The bounds for the CALayer in pixels.
- gfx::RectF bounds_rect;
- // The background color property for the CALayer.
- SkColor background_color = SK_ColorTRANSPARENT;
- // The edge anti-aliasing mask property for the CALayer.
- unsigned edge_aa_mask = 0;
- // The minification and magnification filters for the CALayer.
- unsigned filter;
- // If |rpdq| is present, then the renderer must draw the filter effects and
- // copy the result into an IOSurface.
- const RenderPassDrawQuad* rpdq = nullptr;
-};
-
-typedef std::vector<CALayerOverlay> CALayerOverlayList;
-
-// Returns true if all quads in the root render pass have been replaced by
-// CALayerOverlays.
-bool ProcessForCALayerOverlays(
- ResourceProvider* resource_provider,
- const gfx::RectF& display_rect,
- const QuadList& quad_list,
- const base::flat_map<RenderPassId, FilterOperations*>& render_pass_filters,
- const base::flat_map<RenderPassId, FilterOperations*>&
- render_pass_background_filters,
- CALayerOverlayList* ca_layer_overlays);
-
-} // namespace cc
-
-#endif // CC_OUTPUT_CA_LAYER_OVERLAY_H_
diff --git a/chromium/cc/output/compositor_frame.cc b/chromium/cc/output/compositor_frame.cc
deleted file mode 100644
index 82479cf3b43..00000000000
--- a/chromium/cc/output/compositor_frame.cc
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/compositor_frame.h"
-
-namespace cc {
-
-CompositorFrame::CompositorFrame() {}
-
-CompositorFrame::CompositorFrame(CompositorFrame&& other) = default;
-
-CompositorFrame::~CompositorFrame() {}
-
-CompositorFrame& CompositorFrame::operator=(CompositorFrame&& other) = default;
-
-} // namespace cc
diff --git a/chromium/cc/output/compositor_frame.h b/chromium/cc/output/compositor_frame.h
deleted file mode 100644
index 8cd44eae16b..00000000000
--- a/chromium/cc/output/compositor_frame.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_COMPOSITOR_FRAME_H_
-#define CC_OUTPUT_COMPOSITOR_FRAME_H_
-
-#include <memory>
-
-#include "base/macros.h"
-#include "cc/cc_export.h"
-#include "cc/output/compositor_frame_metadata.h"
-#include "cc/quads/render_pass.h"
-#include "components/viz/common/resources/transferable_resource.h"
-
-namespace cc {
-
-// A CompositorFrame struct contains the complete output of a compositor meant
-// for display. A CompositorFrame consists of a series of DrawQuads that
-// describe placement of textures, solid colors, overlays and other
-// CompositorFrames within an area specified by the parent compositor. DrawQuads
-// may share common data referred to as SharedQuadState. A CompositorFrame also
-// has |metadata| that refers to global graphical state associated with this
-// frame.
-class CC_EXPORT CompositorFrame {
- public:
- CompositorFrame();
- CompositorFrame(CompositorFrame&& other);
- ~CompositorFrame();
-
- CompositorFrame& operator=(CompositorFrame&& other);
-
- float device_scale_factor() const { return metadata.device_scale_factor; }
-
- const gfx::Size& size_in_pixels() const {
- DCHECK(!render_pass_list.empty());
- return render_pass_list.back()->output_rect.size();
- }
-
- CompositorFrameMetadata metadata;
- std::vector<viz::TransferableResource> resource_list;
- // This list is in the order that each RenderPass will be drawn. The last one
- // is the "root" RenderPass that all others are directly or indirectly drawn
- // into.
- RenderPassList render_pass_list;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(CompositorFrame);
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_COMPOSITOR_FRAME_H_
diff --git a/chromium/cc/output/compositor_frame_metadata.cc b/chromium/cc/output/compositor_frame_metadata.cc
deleted file mode 100644
index afd974182fe..00000000000
--- a/chromium/cc/output/compositor_frame_metadata.cc
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/compositor_frame_metadata.h"
-
-namespace cc {
-
-CompositorFrameMetadata::CompositorFrameMetadata() = default;
-
-CompositorFrameMetadata::CompositorFrameMetadata(
- CompositorFrameMetadata&& other) = default;
-
-CompositorFrameMetadata::~CompositorFrameMetadata() {
-}
-
-CompositorFrameMetadata& CompositorFrameMetadata::operator=(
- CompositorFrameMetadata&& other) = default;
-
-CompositorFrameMetadata CompositorFrameMetadata::Clone() const {
- CompositorFrameMetadata metadata(*this);
- return metadata;
-}
-
-CompositorFrameMetadata::CompositorFrameMetadata(
- const CompositorFrameMetadata& other) = default;
-
-} // namespace cc
diff --git a/chromium/cc/output/compositor_frame_metadata.h b/chromium/cc/output/compositor_frame_metadata.h
deleted file mode 100644
index 104b24b89b2..00000000000
--- a/chromium/cc/output/compositor_frame_metadata.h
+++ /dev/null
@@ -1,126 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_COMPOSITOR_FRAME_METADATA_H_
-#define CC_OUTPUT_COMPOSITOR_FRAME_METADATA_H_
-
-#include <stdint.h>
-
-#include <vector>
-
-#include "cc/cc_export.h"
-#include "cc/input/selection.h"
-#include "components/viz/common/frame_sinks/begin_frame_args.h"
-#include "components/viz/common/surfaces/surface_id.h"
-#include "third_party/skia/include/core/SkColor.h"
-#include "ui/gfx/geometry/size_f.h"
-#include "ui/gfx/geometry/vector2d_f.h"
-#include "ui/gfx/selection_bound.h"
-#include "ui/latency/latency_info.h"
-
-namespace cc {
-
-class CC_EXPORT CompositorFrameMetadata {
- public:
- CompositorFrameMetadata();
- CompositorFrameMetadata(CompositorFrameMetadata&& other);
- ~CompositorFrameMetadata();
-
- CompositorFrameMetadata& operator=(CompositorFrameMetadata&& other);
-
- CompositorFrameMetadata Clone() const;
-
- // The device scale factor used to generate this compositor frame.
- float device_scale_factor = 0.f;
-
- // Scroll offset and scale of the root layer. This can be used for tasks
- // like positioning windowed plugins.
- gfx::Vector2dF root_scroll_offset;
- float page_scale_factor = 0.f;
-
- // These limits can be used together with the scroll/scale fields above to
- // determine if scrolling/scaling in a particular direction is possible.
- gfx::SizeF scrollable_viewport_size;
- gfx::SizeF root_layer_size;
- float min_page_scale_factor = 0.f;
- float max_page_scale_factor = 0.f;
- bool root_overflow_x_hidden = false;
- bool root_overflow_y_hidden = false;
- bool may_contain_video = false;
-
- // WebView makes quality decisions for rastering resourceless software frames
- // based on information that a scroll or animation is active.
- // TODO(aelias): Remove this and always enable filtering if there aren't apps
- // depending on this anymore.
- bool is_resourceless_software_draw_with_scroll_or_animation = false;
-
- // Used to position the Android location top bar and page content, whose
- // precise position is computed by the renderer compositor.
- float top_controls_height = 0.f;
- float top_controls_shown_ratio = 0.f;
-
- // Used to position Android bottom bar, whose position is computed by the
- // renderer compositor.
- float bottom_controls_height = 0.f;
- float bottom_controls_shown_ratio = 0.f;
-
- // This color is usually obtained from the background color of the <body>
- // element. It can be used for filling in gutter areas around the frame when
- // it's too small to fill the box the parent reserved for it.
- SkColor root_background_color = SK_ColorWHITE;
-
- // Provides selection region updates relative to the current viewport. If the
- // selection is empty or otherwise unused, the bound types will indicate such.
- Selection<gfx::SelectionBound> selection;
-
- std::vector<ui::LatencyInfo> latency_info;
-
- // This is the set of Surfaces that are referenced by this frame.
- // Note: this includes occluded and clipped surfaces and surfaces that may
- // be accessed by this CompositorFrame in the future.
- // TODO(fsamuel): In the future, a generalized frame eviction system will
- // determine which surfaces to retain and which to evict. It will likely
- // be unnecessary for the embedder to explicitly specify which surfaces to
- // retain. Thus, this field will likely go away.
- std::vector<viz::SurfaceId> referenced_surfaces;
-
- // This is the set of dependent SurfaceIds that should be active in the
- // display compositor before this CompositorFrame can be activated. Note
- // that if |can_activate_before_dependencies| then the display compositor
- // can choose to activate a CompositorFrame before all dependencies are
- // available.
- // Note: |activation_dependencies| and |referenced_surfaces| are disjoint
- // sets of surface IDs. If a surface ID is known to exist and can be
- // used without additional synchronization, then it is placed in
- // |referenced_surfaces|. |activation_dependencies| is the set of
- // surface IDs that this frame would like to block on until they
- // become available or a deadline hits.
- std::vector<viz::SurfaceId> activation_dependencies;
-
- // This indicates whether this CompositorFrame can be activated before
- // dependencies have been resolved.
- bool can_activate_before_dependencies = true;
-
- // This is a value that allows the browser to associate compositor frames
- // with the content that they represent -- typically top-level page loads.
- // TODO(kenrb, fsamuel): This should eventually by SurfaceID, when they
- // become available in all renderer processes. See https://crbug.com/695579.
- uint32_t content_source_id = 0;
-
- // viz::BeginFrameAck for the BeginFrame that this CompositorFrame answers.
- viz::BeginFrameAck begin_frame_ack;
-
- // Once the display compositor processes a frame containing a non-zero frame
- // token, the token is sent to embedder of the frame. This is helpful when
- // the embedder wants to do something after a particular frame is processed.
- uint32_t frame_token = 0;
-
- private:
- CompositorFrameMetadata(const CompositorFrameMetadata& other);
- CompositorFrameMetadata operator=(const CompositorFrameMetadata&) = delete;
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_COMPOSITOR_FRAME_METADATA_H_
diff --git a/chromium/cc/output/context_cache_controller_unittest.cc b/chromium/cc/output/context_cache_controller_unittest.cc
deleted file mode 100644
index 5f32ac3ca7c..00000000000
--- a/chromium/cc/output/context_cache_controller_unittest.cc
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright (c) 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/viz/common/gpu/context_cache_controller.h"
-
-#include "base/memory/ptr_util.h"
-#include "base/test/test_mock_time_task_runner.h"
-#include "cc/test/test_context_provider.h"
-#include "cc/test/test_context_support.h"
-#include "cc/test/test_web_graphics_context_3d.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace cc {
-namespace {
-using ::testing::Mock;
-using ::testing::StrictMock;
-
-class MockContextSupport : public TestContextSupport {
- public:
- MockContextSupport() {}
- MOCK_METHOD1(SetAggressivelyFreeResources,
- void(bool aggressively_free_resources));
-};
-
-TEST(ContextCacheControllerTest, ScopedVisibilityBasic) {
- StrictMock<MockContextSupport> context_support;
- auto task_runner = make_scoped_refptr(new base::TestMockTimeTaskRunner);
- viz::ContextCacheController cache_controller(&context_support, task_runner);
-
- EXPECT_CALL(context_support, SetAggressivelyFreeResources(false));
- std::unique_ptr<viz::ContextCacheController::ScopedVisibility> visibility =
- cache_controller.ClientBecameVisible();
- Mock::VerifyAndClearExpectations(&context_support);
-
- EXPECT_CALL(context_support, SetAggressivelyFreeResources(true));
- cache_controller.ClientBecameNotVisible(std::move(visibility));
-}
-
-TEST(ContextCacheControllerTest, ScopedVisibilityMulti) {
- StrictMock<MockContextSupport> context_support;
- auto task_runner = make_scoped_refptr(new base::TestMockTimeTaskRunner);
- viz::ContextCacheController cache_controller(&context_support, task_runner);
-
- EXPECT_CALL(context_support, SetAggressivelyFreeResources(false));
- auto visibility_1 = cache_controller.ClientBecameVisible();
- Mock::VerifyAndClearExpectations(&context_support);
- auto visibility_2 = cache_controller.ClientBecameVisible();
-
- cache_controller.ClientBecameNotVisible(std::move(visibility_1));
- EXPECT_CALL(context_support, SetAggressivelyFreeResources(true));
- cache_controller.ClientBecameNotVisible(std::move(visibility_2));
-}
-
-TEST(ContextCacheControllerTest, ScopedBusyWhileVisible) {
- StrictMock<MockContextSupport> context_support;
- auto task_runner = make_scoped_refptr(new base::TestMockTimeTaskRunner);
- viz::ContextCacheController cache_controller(&context_support, task_runner);
-
- EXPECT_CALL(context_support, SetAggressivelyFreeResources(false));
- auto visibility = cache_controller.ClientBecameVisible();
- Mock::VerifyAndClearExpectations(&context_support);
-
- // Now that we're visible, ensure that going idle triggers a delayed cleanup.
- auto busy = cache_controller.ClientBecameBusy();
- cache_controller.ClientBecameNotBusy(std::move(busy));
-
- EXPECT_CALL(context_support, SetAggressivelyFreeResources(true));
- EXPECT_CALL(context_support, SetAggressivelyFreeResources(false));
- task_runner->FastForwardBy(base::TimeDelta::FromSeconds(5));
- Mock::VerifyAndClearExpectations(&context_support);
-
- EXPECT_CALL(context_support, SetAggressivelyFreeResources(true));
- cache_controller.ClientBecameNotVisible(std::move(visibility));
-}
-
-TEST(ContextCacheControllerTest, ScopedBusyWhileNotVisible) {
- StrictMock<MockContextSupport> context_support;
- auto task_runner = make_scoped_refptr(new base::TestMockTimeTaskRunner);
- viz::ContextCacheController cache_controller(&context_support, task_runner);
-
- auto busy = cache_controller.ClientBecameBusy();
-
- // We are not visible, so becoming busy should not trigger an idle callback.
- cache_controller.ClientBecameNotBusy(std::move(busy));
- task_runner->FastForwardBy(base::TimeDelta::FromSeconds(5));
-}
-
-TEST(ContextCacheControllerTest, ScopedBusyMulitpleWhileVisible) {
- StrictMock<MockContextSupport> context_support;
- auto task_runner = make_scoped_refptr(new base::TestMockTimeTaskRunner);
- viz::ContextCacheController cache_controller(&context_support, task_runner);
-
- EXPECT_CALL(context_support, SetAggressivelyFreeResources(false));
- auto visible = cache_controller.ClientBecameVisible();
- Mock::VerifyAndClearExpectations(&context_support);
-
- auto busy_1 = cache_controller.ClientBecameBusy();
- cache_controller.ClientBecameNotBusy(std::move(busy_1));
- auto busy_2 = cache_controller.ClientBecameBusy();
- cache_controller.ClientBecameNotBusy(std::move(busy_2));
-
- // When we fast forward, only one cleanup should happen.
- EXPECT_CALL(context_support, SetAggressivelyFreeResources(true));
- EXPECT_CALL(context_support, SetAggressivelyFreeResources(false));
- task_runner->FastForwardBy(base::TimeDelta::FromSeconds(5));
- Mock::VerifyAndClearExpectations(&context_support);
-
- EXPECT_CALL(context_support, SetAggressivelyFreeResources(true));
- cache_controller.ClientBecameNotVisible(std::move(visible));
-}
-
-} // namespace
-} // namespace cc
diff --git a/chromium/cc/output/dc_layer_overlay.cc b/chromium/cc/output/dc_layer_overlay.cc
deleted file mode 100644
index 51f120d16ef..00000000000
--- a/chromium/cc/output/dc_layer_overlay.cc
+++ /dev/null
@@ -1,416 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/dc_layer_overlay.h"
-
-#include "base/metrics/histogram_macros.h"
-#include "cc/base/math_util.h"
-#include "cc/quads/render_pass_draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/yuv_video_draw_quad.h"
-#include "cc/resources/resource_provider.h"
-#include "gpu/GLES2/gl2extchromium.h"
-#include "ui/gfx/geometry/rect_conversions.h"
-#include "ui/gl/gl_switches.h"
-
-namespace cc {
-
-namespace {
-
-DCLayerOverlayProcessor::DCLayerResult FromYUVQuad(
- ResourceProvider* resource_provider,
- const YUVVideoDrawQuad* quad,
- DCLayerOverlay* ca_layer_overlay) {
- for (const auto& resource : quad->resources) {
- if (!resource_provider->IsOverlayCandidate(resource))
- return DCLayerOverlayProcessor::DC_LAYER_FAILED_TEXTURE_NOT_CANDIDATE;
- }
- ca_layer_overlay->resources = quad->resources;
- ca_layer_overlay->contents_rect = quad->ya_tex_coord_rect;
- ca_layer_overlay->filter = GL_LINEAR;
- ca_layer_overlay->color_space = quad->video_color_space;
- ca_layer_overlay->require_overlay = quad->require_overlay;
- return DCLayerOverlayProcessor::DC_LAYER_SUCCESS;
-}
-
-// This returns the smallest rectangle in target space that contains the quad.
-gfx::RectF ClippedQuadRectangle(const DrawQuad* quad) {
- gfx::RectF quad_rect = MathUtil::MapClippedRect(
- quad->shared_quad_state->quad_to_target_transform,
- gfx::RectF(quad->rect));
- if (quad->shared_quad_state->is_clipped)
- quad_rect.Intersect(gfx::RectF(quad->shared_quad_state->clip_rect));
- return quad_rect;
-}
-
-// Find a rectangle containing all the quads in a list that occlude the area
-// in target_quad.
-gfx::RectF GetOcclusionBounds(const gfx::RectF& target_quad,
- QuadList::ConstIterator quad_list_begin,
- QuadList::ConstIterator quad_list_end) {
- gfx::RectF occlusion_bounding_box;
- for (auto overlap_iter = quad_list_begin; overlap_iter != quad_list_end;
- ++overlap_iter) {
- float opacity = overlap_iter->shared_quad_state->opacity;
- if (opacity < std::numeric_limits<float>::epsilon())
- continue;
- const DrawQuad* quad = *overlap_iter;
- gfx::RectF overlap_rect = ClippedQuadRectangle(quad);
- if (quad->material == DrawQuad::SOLID_COLOR) {
- SkColor color = SolidColorDrawQuad::MaterialCast(quad)->color;
- float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity;
- if (quad->ShouldDrawWithBlending() &&
- alpha < std::numeric_limits<float>::epsilon())
- continue;
- }
- overlap_rect.Intersect(target_quad);
- if (!overlap_rect.IsEmpty()) {
- occlusion_bounding_box.Union(overlap_rect);
- }
- }
- return occlusion_bounding_box;
-}
-
-void RecordDCLayerResult(DCLayerOverlayProcessor::DCLayerResult result) {
- UMA_HISTOGRAM_ENUMERATION("GPU.DirectComposition.DCLayerResult", result,
- DCLayerOverlayProcessor::DC_LAYER_FAILED_MAX);
-}
-
-} // namespace
-
-DCLayerOverlay::DCLayerOverlay() : filter(GL_LINEAR) {}
-
-DCLayerOverlay::DCLayerOverlay(const DCLayerOverlay& other) = default;
-
-DCLayerOverlay::~DCLayerOverlay() {}
-
-DCLayerOverlayProcessor::DCLayerOverlayProcessor() = default;
-
-DCLayerOverlayProcessor::~DCLayerOverlayProcessor() = default;
-
-DCLayerOverlayProcessor::DCLayerResult DCLayerOverlayProcessor::FromDrawQuad(
- ResourceProvider* resource_provider,
- const gfx::RectF& display_rect,
- QuadList::ConstIterator quad_list_begin,
- QuadList::ConstIterator quad,
- DCLayerOverlay* ca_layer_overlay) {
- if (quad->shared_quad_state->blend_mode != SkBlendMode::kSrcOver)
- return DC_LAYER_FAILED_QUAD_BLEND_MODE;
-
- DCLayerResult result;
- switch (quad->material) {
- case DrawQuad::YUV_VIDEO_CONTENT:
- result =
- FromYUVQuad(resource_provider, YUVVideoDrawQuad::MaterialCast(*quad),
- ca_layer_overlay);
- break;
- default:
- return DC_LAYER_FAILED_UNSUPPORTED_QUAD;
- }
- if (result != DC_LAYER_SUCCESS)
- return result;
-
- scoped_refptr<DCLayerOverlaySharedState> overlay_shared_state(
- new DCLayerOverlaySharedState);
- overlay_shared_state->z_order = 1;
-
- overlay_shared_state->is_clipped = quad->shared_quad_state->is_clipped;
- overlay_shared_state->clip_rect =
- gfx::RectF(quad->shared_quad_state->clip_rect);
-
- overlay_shared_state->opacity = quad->shared_quad_state->opacity;
- overlay_shared_state->transform =
- quad->shared_quad_state->quad_to_target_transform.matrix();
-
- ca_layer_overlay->shared_state = overlay_shared_state;
- ca_layer_overlay->bounds_rect = gfx::RectF(quad->rect);
-
- return result;
-}
-
-void DCLayerOverlayProcessor::Process(ResourceProvider* resource_provider,
- const gfx::RectF& display_rect,
- RenderPassList* render_passes,
- gfx::Rect* overlay_damage_rect,
- gfx::Rect* damage_rect,
- DCLayerOverlayList* ca_layer_overlays) {
- DCHECK(pass_info_.empty());
- processed_overlay_in_frame_ = false;
- if (base::FeatureList::IsEnabled(
- features::kDirectCompositionNonrootOverlays)) {
- for (auto& pass : *render_passes) {
- bool is_root = (pass == render_passes->back());
- ProcessRenderPass(resource_provider, display_rect, pass.get(), is_root,
- overlay_damage_rect,
- is_root ? damage_rect : &pass->damage_rect,
- ca_layer_overlays);
- }
- } else {
- ProcessRenderPass(resource_provider, display_rect,
- render_passes->back().get(), true, overlay_damage_rect,
- damage_rect, ca_layer_overlays);
- }
- pass_info_.clear();
-}
-
-QuadList::Iterator DCLayerOverlayProcessor::ProcessRenderPassDrawQuad(
- RenderPass* render_pass,
- gfx::Rect* damage_rect,
- QuadList::Iterator it) {
- DCHECK_EQ(DrawQuad::RENDER_PASS, it->material);
- const RenderPassDrawQuad* rpdq = RenderPassDrawQuad::MaterialCast(*it);
-
- ++it;
- // Check if this quad is broken to avoid corrupting pass_info.
- if (rpdq->render_pass_id == render_pass->id)
- return it;
- if (!pass_info_.count(rpdq->render_pass_id))
- return it;
- pass_info_[render_pass->id] = std::vector<PunchThroughRect>();
- auto& pass_info = pass_info_[rpdq->render_pass_id];
-
- const viz::SharedQuadState* original_shared_quad_state =
- rpdq->shared_quad_state;
-
- // Punch holes through for all child video quads that will be displayed in
- // underlays. This doesn't work perfectly in all cases - it breaks with
- // complex overlap or filters - but it's needed to be able to display these
- // videos at all. The EME spec allows that some HTML rendering capabilities
- // may be unavailable for EME videos.
- //
- // The solid color quads are inserted after the RPDQ, so they'll be drawn
- // before it and will only cut out contents behind it. A kDstOut solid color
- // quad is used with an accumulated opacity to do the hole punching, because
- // with premultiplied alpha that reduces the opacity of the current content
- // by the opacity of the layer.
- it = render_pass->quad_list
- .InsertBeforeAndInvalidateAllPointers<SolidColorDrawQuad>(
- it, pass_info.size());
- rpdq = nullptr;
- for (size_t i = 0; i < pass_info.size(); i++, ++it) {
- auto& punch_through = pass_info[i];
- viz::SharedQuadState* new_shared_quad_state =
- render_pass->shared_quad_state_list
- .AllocateAndConstruct<viz::SharedQuadState>();
- gfx::Transform new_transform(
- original_shared_quad_state->quad_to_target_transform,
- punch_through.transform_to_target);
- float new_opacity =
- punch_through.opacity * original_shared_quad_state->opacity;
- new_shared_quad_state->SetAll(new_transform, punch_through.rect,
- punch_through.rect, punch_through.rect, false,
- new_opacity, SkBlendMode::kDstOut, 0);
- SolidColorDrawQuad* solid_quad = static_cast<SolidColorDrawQuad*>(*it);
- solid_quad->SetAll(new_shared_quad_state, punch_through.rect,
- punch_through.rect, false, 0xff000000, true);
- damage_rect->Union(gfx::ToEnclosingRect(ClippedQuadRectangle(solid_quad)));
-
- // Add transformed info to list in case this renderpass is included in
- // another pass.
- PunchThroughRect info;
- info.rect = punch_through.rect;
- info.transform_to_target = new_transform;
- info.opacity = new_opacity;
- pass_info_[render_pass->id].push_back(info);
- }
- return it;
-}
-
-void DCLayerOverlayProcessor::ProcessRenderPass(
- ResourceProvider* resource_provider,
- const gfx::RectF& display_rect,
- RenderPass* render_pass,
- bool is_root,
- gfx::Rect* overlay_damage_rect,
- gfx::Rect* damage_rect,
- DCLayerOverlayList* ca_layer_overlays) {
- gfx::Rect this_frame_underlay_rect;
- QuadList* quad_list = &render_pass->quad_list;
-
- QuadList::Iterator next_it = quad_list->begin();
- for (auto it = quad_list->begin(); it != quad_list->end(); it = next_it) {
- next_it = it;
- ++next_it;
- // next_it may be modified inside the loop if methods modify the quad list
- // and invalidate iterators to it.
-
- if (it->material == DrawQuad::RENDER_PASS) {
- next_it = ProcessRenderPassDrawQuad(render_pass, damage_rect, it);
- continue;
- }
-
- DCLayerOverlay dc_layer;
- DCLayerResult result = FromDrawQuad(resource_provider, display_rect,
- quad_list->begin(), it, &dc_layer);
- if (result != DC_LAYER_SUCCESS) {
- RecordDCLayerResult(result);
- continue;
- }
-
- if (!it->shared_quad_state->quad_to_target_transform
- .Preserves2dAxisAlignment() &&
- !dc_layer.require_overlay &&
- !base::FeatureList::IsEnabled(
- features::kDirectCompositionComplexOverlays)) {
- RecordDCLayerResult(DC_LAYER_FAILED_COMPLEX_TRANSFORM);
- continue;
- }
-
- dc_layer.shared_state->transform.postConcat(
- render_pass->transform_to_root_target.matrix());
-
- gfx::Rect quad_rectangle = gfx::ToEnclosingRect(ClippedQuadRectangle(*it));
- gfx::RectF occlusion_bounding_box =
- GetOcclusionBounds(gfx::RectF(quad_rectangle), quad_list->begin(), it);
- bool processed_overlay = false;
-
- // Underlays are less efficient, so attempt regular overlays first.
- if (is_root && !processed_overlay_in_frame_ &&
- ProcessForOverlay(display_rect, quad_list, quad_rectangle,
- occlusion_bounding_box, &it, damage_rect)) {
- // ProcessForOverlay makes the iterator point to the next value on
- // success.
- next_it = it;
- processed_overlay = true;
- } else if (ProcessForUnderlay(display_rect, render_pass, quad_rectangle,
- occlusion_bounding_box, it, is_root,
- damage_rect, &this_frame_underlay_rect,
- &dc_layer)) {
- processed_overlay = true;
- }
-
- if (processed_overlay) {
- gfx::Rect rect_in_root = MathUtil::MapEnclosingClippedRect(
- render_pass->transform_to_root_target, quad_rectangle);
- overlay_damage_rect->Union(rect_in_root);
-
- RecordDCLayerResult(DC_LAYER_SUCCESS);
- ca_layer_overlays->push_back(dc_layer);
- if (!base::FeatureList::IsEnabled(
- features::kDirectCompositionNonrootOverlays)) {
- // Only allow one overlay for now.
- break;
- }
- processed_overlay_in_frame_ = true;
- }
- }
- if (is_root) {
- damage_rect->Intersect(gfx::ToEnclosingRect(display_rect));
- previous_frame_underlay_rect_ = this_frame_underlay_rect;
- previous_display_rect_ = display_rect;
- }
-}
-
-bool DCLayerOverlayProcessor::ProcessForOverlay(
- const gfx::RectF& display_rect,
- QuadList* quad_list,
- const gfx::Rect& quad_rectangle,
- const gfx::RectF& occlusion_bounding_box,
- QuadList::Iterator* it,
- gfx::Rect* damage_rect) {
- bool display_rect_changed = (display_rect != previous_display_rect_);
- if (!occlusion_bounding_box.IsEmpty())
- return false;
- // The quad is on top, so promote it to an overlay and remove all damage
- // underneath it.
- if ((*it)
- ->shared_quad_state->quad_to_target_transform
- .Preserves2dAxisAlignment() &&
- !display_rect_changed && !(*it)->ShouldDrawWithBlending()) {
- damage_rect->Subtract(quad_rectangle);
- }
- *it = quad_list->EraseAndInvalidateAllPointers(*it);
- return true;
-}
-
-bool DCLayerOverlayProcessor::ProcessForUnderlay(
- const gfx::RectF& display_rect,
- RenderPass* render_pass,
- const gfx::Rect& quad_rectangle,
- const gfx::RectF& occlusion_bounding_box,
- const QuadList::Iterator& it,
- bool is_root,
- gfx::Rect* damage_rect,
- gfx::Rect* this_frame_underlay_rect,
- DCLayerOverlay* dc_layer) {
- if (!dc_layer->require_overlay) {
- if (!base::FeatureList::IsEnabled(features::kDirectCompositionUnderlays)) {
- RecordDCLayerResult(DC_LAYER_FAILED_OCCLUDED);
- return false;
- }
- if (!is_root) {
- RecordDCLayerResult(DC_LAYER_FAILED_NON_ROOT);
- return false;
- }
- if (processed_overlay_in_frame_) {
- RecordDCLayerResult(DC_LAYER_FAILED_TOO_MANY_OVERLAYS);
- return false;
- }
- if ((it->shared_quad_state->opacity < 1.0)) {
- RecordDCLayerResult(DC_LAYER_FAILED_TRANSPARENT);
- return false;
- }
- }
- bool display_rect_changed = (display_rect != previous_display_rect_);
- // The quad is occluded, so replace it with a black solid color quad and
- // place the overlay itself under the quad.
- if (is_root && it->shared_quad_state->quad_to_target_transform
- .IsIdentityOrIntegerTranslation()) {
- *this_frame_underlay_rect = quad_rectangle;
- }
- dc_layer->shared_state->z_order = -1;
- const viz::SharedQuadState* shared_quad_state = it->shared_quad_state;
- gfx::Rect rect = it->visible_rect;
-
- if (shared_quad_state->opacity < 1.0) {
- viz::SharedQuadState* new_shared_quad_state =
- render_pass->shared_quad_state_list.AllocateAndCopyFrom(
- shared_quad_state);
- new_shared_quad_state->blend_mode = SkBlendMode::kDstOut;
- SolidColorDrawQuad* replacement =
- render_pass->quad_list.ReplaceExistingElement<SolidColorDrawQuad>(it);
- replacement->SetAll(shared_quad_state, rect, rect, false, 0xff000000, true);
- } else {
- // When the opacity == 1.0, drawing with transparent will be done without
- // blending and will have the proper effect of completely clearing the
- // layer.
- render_pass->quad_list.ReplaceExistingQuadWithOpaqueTransparentSolidColor(
- it);
- }
-
- if (*this_frame_underlay_rect == previous_frame_underlay_rect_ && is_root &&
- !processed_overlay_in_frame_) {
- // If this underlay rect is the same as for last frame, subtract its
- // area from the damage of the main surface, as the cleared area was
- // already cleared last frame. Add back the damage from the occluded
- // area for this and last frame, as that may have changed.
- if (it->shared_quad_state->quad_to_target_transform
- .Preserves2dAxisAlignment() &&
- !display_rect_changed) {
- gfx::Rect occluding_damage_rect = *damage_rect;
- occluding_damage_rect.Intersect(quad_rectangle);
- damage_rect->Subtract(quad_rectangle);
- gfx::Rect new_occlusion_bounding_box =
- gfx::ToEnclosingRect(occlusion_bounding_box);
- new_occlusion_bounding_box.Union(previous_occlusion_bounding_box_);
- occluding_damage_rect.Intersect(new_occlusion_bounding_box);
-
- damage_rect->Union(occluding_damage_rect);
- }
- } else {
- // Entire replacement quad must be redrawn.
- damage_rect->Union(quad_rectangle);
- }
- PunchThroughRect info;
- info.rect = gfx::ToEnclosingRect(dc_layer->bounds_rect);
- info.transform_to_target = shared_quad_state->quad_to_target_transform;
- info.opacity = shared_quad_state->opacity;
- pass_info_[render_pass->id].push_back(info);
-
- previous_occlusion_bounding_box_ =
- gfx::ToEnclosingRect(occlusion_bounding_box);
- return true;
-}
-
-} // namespace cc
diff --git a/chromium/cc/output/dc_layer_overlay.h b/chromium/cc/output/dc_layer_overlay.h
deleted file mode 100644
index 4f3b68e92b5..00000000000
--- a/chromium/cc/output/dc_layer_overlay.h
+++ /dev/null
@@ -1,159 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_DC_LAYER_OVERLAY_H_
-#define CC_OUTPUT_DC_LAYER_OVERLAY_H_
-
-#include "base/containers/flat_map.h"
-#include "base/memory/ref_counted.h"
-#include "cc/quads/render_pass.h"
-#include "third_party/skia/include/core/SkColor.h"
-#include "third_party/skia/include/core/SkMatrix44.h"
-#include "ui/gfx/geometry/rect_f.h"
-#include "ui/gl/dc_renderer_layer_params.h"
-
-namespace cc {
-class DrawQuad;
-class ResourceProvider;
-
-class CC_EXPORT DCLayerOverlaySharedState
- : public base::RefCounted<DCLayerOverlaySharedState> {
- public:
- DCLayerOverlaySharedState() {}
- int z_order = 0;
- // If |is_clipped| is true, then clip to |clip_rect| in the target space.
- bool is_clipped = false;
- gfx::RectF clip_rect;
- // The opacity property for the CAayer.
- float opacity = 1;
- // The transform to apply to the DCLayer.
- SkMatrix44 transform = SkMatrix44(SkMatrix44::kIdentity_Constructor);
-
- private:
- friend class base::RefCounted<DCLayerOverlaySharedState>;
- ~DCLayerOverlaySharedState() {}
-};
-
-// Holds all information necessary to construct a DCLayer from a DrawQuad.
-class CC_EXPORT DCLayerOverlay {
- public:
- DCLayerOverlay();
- DCLayerOverlay(const DCLayerOverlay& other);
- ~DCLayerOverlay();
-
- // State that is frequently shared between consecutive DCLayerOverlays.
- scoped_refptr<DCLayerOverlaySharedState> shared_state;
-
- // Resource ids that correspond to the DXGI textures to set as the contents
- // of the DCLayer.
- DrawQuad::Resources resources;
- // The contents rect property for the DCLayer.
- gfx::RectF contents_rect;
- // The bounds for the DCLayer in pixels.
- gfx::RectF bounds_rect;
- // The background color property for the DCLayer.
- SkColor background_color = SK_ColorTRANSPARENT;
- // The edge anti-aliasing mask property for the DCLayer.
- unsigned edge_aa_mask = 0;
- // The minification and magnification filters for the DCLayer.
- unsigned filter;
- // If |rpdq| is present, then the renderer must draw the filter effects and
- // copy the result into an IOSurface.
- const RenderPassDrawQuad* rpdq = nullptr;
-
- // This is the color-space the texture should be displayed as. If invalid,
- // then the default for the texture should be used. For YUV textures, that's
- // normally BT.709.
- gfx::ColorSpace color_space;
-
- bool require_overlay = false;
-};
-
-typedef std::vector<DCLayerOverlay> DCLayerOverlayList;
-
-class DCLayerOverlayProcessor {
- public:
- // This is used for a histogram to determine why overlays are or aren't
- // used, so don't remove entries and make sure to update enums.xml if
- // it changes.
- enum DCLayerResult {
- DC_LAYER_SUCCESS,
- DC_LAYER_FAILED_UNSUPPORTED_QUAD,
- DC_LAYER_FAILED_QUAD_BLEND_MODE,
- DC_LAYER_FAILED_TEXTURE_NOT_CANDIDATE,
- DC_LAYER_FAILED_OCCLUDED,
- DC_LAYER_FAILED_COMPLEX_TRANSFORM,
- DC_LAYER_FAILED_TRANSPARENT,
- DC_LAYER_FAILED_NON_ROOT,
- DC_LAYER_FAILED_TOO_MANY_OVERLAYS,
- DC_LAYER_FAILED_MAX,
- };
-
- DCLayerOverlayProcessor();
- ~DCLayerOverlayProcessor();
-
- void Process(ResourceProvider* resource_provider,
- const gfx::RectF& display_rect,
- RenderPassList* render_passes,
- gfx::Rect* overlay_damage_rect,
- gfx::Rect* damage_rect,
- DCLayerOverlayList* ca_layer_overlays);
- void ClearOverlayState() {
- previous_frame_underlay_rect_ = gfx::Rect();
- previous_occlusion_bounding_box_ = gfx::Rect();
- }
-
- private:
- DCLayerResult FromDrawQuad(ResourceProvider* resource_provider,
- const gfx::RectF& display_rect,
- QuadList::ConstIterator quad_list_begin,
- QuadList::ConstIterator quad,
- DCLayerOverlay* ca_layer_overlay);
- // Returns an iterator to the element after |it|.
- QuadList::Iterator ProcessRenderPassDrawQuad(RenderPass* render_pass,
- gfx::Rect* damage_rect,
- QuadList::Iterator it);
- void ProcessRenderPass(ResourceProvider* resource_provider,
- const gfx::RectF& display_rect,
- RenderPass* render_pass,
- bool is_root,
- gfx::Rect* overlay_damage_rect,
- gfx::Rect* damage_rect,
- DCLayerOverlayList* ca_layer_overlays);
- bool ProcessForOverlay(const gfx::RectF& display_rect,
- QuadList* quad_list,
- const gfx::Rect& quad_rectangle,
- const gfx::RectF& occlusion_bounding_box,
- QuadList::Iterator* it,
- gfx::Rect* damage_rect);
- bool ProcessForUnderlay(const gfx::RectF& display_rect,
- RenderPass* render_pass,
- const gfx::Rect& quad_rectangle,
- const gfx::RectF& occlusion_bounding_box,
- const QuadList::Iterator& it,
- bool is_root,
- gfx::Rect* damage_rect,
- gfx::Rect* this_frame_underlay_rect,
- DCLayerOverlay* dc_layer);
-
- gfx::Rect previous_frame_underlay_rect_;
- gfx::Rect previous_occlusion_bounding_box_;
- gfx::RectF previous_display_rect_;
- bool processed_overlay_in_frame_ = false;
-
- // Store information about punch-through rectangles for non-root
- // RenderPasses. These rectangles are used to clear the corresponding areas
- // in parent renderpasses.
- struct PunchThroughRect {
- gfx::Rect rect;
- gfx::Transform transform_to_target;
- float opacity;
- };
-
- base::flat_map<RenderPassId, std::vector<PunchThroughRect>> pass_info_;
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_DC_LAYER_OVERLAY_H_
diff --git a/chromium/cc/output/direct_renderer.cc b/chromium/cc/output/direct_renderer.cc
deleted file mode 100644
index 6bac6ccac06..00000000000
--- a/chromium/cc/output/direct_renderer.cc
+++ /dev/null
@@ -1,671 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/direct_renderer.h"
-
-#include <stddef.h>
-
-#include <utility>
-#include <vector>
-
-#include "base/auto_reset.h"
-#include "base/metrics/histogram_macros.h"
-#include "base/numerics/safe_conversions.h"
-#include "base/trace_event/trace_event.h"
-#include "cc/base/math_util.h"
-#include "cc/output/bsp_tree.h"
-#include "cc/output/bsp_walk_action.h"
-#include "cc/output/output_surface.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/resources/scoped_resource.h"
-#include "components/viz/common/display/renderer_settings.h"
-#include "components/viz/common/quads/copy_output_request.h"
-#include "ui/gfx/geometry/quad_f.h"
-#include "ui/gfx/geometry/rect_conversions.h"
-#include "ui/gfx/transform.h"
-
-namespace {
-
-static gfx::Transform OrthoProjectionMatrix(float left,
- float right,
- float bottom,
- float top) {
- // Use the standard formula to map the clipping frustum to the cube from
- // [-1, -1, -1] to [1, 1, 1].
- float delta_x = right - left;
- float delta_y = top - bottom;
- gfx::Transform proj;
- if (!delta_x || !delta_y)
- return proj;
- proj.matrix().set(0, 0, 2.0f / delta_x);
- proj.matrix().set(0, 3, -(right + left) / delta_x);
- proj.matrix().set(1, 1, 2.0f / delta_y);
- proj.matrix().set(1, 3, -(top + bottom) / delta_y);
-
- // Z component of vertices is always set to zero as we don't use the depth
- // buffer while drawing.
- proj.matrix().set(2, 2, 0);
-
- return proj;
-}
-
-static gfx::Transform window_matrix(int x, int y, int width, int height) {
- gfx::Transform canvas;
-
- // Map to window position and scale up to pixel coordinates.
- canvas.Translate3d(x, y, 0);
- canvas.Scale3d(width, height, 0);
-
- // Map from ([-1, -1] to [1, 1]) -> ([0, 0] to [1, 1])
- canvas.Translate3d(0.5, 0.5, 0.5);
- canvas.Scale3d(0.5, 0.5, 0.5);
-
- return canvas;
-}
-
-// Switching between enabling DC layers and not is expensive, so only
-// switch away after a large number of frames not needing DC layers have
-// been produced.
-constexpr int kNumberOfFramesBeforeDisablingDCLayers = 60;
-
-} // namespace
-
-namespace cc {
-
-DirectRenderer::DrawingFrame::DrawingFrame() = default;
-DirectRenderer::DrawingFrame::~DrawingFrame() = default;
-
-DirectRenderer::DirectRenderer(const viz::RendererSettings* settings,
- OutputSurface* output_surface,
- DisplayResourceProvider* resource_provider)
- : settings_(settings),
- output_surface_(output_surface),
- resource_provider_(resource_provider),
- overlay_processor_(new OverlayProcessor(output_surface)) {}
-
-DirectRenderer::~DirectRenderer() = default;
-
-void DirectRenderer::Initialize() {
- overlay_processor_->Initialize();
-
- auto* context_provider = output_surface_->context_provider();
-
- use_partial_swap_ = settings_->partial_swap_enabled && CanPartialSwap();
- allow_empty_swap_ = use_partial_swap_;
- if (context_provider) {
- if (context_provider->ContextCapabilities().commit_overlay_planes)
- allow_empty_swap_ = true;
- if (context_provider->ContextCapabilities().dc_layers)
- supports_dc_layers_ = true;
- if (context_provider->ContextCapabilities()
- .disable_non_empty_post_sub_buffers) {
- use_partial_swap_ = false;
- }
- }
-
- initialized_ = true;
-}
-
-// static
-gfx::RectF DirectRenderer::QuadVertexRect() {
- return gfx::RectF(-0.5f, -0.5f, 1.f, 1.f);
-}
-
-// static
-void DirectRenderer::QuadRectTransform(gfx::Transform* quad_rect_transform,
- const gfx::Transform& quad_transform,
- const gfx::RectF& quad_rect) {
- *quad_rect_transform = quad_transform;
- quad_rect_transform->Translate(0.5 * quad_rect.width() + quad_rect.x(),
- 0.5 * quad_rect.height() + quad_rect.y());
- quad_rect_transform->Scale(quad_rect.width(), quad_rect.height());
-}
-
-void DirectRenderer::InitializeViewport(DrawingFrame* frame,
- const gfx::Rect& draw_rect,
- const gfx::Rect& viewport_rect,
- const gfx::Size& surface_size) {
- DCHECK_GE(viewport_rect.x(), 0);
- DCHECK_GE(viewport_rect.y(), 0);
- DCHECK_LE(viewport_rect.right(), surface_size.width());
- DCHECK_LE(viewport_rect.bottom(), surface_size.height());
- bool flip_y = FlippedFramebuffer();
- if (flip_y) {
- frame->projection_matrix = OrthoProjectionMatrix(
- draw_rect.x(), draw_rect.right(), draw_rect.bottom(), draw_rect.y());
- } else {
- frame->projection_matrix = OrthoProjectionMatrix(
- draw_rect.x(), draw_rect.right(), draw_rect.y(), draw_rect.bottom());
- }
-
- gfx::Rect window_rect = viewport_rect;
- if (flip_y)
- window_rect.set_y(surface_size.height() - viewport_rect.bottom());
- frame->window_matrix =
- window_matrix(window_rect.x(), window_rect.y(), window_rect.width(),
- window_rect.height());
- current_draw_rect_ = draw_rect;
- current_viewport_rect_ = viewport_rect;
- current_surface_size_ = surface_size;
- current_window_space_viewport_ = window_rect;
-}
-
-gfx::Rect DirectRenderer::MoveFromDrawToWindowSpace(
- const gfx::Rect& draw_rect) const {
- gfx::Rect window_rect = draw_rect;
- window_rect -= current_draw_rect_.OffsetFromOrigin();
- window_rect += current_viewport_rect_.OffsetFromOrigin();
- if (FlippedFramebuffer())
- window_rect.set_y(current_surface_size_.height() - window_rect.bottom());
- return window_rect;
-}
-
-const TileDrawQuad* DirectRenderer::CanPassBeDrawnDirectly(
- const RenderPass* pass) {
- return nullptr;
-}
-
-void DirectRenderer::SetVisible(bool visible) {
- DCHECK(initialized_);
- if (visible_ == visible)
- return;
- visible_ = visible;
- DidChangeVisibility();
-}
-
-void DirectRenderer::DecideRenderPassAllocationsForFrame(
- const RenderPassList& render_passes_in_draw_order) {
- render_pass_bypass_quads_.clear();
-
- auto& root_render_pass = render_passes_in_draw_order.back();
-
- base::flat_map<RenderPassId, gfx::Size> render_passes_in_frame;
- for (const auto& pass : render_passes_in_draw_order) {
- if (pass != root_render_pass) {
- if (const TileDrawQuad* tile_quad = CanPassBeDrawnDirectly(pass.get())) {
- // If the render pass is drawn directly, it will not be drawn from as
- // a render pass so it's not added to the map.
- render_pass_bypass_quads_[pass->id] = *tile_quad;
- continue;
- }
- }
- render_passes_in_frame[pass->id] = RenderPassTextureSize(pass.get());
- }
-
- std::vector<RenderPassId> passes_to_delete;
- for (const auto& pair : render_pass_textures_) {
- auto it = render_passes_in_frame.find(pair.first);
- if (it == render_passes_in_frame.end()) {
- passes_to_delete.push_back(pair.first);
- continue;
- }
-
- gfx::Size required_size = it->second;
- ScopedResource* texture = pair.second.get();
- DCHECK(texture);
-
- bool size_appropriate = texture->size().width() >= required_size.width() &&
- texture->size().height() >= required_size.height();
- if (texture->id() && !size_appropriate)
- texture->Free();
- }
-
- // Delete RenderPass textures from the previous frame that will not be used
- // again.
- for (size_t i = 0; i < passes_to_delete.size(); ++i)
- render_pass_textures_.erase(passes_to_delete[i]);
-
- for (auto& pass : render_passes_in_draw_order) {
- auto& resource = render_pass_textures_[pass->id];
- if (!resource) {
- resource = std::make_unique<ScopedResource>(resource_provider_);
-
- // |has_damage_from_contributing_content| is used to determine if previous
- // contents can be reused when caching render pass and as a result needs
- // to be true when a new resource is created to ensure that it is updated
- // and not assumed to already contain correct contents.
- pass->has_damage_from_contributing_content = true;
- }
- }
-}
-
-void DirectRenderer::DrawFrame(RenderPassList* render_passes_in_draw_order,
- float device_scale_factor,
- const gfx::Size& device_viewport_size) {
- DCHECK(visible_);
- TRACE_EVENT0("cc", "DirectRenderer::DrawFrame");
- UMA_HISTOGRAM_COUNTS(
- "Renderer4.renderPassCount",
- base::saturated_cast<int>(render_passes_in_draw_order->size()));
-
- RenderPass* root_render_pass = render_passes_in_draw_order->back().get();
- DCHECK(root_render_pass);
-
- bool overdraw_tracing_enabled;
- TRACE_EVENT_CATEGORY_GROUP_ENABLED(
- TRACE_DISABLED_BY_DEFAULT("cc.debug.overdraw"),
- &overdraw_tracing_enabled);
- bool overdraw_feedback =
- settings_->show_overdraw_feedback || overdraw_tracing_enabled;
- if (overdraw_feedback && !output_surface_->capabilities().supports_stencil) {
-#if DCHECK_IS_ON()
- DLOG_IF(WARNING, !overdraw_feedback_support_missing_logged_once_)
- << "Overdraw feedback enabled on platform without support.";
- overdraw_feedback_support_missing_logged_once_ = true;
-#endif
- overdraw_feedback = false;
- }
- base::AutoReset<bool> auto_reset_overdraw_feedback(&overdraw_feedback_,
- overdraw_feedback);
-
- current_frame_valid_ = true;
- current_frame_ = DrawingFrame();
- current_frame()->render_passes_in_draw_order = render_passes_in_draw_order;
- current_frame()->root_render_pass = root_render_pass;
- current_frame()->root_damage_rect = root_render_pass->damage_rect;
- current_frame()->root_damage_rect.Union(
- overlay_processor_->GetAndResetOverlayDamage());
- current_frame()->root_damage_rect.Intersect(gfx::Rect(device_viewport_size));
- current_frame()->device_viewport_size = device_viewport_size;
-
- // Only reshape when we know we are going to draw. Otherwise, the reshape
- // can leave the window at the wrong size if we never draw and the proper
- // viewport size is never set.
- bool frame_has_alpha =
- current_frame()->root_render_pass->has_transparent_background;
- bool use_stencil = overdraw_feedback_;
- bool did_reshape = false;
- if (device_viewport_size != reshape_surface_size_ ||
- device_scale_factor != reshape_device_scale_factor_ ||
- root_render_pass->color_space != reshape_device_color_space_ ||
- frame_has_alpha != reshape_has_alpha_ ||
- use_stencil != reshape_use_stencil_) {
- reshape_surface_size_ = device_viewport_size;
- reshape_device_scale_factor_ = device_scale_factor;
- reshape_device_color_space_ = root_render_pass->color_space;
- reshape_has_alpha_ =
- current_frame()->root_render_pass->has_transparent_background;
- reshape_use_stencil_ = overdraw_feedback_;
- output_surface_->Reshape(
- reshape_surface_size_, reshape_device_scale_factor_,
- reshape_device_color_space_, reshape_has_alpha_, reshape_use_stencil_);
- did_reshape = true;
- }
-
- BeginDrawingFrame();
-
- for (const auto& pass : *render_passes_in_draw_order) {
- if (!pass->filters.IsEmpty())
- render_pass_filters_[pass->id] = &pass->filters;
- if (!pass->background_filters.IsEmpty())
- render_pass_background_filters_[pass->id] = &pass->background_filters;
- }
-
- // Create the overlay candidate for the output surface, and mark it as
- // always handled.
- if (output_surface_->IsDisplayedAsOverlayPlane()) {
- OverlayCandidate output_surface_plane;
- output_surface_plane.display_rect =
- gfx::RectF(device_viewport_size.width(), device_viewport_size.height());
- output_surface_plane.format = output_surface_->GetOverlayBufferFormat();
- output_surface_plane.use_output_surface_for_resource = true;
- output_surface_plane.overlay_handled = true;
- current_frame()->overlay_list.push_back(output_surface_plane);
- }
-
- // Attempt to replace some or all of the quads of the root render pass with
- // overlays.
- overlay_processor_->ProcessForOverlays(
- resource_provider_, render_passes_in_draw_order, render_pass_filters_,
- render_pass_background_filters_, &current_frame()->overlay_list,
- &current_frame()->ca_layer_overlay_list,
- &current_frame()->dc_layer_overlay_list,
- &current_frame()->root_damage_rect,
- &current_frame()->root_content_bounds);
-
- // Draw all non-root render passes except for the root render pass.
- for (const auto& pass : *render_passes_in_draw_order) {
- if (pass.get() == root_render_pass)
- break;
- DrawRenderPassAndExecuteCopyRequests(pass.get());
- }
-
- bool was_using_dc_layers = using_dc_layers_;
- if (!current_frame()->dc_layer_overlay_list.empty()) {
- DCHECK(supports_dc_layers_);
- using_dc_layers_ = true;
- frames_since_using_dc_layers_ = 0;
- } else if (++frames_since_using_dc_layers_ >=
- kNumberOfFramesBeforeDisablingDCLayers) {
- using_dc_layers_ = false;
- }
- if (supports_dc_layers_ &&
- (did_reshape || (was_using_dc_layers != using_dc_layers_))) {
- // The entire surface has to be redrawn if it was reshaped or if switching
- // from or to DirectComposition layers, because the previous contents are
- // discarded and some contents would otherwise be undefined.
- current_frame()->root_damage_rect = gfx::Rect(device_viewport_size);
- }
-
- // We can skip all drawing if the damage rect is now empty.
- bool skip_drawing_root_render_pass =
- current_frame()->root_damage_rect.IsEmpty() && allow_empty_swap_;
-
- // If we have to draw but don't support partial swap, the whole output should
- // be considered damaged.
- if (!skip_drawing_root_render_pass && !use_partial_swap_)
- current_frame()->root_damage_rect = gfx::Rect(device_viewport_size);
-
- if (!skip_drawing_root_render_pass)
- DrawRenderPassAndExecuteCopyRequests(root_render_pass);
-
- FinishDrawingFrame();
- render_passes_in_draw_order->clear();
- render_pass_filters_.clear();
- render_pass_background_filters_.clear();
-
- current_frame_valid_ = false;
-}
-
-gfx::Rect DirectRenderer::DrawingFrame::ComputeScissorRectForRenderPass()
- const {
- if (current_render_pass == root_render_pass)
- return root_damage_rect;
-
- // If the root damage rect has been expanded due to overlays, all the other
- // damage rect calculations are incorrect.
- if (!root_render_pass->damage_rect.Contains(root_damage_rect))
- return current_render_pass->output_rect;
-
- DCHECK(
- current_render_pass->copy_requests.empty() ||
- (current_render_pass->damage_rect == current_render_pass->output_rect));
- return current_render_pass->damage_rect;
-}
-
-gfx::Rect DirectRenderer::DeviceViewportRectInDrawSpace() const {
- gfx::Rect device_viewport_rect(current_frame()->device_viewport_size);
- device_viewport_rect -= current_viewport_rect_.OffsetFromOrigin();
- device_viewport_rect += current_draw_rect_.OffsetFromOrigin();
- return device_viewport_rect;
-}
-
-gfx::Rect DirectRenderer::OutputSurfaceRectInDrawSpace() const {
- if (current_frame()->current_render_pass ==
- current_frame()->root_render_pass) {
- gfx::Rect output_surface_rect(current_frame()->device_viewport_size);
- output_surface_rect -= current_viewport_rect_.OffsetFromOrigin();
- output_surface_rect += current_draw_rect_.OffsetFromOrigin();
- return output_surface_rect;
- } else {
- return current_frame()->current_render_pass->output_rect;
- }
-}
-
-bool DirectRenderer::ShouldSkipQuad(const DrawQuad& quad,
- const gfx::Rect& render_pass_scissor) {
- if (render_pass_scissor.IsEmpty())
- return true;
-
- gfx::Rect target_rect = MathUtil::MapEnclosingClippedRect(
- quad.shared_quad_state->quad_to_target_transform, quad.visible_rect);
- if (quad.shared_quad_state->is_clipped)
- target_rect.Intersect(quad.shared_quad_state->clip_rect);
-
- target_rect.Intersect(render_pass_scissor);
- return target_rect.IsEmpty();
-}
-
-void DirectRenderer::SetScissorStateForQuad(
- const DrawQuad& quad,
- const gfx::Rect& render_pass_scissor,
- bool use_render_pass_scissor) {
- if (use_render_pass_scissor) {
- gfx::Rect quad_scissor_rect = render_pass_scissor;
- if (quad.shared_quad_state->is_clipped)
- quad_scissor_rect.Intersect(quad.shared_quad_state->clip_rect);
- SetScissorTestRectInDrawSpace(quad_scissor_rect);
- return;
- } else if (quad.shared_quad_state->is_clipped) {
- SetScissorTestRectInDrawSpace(quad.shared_quad_state->clip_rect);
- return;
- }
-
- EnsureScissorTestDisabled();
-}
-
-void DirectRenderer::SetScissorTestRectInDrawSpace(
- const gfx::Rect& draw_space_rect) {
- gfx::Rect window_space_rect = MoveFromDrawToWindowSpace(draw_space_rect);
- SetScissorTestRect(window_space_rect);
-}
-
-void DirectRenderer::DoDrawPolygon(const DrawPolygon& poly,
- const gfx::Rect& render_pass_scissor,
- bool use_render_pass_scissor) {
- SetScissorStateForQuad(*poly.original_ref(), render_pass_scissor,
- use_render_pass_scissor);
-
- // If the poly has not been split, then it is just a normal DrawQuad,
- // and we should save any extra processing that would have to be done.
- if (!poly.is_split()) {
- DoDrawQuad(poly.original_ref(), NULL);
- return;
- }
-
- std::vector<gfx::QuadF> quads;
- poly.ToQuads2D(&quads);
- for (size_t i = 0; i < quads.size(); ++i) {
- DoDrawQuad(poly.original_ref(), &quads[i]);
- }
-}
-
-const FilterOperations* DirectRenderer::FiltersForPass(
- RenderPassId render_pass_id) const {
- auto it = render_pass_filters_.find(render_pass_id);
- return it == render_pass_filters_.end() ? nullptr : it->second;
-}
-
-const FilterOperations* DirectRenderer::BackgroundFiltersForPass(
- RenderPassId render_pass_id) const {
- auto it = render_pass_background_filters_.find(render_pass_id);
- return it == render_pass_background_filters_.end() ? nullptr : it->second;
-}
-
-void DirectRenderer::FlushPolygons(
- std::deque<std::unique_ptr<DrawPolygon>>* poly_list,
- const gfx::Rect& render_pass_scissor,
- bool use_render_pass_scissor) {
- if (poly_list->empty()) {
- return;
- }
-
- BspTree bsp_tree(poly_list);
- BspWalkActionDrawPolygon action_handler(this, render_pass_scissor,
- use_render_pass_scissor);
- bsp_tree.TraverseWithActionHandler(&action_handler);
- DCHECK(poly_list->empty());
-}
-
-void DirectRenderer::DrawRenderPassAndExecuteCopyRequests(
- RenderPass* render_pass) {
- if (render_pass_bypass_quads_.find(render_pass->id) !=
- render_pass_bypass_quads_.end()) {
- return;
- }
-
- // Repeated draw to simulate a slower device for the evaluation of performance
- // improvements in UI effects.
- for (int i = 0; i < settings_->slow_down_compositing_scale_factor; ++i)
- DrawRenderPass(render_pass);
-
- bool first_request = true;
- for (auto& copy_request : render_pass->copy_requests) {
- // Doing a readback is destructive of our state on Mac, so make sure
- // we restore the state between readbacks. http://crbug.com/99393.
- if (!first_request)
- UseRenderPass(render_pass);
- CopyCurrentRenderPassToBitmap(std::move(copy_request));
- first_request = false;
- }
-}
-
-void DirectRenderer::DrawRenderPass(const RenderPass* render_pass) {
- TRACE_EVENT0("cc", "DirectRenderer::DrawRenderPass");
- if (!UseRenderPass(render_pass))
- return;
-
- const gfx::Rect surface_rect_in_draw_space = OutputSurfaceRectInDrawSpace();
- gfx::Rect render_pass_scissor_in_draw_space = surface_rect_in_draw_space;
-
- if (current_frame()->current_render_pass ==
- current_frame()->root_render_pass) {
- render_pass_scissor_in_draw_space.Intersect(
- DeviceViewportRectInDrawSpace());
- }
-
- if (use_partial_swap_) {
- render_pass_scissor_in_draw_space.Intersect(
- current_frame()->ComputeScissorRectForRenderPass());
- }
-
- bool is_root_render_pass =
- current_frame()->current_render_pass == current_frame()->root_render_pass;
-
- bool render_pass_is_clipped =
- !render_pass_scissor_in_draw_space.Contains(surface_rect_in_draw_space);
-
- // The SetDrawRectangleCHROMIUM spec requires that the scissor bit is always
- // set on the root framebuffer or else the rendering may modify something
- // outside the damage rectangle, even if the damage rectangle is the size of
- // the full backbuffer.
- bool render_pass_requires_scissor =
- (supports_dc_layers_ && is_root_render_pass) || render_pass_is_clipped;
- bool has_external_stencil_test =
- is_root_render_pass && output_surface_->HasExternalStencilTest();
- bool should_clear_surface =
- !has_external_stencil_test &&
- (!is_root_render_pass || settings_->should_clear_root_render_pass);
-
- // If |has_external_stencil_test| we can't discard or clear. Make sure we
- // don't need to.
- DCHECK(!has_external_stencil_test ||
- !current_frame()->current_render_pass->has_transparent_background);
-
- SurfaceInitializationMode mode;
- if (should_clear_surface && render_pass_requires_scissor) {
- mode = SURFACE_INITIALIZATION_MODE_SCISSORED_CLEAR;
- } else if (should_clear_surface) {
- mode = SURFACE_INITIALIZATION_MODE_FULL_SURFACE_CLEAR;
- } else {
- mode = SURFACE_INITIALIZATION_MODE_PRESERVE;
- }
-
- PrepareSurfaceForPass(
- mode, MoveFromDrawToWindowSpace(render_pass_scissor_in_draw_space));
-
- const QuadList& quad_list = render_pass->quad_list;
- std::deque<std::unique_ptr<DrawPolygon>> poly_list;
-
- int next_polygon_id = 0;
- int last_sorting_context_id = 0;
- for (auto it = quad_list.BackToFrontBegin(); it != quad_list.BackToFrontEnd();
- ++it) {
- const DrawQuad& quad = **it;
-
- if (render_pass_is_clipped &&
- ShouldSkipQuad(quad, render_pass_scissor_in_draw_space)) {
- continue;
- }
-
- if (last_sorting_context_id != quad.shared_quad_state->sorting_context_id) {
- last_sorting_context_id = quad.shared_quad_state->sorting_context_id;
- FlushPolygons(&poly_list, render_pass_scissor_in_draw_space,
- render_pass_requires_scissor);
- }
-
- // This layer is in a 3D sorting context so we add it to the list of
- // polygons to go into the BSP tree.
- if (quad.shared_quad_state->sorting_context_id != 0) {
- std::unique_ptr<DrawPolygon> new_polygon(new DrawPolygon(
- *it, gfx::RectF(quad.visible_rect),
- quad.shared_quad_state->quad_to_target_transform, next_polygon_id++));
- if (new_polygon->points().size() > 2u) {
- poly_list.push_back(std::move(new_polygon));
- }
- continue;
- }
-
- // We are not in a 3d sorting context, so we should draw the quad normally.
- SetScissorStateForQuad(quad, render_pass_scissor_in_draw_space,
- render_pass_requires_scissor);
-
- DoDrawQuad(&quad, nullptr);
- }
- FlushPolygons(&poly_list, render_pass_scissor_in_draw_space,
- render_pass_requires_scissor);
- FinishDrawingQuadList();
-}
-
-bool DirectRenderer::UseRenderPass(const RenderPass* render_pass) {
- current_frame()->current_render_pass = render_pass;
- current_frame()->current_texture = nullptr;
- if (render_pass == current_frame()->root_render_pass) {
- BindFramebufferToOutputSurface();
-
- if (supports_dc_layers_) {
- SetEnableDCLayers(using_dc_layers_);
- output_surface_->SetDrawRectangle(current_frame()->root_damage_rect);
- }
- InitializeViewport(current_frame(), render_pass->output_rect,
- gfx::Rect(current_frame()->device_viewport_size),
- current_frame()->device_viewport_size);
- return true;
- }
-
- ScopedResource* texture = render_pass_textures_[render_pass->id].get();
- DCHECK(texture);
-
- gfx::Size size = RenderPassTextureSize(render_pass);
- size.Enlarge(enlarge_pass_texture_amount_.width(),
- enlarge_pass_texture_amount_.height());
- if (!texture->id()) {
- texture->Allocate(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE_FRAMEBUFFER,
- BackbufferFormat(), current_frame()->current_render_pass->color_space);
- } else if (render_pass->cache_render_pass &&
- !render_pass->has_damage_from_contributing_content) {
- return false;
- } else if (current_frame()->ComputeScissorRectForRenderPass().IsEmpty()) {
- return false;
- }
- DCHECK(texture->id());
-
- if (BindFramebufferToTexture(texture)) {
- InitializeViewport(current_frame(), render_pass->output_rect,
- gfx::Rect(render_pass->output_rect.size()),
- texture->size());
- return true;
- }
-
- return false;
-}
-
-bool DirectRenderer::HasAllocatedResourcesForTesting(
- RenderPassId render_pass_id) const {
- auto iter = render_pass_textures_.find(render_pass_id);
- return iter != render_pass_textures_.end() && iter->second->id();
-}
-
-// static
-gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) {
- return render_pass->output_rect.size();
-}
-
-void DirectRenderer::SetCurrentFrameForTesting(const DrawingFrame& frame) {
- current_frame_valid_ = true;
- current_frame_ = frame;
-}
-
-} // namespace cc
diff --git a/chromium/cc/output/direct_renderer.h b/chromium/cc/output/direct_renderer.h
deleted file mode 100644
index 0cec4d429a8..00000000000
--- a/chromium/cc/output/direct_renderer.h
+++ /dev/null
@@ -1,266 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_DIRECT_RENDERER_H_
-#define CC_OUTPUT_DIRECT_RENDERER_H_
-
-#include <memory>
-#include <vector>
-
-#include "base/callback.h"
-#include "base/containers/flat_map.h"
-#include "base/macros.h"
-#include "cc/base/filter_operations.h"
-#include "cc/cc_export.h"
-#include "cc/output/ca_layer_overlay.h"
-#include "cc/output/dc_layer_overlay.h"
-#include "cc/output/overlay_processor.h"
-#include "cc/quads/tile_draw_quad.h"
-#include "cc/resources/display_resource_provider.h"
-#include "gpu/command_buffer/common/texture_in_use_response.h"
-#include "ui/gfx/geometry/quad_f.h"
-#include "ui/gfx/geometry/rect.h"
-#include "ui/latency/latency_info.h"
-
-namespace gfx {
-class ColorSpace;
-}
-
-namespace viz {
-class RendererSettings;
-}
-
-namespace cc {
-class DisplayResourceProvider;
-class DrawPolygon;
-class OutputSurface;
-class RenderPass;
-class ScopedResource;
-
-// This is the base class for code shared between the GL and software
-// renderer implementations. "Direct" refers to the fact that it does not
-// delegate rendering to another compositor (see historical DelegatingRenderer
-// for reference).
-class CC_EXPORT DirectRenderer {
- public:
- DirectRenderer(const viz::RendererSettings* settings,
- OutputSurface* output_surface,
- DisplayResourceProvider* resource_provider);
- virtual ~DirectRenderer();
-
- void Initialize();
-
- bool use_partial_swap() const { return use_partial_swap_; }
-
- void SetVisible(bool visible);
- void DecideRenderPassAllocationsForFrame(
- const RenderPassList& render_passes_in_draw_order);
- bool HasAllocatedResourcesForTesting(RenderPassId render_pass_id) const;
- void DrawFrame(RenderPassList* render_passes_in_draw_order,
- float device_scale_factor,
- const gfx::Size& device_viewport_size);
-
- // Public interface implemented by subclasses.
- virtual void SwapBuffers(std::vector<ui::LatencyInfo> latency_info) = 0;
- virtual void SwapBuffersComplete() {}
- virtual void DidReceiveTextureInUseResponses(
- const gpu::TextureInUseResponses& responses) {}
-
- // Allow tests to enlarge the texture size of non-root render passes to
- // verify cases where the texture doesn't match the render pass size.
- void SetEnlargePassTextureAmountForTesting(const gfx::Size& amount) {
- enlarge_pass_texture_amount_ = amount;
- }
-
- // Public for tests that poke at internals.
- struct CC_EXPORT DrawingFrame {
- DrawingFrame();
- ~DrawingFrame();
- gfx::Rect ComputeScissorRectForRenderPass() const;
-
- const RenderPassList* render_passes_in_draw_order = nullptr;
- const RenderPass* root_render_pass = nullptr;
- const RenderPass* current_render_pass = nullptr;
- const ScopedResource* current_texture = nullptr;
-
- gfx::Rect root_damage_rect;
- std::vector<gfx::Rect> root_content_bounds;
- gfx::Size device_viewport_size;
-
- gfx::Transform projection_matrix;
- gfx::Transform window_matrix;
-
- OverlayCandidateList overlay_list;
- CALayerOverlayList ca_layer_overlay_list;
- DCLayerOverlayList dc_layer_overlay_list;
- };
-
- void DisableColorChecksForTesting() {
- disable_color_checks_for_testing_ = true;
- }
-
- protected:
- friend class BspWalkActionDrawPolygon;
-
- enum SurfaceInitializationMode {
- SURFACE_INITIALIZATION_MODE_PRESERVE,
- SURFACE_INITIALIZATION_MODE_SCISSORED_CLEAR,
- SURFACE_INITIALIZATION_MODE_FULL_SURFACE_CLEAR,
- };
-
- static gfx::RectF QuadVertexRect();
- static void QuadRectTransform(gfx::Transform* quad_rect_transform,
- const gfx::Transform& quad_transform,
- const gfx::RectF& quad_rect);
- // This function takes DrawingFrame as an argument because RenderPass drawing
- // code uses its computations for buffer sizing.
- void InitializeViewport(DrawingFrame* frame,
- const gfx::Rect& draw_rect,
- const gfx::Rect& viewport_rect,
- const gfx::Size& surface_size);
- gfx::Rect MoveFromDrawToWindowSpace(const gfx::Rect& draw_rect) const;
-
- gfx::Rect DeviceViewportRectInDrawSpace() const;
- gfx::Rect OutputSurfaceRectInDrawSpace() const;
- void SetScissorStateForQuad(const DrawQuad& quad,
- const gfx::Rect& render_pass_scissor,
- bool use_render_pass_scissor);
- bool ShouldSkipQuad(const DrawQuad& quad,
- const gfx::Rect& render_pass_scissor);
- void SetScissorTestRectInDrawSpace(const gfx::Rect& draw_space_rect);
-
- static gfx::Size RenderPassTextureSize(const RenderPass* render_pass);
-
- void FlushPolygons(std::deque<std::unique_ptr<DrawPolygon>>* poly_list,
- const gfx::Rect& render_pass_scissor,
- bool use_render_pass_scissor);
- void DrawRenderPassAndExecuteCopyRequests(RenderPass* render_pass);
- void DrawRenderPass(const RenderPass* render_pass);
- bool UseRenderPass(const RenderPass* render_pass);
-
- void DoDrawPolygon(const DrawPolygon& poly,
- const gfx::Rect& render_pass_scissor,
- bool use_render_pass_scissor);
-
- const FilterOperations* FiltersForPass(RenderPassId render_pass_id) const;
- const FilterOperations* BackgroundFiltersForPass(
- RenderPassId render_pass_id) const;
-
- // Private interface implemented by subclasses for use by DirectRenderer.
- virtual bool CanPartialSwap() = 0;
- virtual viz::ResourceFormat BackbufferFormat() const = 0;
- virtual void BindFramebufferToOutputSurface() = 0;
- virtual bool BindFramebufferToTexture(const ScopedResource* resource) = 0;
- virtual void SetScissorTestRect(const gfx::Rect& scissor_rect) = 0;
- virtual void PrepareSurfaceForPass(
- SurfaceInitializationMode initialization_mode,
- const gfx::Rect& render_pass_scissor) = 0;
- // |clip_region| is a (possibly null) pointer to a quad in the same
- // space as the quad. When non-null only the area of the quad that overlaps
- // with clip_region will be drawn.
- virtual void DoDrawQuad(const DrawQuad* quad,
- const gfx::QuadF* clip_region) = 0;
- virtual void BeginDrawingFrame() = 0;
- virtual void FinishDrawingFrame() = 0;
- // If a pass contains a single tile draw quad and can be drawn without
- // a render pass (e.g. applying a filter directly to the tile quad)
- // return that quad, otherwise return null.
- virtual const TileDrawQuad* CanPassBeDrawnDirectly(const RenderPass* pass);
- virtual void FinishDrawingQuadList() {}
- virtual bool FlippedFramebuffer() const = 0;
- virtual void EnsureScissorTestEnabled() = 0;
- virtual void EnsureScissorTestDisabled() = 0;
- virtual void DidChangeVisibility() = 0;
- virtual void CopyCurrentRenderPassToBitmap(
- std::unique_ptr<viz::CopyOutputRequest> request) = 0;
- virtual void SetEnableDCLayers(bool enable) = 0;
-
- gfx::Size surface_size_for_swap_buffers() const {
- return reshape_surface_size_;
- }
-
- const viz::RendererSettings* const settings_;
- OutputSurface* const output_surface_;
- DisplayResourceProvider* const resource_provider_;
- // This can be replaced by test implementations.
- std::unique_ptr<OverlayProcessor> overlay_processor_;
-
- // Whether it's valid to SwapBuffers with an empty rect. Trivially true when
- // using partial swap.
- bool allow_empty_swap_ = false;
- // Whether partial swap can be used.
- bool use_partial_swap_ = false;
- // Whether overdraw feedback is enabled and can be used.
- bool overdraw_feedback_ = false;
- // Whether the SetDrawRectangle and EnableDCLayers commands are in
- // use.
- bool supports_dc_layers_ = false;
- // Whether the output surface is actually using DirectComposition.
- bool using_dc_layers_ = false;
- // This counts the number of draws since the last time
- // DirectComposition layers needed to be used.
- int frames_since_using_dc_layers_ = 0;
-
- // A map from RenderPass id to the texture used to draw the RenderPass from.
- base::flat_map<RenderPassId, std::unique_ptr<ScopedResource>>
- render_pass_textures_;
- // A map from RenderPass id to the single quad present in and replacing the
- // RenderPass.
- base::flat_map<RenderPassId, TileDrawQuad> render_pass_bypass_quads_;
-
- // A map from RenderPass id to the filters used when drawing the RenderPass.
- base::flat_map<RenderPassId, FilterOperations*> render_pass_filters_;
- base::flat_map<RenderPassId, FilterOperations*>
- render_pass_background_filters_;
-
- bool visible_ = false;
- bool disable_color_checks_for_testing_ = false;
-
- // For use in coordinate conversion, this stores the output rect, viewport
- // rect (= unflipped version of glViewport rect), the size of target
- // framebuffer, and the current window space viewport. During a draw, this
- // stores the values for the current render pass; in between draws, they
- // retain the values for the root render pass of the last draw.
- gfx::Rect current_draw_rect_;
- gfx::Rect current_viewport_rect_;
- gfx::Size current_surface_size_;
- gfx::Rect current_window_space_viewport_;
-
- DrawingFrame* current_frame() {
- DCHECK(current_frame_valid_);
- return &current_frame_;
- }
- const DrawingFrame* current_frame() const {
- DCHECK(current_frame_valid_);
- return &current_frame_;
- }
-
- void SetCurrentFrameForTesting(const DrawingFrame& frame);
-
- private:
- bool initialized_ = false;
-#if DCHECK_IS_ON()
- bool overdraw_feedback_support_missing_logged_once_ = false;
-#endif
- gfx::Size enlarge_pass_texture_amount_;
-
- // The current drawing frame is valid only during the duration of the
- // DrawFrame function. Use the accessor current_frame() to ensure that use
- // is valid;
- DrawingFrame current_frame_;
- bool current_frame_valid_ = false;
-
- // Cached values given to Reshape().
- gfx::Size reshape_surface_size_;
- float reshape_device_scale_factor_ = 0.f;
- gfx::ColorSpace reshape_device_color_space_;
- bool reshape_has_alpha_ = false;
- bool reshape_use_stencil_ = false;
-
- DISALLOW_COPY_AND_ASSIGN(DirectRenderer);
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_DIRECT_RENDERER_H_
diff --git a/chromium/cc/output/layer_quad.cc b/chromium/cc/output/layer_quad.cc
deleted file mode 100644
index 450bfbcf80b..00000000000
--- a/chromium/cc/output/layer_quad.cc
+++ /dev/null
@@ -1,126 +0,0 @@
-// Copyright 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/layer_quad.h"
-
-#include <stddef.h>
-
-#include "base/logging.h"
-#include "ui/gfx/geometry/quad_f.h"
-
-namespace cc {
-
-LayerQuad::Edge::Edge(const gfx::PointF& p, const gfx::PointF& q) {
- if (p == q) {
- degenerate_ = true;
- return;
- }
- degenerate_ = false;
- gfx::Vector2dF tangent(p.y() - q.y(), q.x() - p.x());
- float cross2 = p.x() * q.y() - q.x() * p.y();
-
- set(tangent.x(), tangent.y(), cross2);
- scale(1.0f / tangent.Length());
-}
-
-gfx::PointF LayerQuad::Edge::Intersect(const LayerQuad::Edge& e) const {
- DCHECK(!degenerate());
- DCHECK(!e.degenerate());
-
- return gfx::PointF((y() * e.z() - e.y() * z()) / (x() * e.y() - e.x() * y()),
- (x() * e.z() - e.x() * z()) / (e.x() * y() - x() * e.y()));
-}
-
-LayerQuad::LayerQuad(const gfx::QuadF& quad) {
- // Create edges.
- left_ = Edge(quad.p4(), quad.p1());
- right_ = Edge(quad.p2(), quad.p3());
- top_ = Edge(quad.p1(), quad.p2());
- bottom_ = Edge(quad.p3(), quad.p4());
-
- float sign = quad.IsCounterClockwise() ? -1 : 1;
- left_.scale(sign);
- right_.scale(sign);
- top_.scale(sign);
- bottom_.scale(sign);
-}
-
-LayerQuad::LayerQuad(const Edge& left,
- const Edge& top,
- const Edge& right,
- const Edge& bottom)
- : left_(left),
- top_(top),
- right_(right),
- bottom_(bottom) {}
-
-gfx::QuadF LayerQuad::ToQuadF() const {
- size_t num_degenerate_edges = left_.degenerate() + right_.degenerate() +
- top_.degenerate() + bottom_.degenerate();
- if (num_degenerate_edges > 1) {
- return gfx::QuadF();
- }
-
- if (left_.degenerate()) {
- return gfx::QuadF(top_.Intersect(bottom_), top_.Intersect(right_),
- right_.Intersect(bottom_), bottom_.Intersect(top_));
- }
- if (right_.degenerate()) {
- return gfx::QuadF(left_.Intersect(top_), top_.Intersect(bottom_),
- bottom_.Intersect(top_), bottom_.Intersect(left_));
- }
- if (top_.degenerate()) {
- return gfx::QuadF(left_.Intersect(right_), right_.Intersect(left_),
- right_.Intersect(bottom_), bottom_.Intersect(left_));
- }
- if (bottom_.degenerate()) {
- return gfx::QuadF(left_.Intersect(top_), top_.Intersect(right_),
- right_.Intersect(left_), left_.Intersect(right_));
- }
- return gfx::QuadF(left_.Intersect(top_),
- top_.Intersect(right_),
- right_.Intersect(bottom_),
- bottom_.Intersect(left_));
-}
-
-void LayerQuad::ToFloatArray(float flattened[12]) const {
- if (left_.degenerate()) {
- flattened[0] = bottom_.x();
- flattened[1] = bottom_.y();
- flattened[2] = bottom_.z();
- } else {
- flattened[0] = left_.x();
- flattened[1] = left_.y();
- flattened[2] = left_.z();
- }
- if (top_.degenerate()) {
- flattened[3] = left_.x();
- flattened[4] = left_.y();
- flattened[5] = left_.z();
- } else {
- flattened[3] = top_.x();
- flattened[4] = top_.y();
- flattened[5] = top_.z();
- }
- if (right_.degenerate()) {
- flattened[6] = top_.x();
- flattened[7] = top_.y();
- flattened[8] = top_.z();
- } else {
- flattened[6] = right_.x();
- flattened[7] = right_.y();
- flattened[8] = right_.z();
- }
- if (bottom_.degenerate()) {
- flattened[9] = right_.x();
- flattened[10] = right_.y();
- flattened[11] = right_.z();
- } else {
- flattened[9] = bottom_.x();
- flattened[10] = bottom_.y();
- flattened[11] = bottom_.z();
- }
-}
-
-} // namespace cc
diff --git a/chromium/cc/output/layer_quad.h b/chromium/cc/output/layer_quad.h
deleted file mode 100644
index 8b109883d32..00000000000
--- a/chromium/cc/output/layer_quad.h
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-
-#ifndef CC_OUTPUT_LAYER_QUAD_H_
-#define CC_OUTPUT_LAYER_QUAD_H_
-
-#include "base/macros.h"
-#include "cc/cc_export.h"
-#include "ui/gfx/geometry/point_f.h"
-
-namespace gfx {
-class QuadF;
-}
-
-static const float kAntiAliasingInflateDistance = 0.5f;
-
-namespace cc {
-
-class CC_EXPORT LayerQuad {
- public:
- class CC_EXPORT Edge {
- public:
- Edge() : x_(0), y_(0), z_(0), degenerate_(false) {}
- Edge(const gfx::PointF& p, const gfx::PointF& q);
-
- float x() const { return x_; }
- float y() const { return y_; }
- float z() const { return z_; }
-
- void set_x(float x) { x_ = x; }
- void set_y(float y) { y_ = y; }
- void set_z(float z) { z_ = z; }
- void set(float x, float y, float z) {
- x_ = x;
- y_ = y;
- z_ = z;
- }
-
- void move_x(float dx) { x_ += dx; }
- void move_y(float dy) { y_ += dy; }
- void move_z(float dz) { z_ += dz; }
- void move(float dx, float dy, float dz) {
- x_ += dx;
- y_ += dy;
- z_ += dz;
- }
-
- void scale_x(float sx) { x_ *= sx; }
- void scale_y(float sy) { y_ *= sy; }
- void scale_z(float sz) { z_ *= sz; }
- void scale(float sx, float sy, float sz) {
- x_ *= sx;
- y_ *= sy;
- z_ *= sz;
- }
- void scale(float s) { scale(s, s, s); }
-
- bool degenerate() const { return degenerate_; }
-
- gfx::PointF Intersect(const Edge& e) const;
-
- private:
- float x_;
- float y_;
- float z_;
- bool degenerate_;
- };
-
- LayerQuad(const Edge& left,
- const Edge& top,
- const Edge& right,
- const Edge& bottom);
- explicit LayerQuad(const gfx::QuadF& quad);
-
- Edge left() const { return left_; }
- Edge top() const { return top_; }
- Edge right() const { return right_; }
- Edge bottom() const { return bottom_; }
-
- void InflateX(float dx) {
- left_.move_z(dx);
- right_.move_z(dx);
- }
- void InflateY(float dy) {
- top_.move_z(dy);
- bottom_.move_z(dy);
- }
- void Inflate(float d) {
- InflateX(d);
- InflateY(d);
- }
- void InflateAntiAliasingDistance() {
- Inflate(kAntiAliasingInflateDistance);
- }
-
- gfx::QuadF ToQuadF() const;
-
- void ToFloatArray(float flattened[12]) const;
-
- private:
- Edge left_;
- Edge top_;
- Edge right_;
- Edge bottom_;
-
- DISALLOW_COPY_AND_ASSIGN(LayerQuad);
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_LAYER_QUAD_H_
diff --git a/chromium/cc/output/layer_quad_unittest.cc b/chromium/cc/output/layer_quad_unittest.cc
deleted file mode 100644
index e910705a0f6..00000000000
--- a/chromium/cc/output/layer_quad_unittest.cc
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/layer_quad.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/geometry/quad_f.h"
-
-namespace cc {
-namespace {
-
-TEST(LayerQuadTest, QuadFConversion) {
- gfx::PointF p1(-0.5f, -0.5f);
- gfx::PointF p2(0.5f, -0.5f);
- gfx::PointF p3(0.5f, 0.5f);
- gfx::PointF p4(-0.5f, 0.5f);
-
- gfx::QuadF quad_cw(p1, p2, p3, p4);
- LayerQuad layer_quad_cw(quad_cw);
- EXPECT_EQ(layer_quad_cw.ToQuadF(), quad_cw);
-
- gfx::QuadF quad_ccw(p1, p4, p3, p2);
- LayerQuad layer_quad_ccw(quad_ccw);
- EXPECT_EQ(layer_quad_ccw.ToQuadF(), quad_ccw);
-}
-
-TEST(LayerQuadTest, Inflate) {
- gfx::PointF p1(-0.5f, -0.5f);
- gfx::PointF p2(0.5f, -0.5f);
- gfx::PointF p3(0.5f, 0.5f);
- gfx::PointF p4(-0.5f, 0.5f);
-
- gfx::QuadF quad(p1, p2, p3, p4);
- LayerQuad layer_quad(quad);
- quad.Scale(2.f, 2.f);
- layer_quad.Inflate(0.5f);
- EXPECT_EQ(layer_quad.ToQuadF(), quad);
-}
-
-TEST(LayerQuadTest, Degenerate) {
- gfx::QuadF quad;
- gfx::PointF p1(1.0f, 1.0f);
- gfx::PointF p2(0.0f, 1.0f);
- gfx::PointF p3(1.0f, 0.0f);
- gfx::QuadF triangle(p1, p2, p3, p1);
-
- LayerQuad::Edge e1d(p1, p1);
- LayerQuad::Edge e2d(p2, p2);
- LayerQuad::Edge e2(p1, p2);
- LayerQuad::Edge e3(p2, p3);
- LayerQuad::Edge e4(p3, p1);
- EXPECT_TRUE(e1d.degenerate());
- EXPECT_TRUE(e2d.degenerate());
- EXPECT_FALSE(e2.degenerate());
- EXPECT_FALSE(e3.degenerate());
- EXPECT_FALSE(e4.degenerate());
-
- LayerQuad degenerate_quad(e1d, e2d, e2, e3);
- // With more than one degenerate edge, we expect the quad to be zero.
- EXPECT_EQ(quad, degenerate_quad.ToQuadF());
-
- LayerQuad triangle_quad(e1d, e2, e3, e4);
- // With only one degenerate edge, we expect the quad to be a triangle.
- EXPECT_EQ(triangle, triangle_quad.ToQuadF());
-}
-
-} // namespace
-} // namespace cc
diff --git a/chromium/cc/output/output_surface.cc b/chromium/cc/output/output_surface.cc
deleted file mode 100644
index 3ab68644108..00000000000
--- a/chromium/cc/output/output_surface.cc
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/output_surface.h"
-
-#include <stdint.h>
-
-#include "base/bind.h"
-#include "base/location.h"
-#include "base/macros.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "base/trace_event/trace_event.h"
-#include "cc/output/output_surface_client.h"
-#include "cc/output/output_surface_frame.h"
-#include "gpu/GLES2/gl2extchromium.h"
-#include "gpu/command_buffer/client/context_support.h"
-#include "gpu/command_buffer/client/gles2_interface.h"
-
-namespace cc {
-
-OutputSurface::OutputSurface(
- scoped_refptr<viz::ContextProvider> context_provider)
- : context_provider_(std::move(context_provider)) {
- DCHECK(context_provider_);
-}
-
-OutputSurface::OutputSurface(
- std::unique_ptr<SoftwareOutputDevice> software_device)
- : software_device_(std::move(software_device)) {
- DCHECK(software_device_);
-}
-
-OutputSurface::OutputSurface(
- scoped_refptr<viz::VulkanContextProvider> vulkan_context_provider)
- : vulkan_context_provider_(std::move(vulkan_context_provider)) {
- DCHECK(vulkan_context_provider_);
-}
-
-OutputSurface::~OutputSurface() = default;
-
-} // namespace cc
diff --git a/chromium/cc/output/output_surface.h b/chromium/cc/output/output_surface.h
deleted file mode 100644
index 6db329a4eaa..00000000000
--- a/chromium/cc/output/output_surface.h
+++ /dev/null
@@ -1,138 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_OUTPUT_SURFACE_H_
-#define CC_OUTPUT_OUTPUT_SURFACE_H_
-
-#include <deque>
-#include <memory>
-
-#include "base/macros.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
-#include "cc/cc_export.h"
-#include "cc/output/overlay_candidate_validator.h"
-#include "cc/output/software_output_device.h"
-#include "components/viz/common/gpu/context_provider.h"
-#include "components/viz/common/gpu/vulkan_context_provider.h"
-#include "components/viz/common/resources/returned_resource.h"
-#include "gpu/command_buffer/common/texture_in_use_response.h"
-#include "ui/gfx/color_space.h"
-
-namespace gfx {
-class ColorSpace;
-class Size;
-}
-
-namespace cc {
-
-class OutputSurfaceClient;
-class OutputSurfaceFrame;
-
-// This class represents a platform-independent API for presenting
-// buffers to display via GPU or software compositing. Implementations
-// can provide platform-specific behaviour.
-class CC_EXPORT OutputSurface {
- public:
- struct Capabilities {
- Capabilities() = default;
-
- int max_frames_pending = 1;
- // Whether this output surface renders to the default OpenGL zero
- // framebuffer or to an offscreen framebuffer.
- bool uses_default_gl_framebuffer = true;
- // Whether this OutputSurface is flipped or not.
- bool flipped_output_surface = false;
- // Whether this OutputSurface supports stencil operations or not.
- // Note: HasExternalStencilTest() must return false when an output surface
- // has been configured for stencil usage.
- bool supports_stencil = false;
- };
-
- // Constructor for GL-based compositing.
- explicit OutputSurface(scoped_refptr<viz::ContextProvider> context_provider);
- // Constructor for software compositing.
- explicit OutputSurface(std::unique_ptr<SoftwareOutputDevice> software_device);
- // Constructor for Vulkan-based compositing.
- explicit OutputSurface(
- scoped_refptr<viz::VulkanContextProvider> vulkan_context_provider);
-
- virtual ~OutputSurface();
-
- const Capabilities& capabilities() const { return capabilities_; }
-
- // Obtain the 3d context or the software device associated with this output
- // surface. Either of these may return a null pointer, but not both.
- // In the event of a lost context, the entire output surface should be
- // recreated.
- viz::ContextProvider* context_provider() const {
- return context_provider_.get();
- }
- viz::VulkanContextProvider* vulkan_context_provider() const {
- return vulkan_context_provider_.get();
- }
- SoftwareOutputDevice* software_device() const {
- return software_device_.get();
- }
-
- virtual void BindToClient(OutputSurfaceClient* client) = 0;
-
- virtual void EnsureBackbuffer() = 0;
- virtual void DiscardBackbuffer() = 0;
-
- // Bind the default framebuffer for drawing to, only valid for GL backed
- // OutputSurfaces.
- virtual void BindFramebuffer() = 0;
-
- // Marks that the given rectangle will be drawn to on the default, bound
- // framebuffer. Only valid for surfaces with dc_layers in the context
- // capabilities.
- virtual void SetDrawRectangle(const gfx::Rect& rect) = 0;
-
- // Get the class capable of informing cc of hardware overlay capability.
- virtual OverlayCandidateValidator* GetOverlayCandidateValidator() const = 0;
-
- // Returns true if a main image overlay plane should be scheduled.
- virtual bool IsDisplayedAsOverlayPlane() const = 0;
-
- // Get the texture for the main image's overlay.
- virtual unsigned GetOverlayTextureId() const = 0;
-
- // Get the format for the main image's overlay.
- virtual gfx::BufferFormat GetOverlayBufferFormat() const = 0;
-
- // If this returns true, then the surface will not attempt to draw.
- virtual bool SurfaceIsSuspendForRecycle() const = 0;
-
- virtual void Reshape(const gfx::Size& size,
- float device_scale_factor,
- const gfx::ColorSpace& color_space,
- bool has_alpha,
- bool use_stencil) = 0;
-
- virtual bool HasExternalStencilTest() const = 0;
- virtual void ApplyExternalStencil() = 0;
-
- // Gives the GL internal format that should be used for calling CopyTexImage2D
- // when the framebuffer is bound via BindFramebuffer().
- virtual uint32_t GetFramebufferCopyTextureFormat() = 0;
-
- // Swaps the current backbuffer to the screen. For successful swaps, the
- // implementation must call OutputSurfaceClient::DidReceiveSwapBuffersAck()
- // after returning from this method in order to unblock the next frame.
- virtual void SwapBuffers(OutputSurfaceFrame frame) = 0;
-
- protected:
- struct OutputSurface::Capabilities capabilities_;
- scoped_refptr<viz::ContextProvider> context_provider_;
- scoped_refptr<viz::VulkanContextProvider> vulkan_context_provider_;
- std::unique_ptr<SoftwareOutputDevice> software_device_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(OutputSurface);
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_OUTPUT_SURFACE_H_
diff --git a/chromium/cc/output/output_surface_client.h b/chromium/cc/output/output_surface_client.h
deleted file mode 100644
index bf12df0e305..00000000000
--- a/chromium/cc/output/output_surface_client.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_OUTPUT_SURFACE_CLIENT_H_
-#define CC_OUTPUT_OUTPUT_SURFACE_CLIENT_H_
-
-#include "base/callback.h"
-#include "base/memory/ref_counted.h"
-#include "base/time/time.h"
-#include "cc/cc_export.h"
-#include "components/viz/common/gpu/context_provider.h"
-#include "components/viz/common/resources/returned_resource.h"
-#include "gpu/command_buffer/common/texture_in_use_response.h"
-#include "ui/gfx/geometry/rect.h"
-
-namespace cc {
-
-class CC_EXPORT OutputSurfaceClient {
- public:
- // A notification that the swap of the backbuffer to the hardware is complete
- // and is now visible to the user.
- virtual void DidReceiveSwapBuffersAck() = 0;
-
- // For surfaceless/ozone implementations to create damage for the next frame.
- virtual void SetNeedsRedrawRect(const gfx::Rect& damage_rect) = 0;
-
- // For overlays.
- virtual void DidReceiveTextureInUseResponses(
- const gpu::TextureInUseResponses& responses) = 0;
-
- protected:
- virtual ~OutputSurfaceClient() {}
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_OUTPUT_SURFACE_CLIENT_H_
diff --git a/chromium/cc/output/output_surface_frame.cc b/chromium/cc/output/output_surface_frame.cc
deleted file mode 100644
index e3bb0fdab5b..00000000000
--- a/chromium/cc/output/output_surface_frame.cc
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/output_surface_frame.h"
-
-namespace cc {
-
-OutputSurfaceFrame::OutputSurfaceFrame() = default;
-
-OutputSurfaceFrame::OutputSurfaceFrame(OutputSurfaceFrame&& other) = default;
-
-OutputSurfaceFrame::~OutputSurfaceFrame() = default;
-
-OutputSurfaceFrame& OutputSurfaceFrame::operator=(OutputSurfaceFrame&& other) =
- default;
-
-} // namespace cc
diff --git a/chromium/cc/output/output_surface_frame.h b/chromium/cc/output/output_surface_frame.h
deleted file mode 100644
index fd01648a114..00000000000
--- a/chromium/cc/output/output_surface_frame.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_OUTPUT_SURFACE_FRAME_H_
-#define CC_OUTPUT_OUTPUT_SURFACE_FRAME_H_
-
-#include <vector>
-
-#include "base/macros.h"
-#include "base/optional.h"
-#include "cc/cc_export.h"
-#include "ui/gfx/geometry/rect.h"
-#include "ui/gfx/geometry/size.h"
-#include "ui/latency/latency_info.h"
-
-namespace cc {
-
-// Metadata given to the OutputSurface for it to swap what was drawn and make
-// current frame visible.
-class CC_EXPORT OutputSurfaceFrame {
- public:
- OutputSurfaceFrame();
- OutputSurfaceFrame(OutputSurfaceFrame&& other);
- ~OutputSurfaceFrame();
-
- OutputSurfaceFrame& operator=(OutputSurfaceFrame&& other);
-
- gfx::Size size;
- // Providing both |sub_buffer_rect| and |content_bounds| is not supported;
- // if neither is present, regular swap is used.
- // Optional rect for partial or empty swap.
- base::Optional<gfx::Rect> sub_buffer_rect;
- // Optional content area for SwapWithBounds. Rectangles may overlap.
- std::vector<gfx::Rect> content_bounds;
- std::vector<ui::LatencyInfo> latency_info;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(OutputSurfaceFrame);
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_OUTPUT_SURFACE_FRAME_H_
diff --git a/chromium/cc/output/overlay_candidate.cc b/chromium/cc/output/overlay_candidate.cc
index b4583c4307c..8fb65c22a51 100644
--- a/chromium/cc/output/overlay_candidate.cc
+++ b/chromium/cc/output/overlay_candidate.cc
@@ -8,11 +8,11 @@
#include <limits>
#include "base/logging.h"
#include "cc/base/math_util.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/stream_video_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
-#include "cc/quads/tile_draw_quad.h"
#include "cc/resources/display_resource_provider.h"
+#include "components/viz/common/quads/solid_color_draw_quad.h"
+#include "components/viz/common/quads/stream_video_draw_quad.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
+#include "components/viz/common/quads/tile_draw_quad.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/vector3d_f.h"
@@ -194,7 +194,7 @@ OverlayCandidate::~OverlayCandidate() {}
// static
bool OverlayCandidate::FromDrawQuad(DisplayResourceProvider* resource_provider,
- const DrawQuad* quad,
+ const viz::DrawQuad* quad,
OverlayCandidate* candidate) {
// We don't support an opacity value different than one for an overlay plane.
if (quad->shared_quad_state->opacity != 1.f)
@@ -205,15 +205,16 @@ bool OverlayCandidate::FromDrawQuad(DisplayResourceProvider* resource_provider,
return false;
switch (quad->material) {
- case DrawQuad::TEXTURE_CONTENT:
+ case viz::DrawQuad::TEXTURE_CONTENT:
return FromTextureQuad(resource_provider,
- TextureDrawQuad::MaterialCast(quad), candidate);
- case DrawQuad::TILED_CONTENT:
- return FromTileQuad(resource_provider, TileDrawQuad::MaterialCast(quad),
- candidate);
- case DrawQuad::STREAM_VIDEO_CONTENT:
+ viz::TextureDrawQuad::MaterialCast(quad),
+ candidate);
+ case viz::DrawQuad::TILED_CONTENT:
+ return FromTileQuad(resource_provider,
+ viz::TileDrawQuad::MaterialCast(quad), candidate);
+ case viz::DrawQuad::STREAM_VIDEO_CONTENT:
return FromStreamVideoQuad(resource_provider,
- StreamVideoDrawQuad::MaterialCast(quad),
+ viz::StreamVideoDrawQuad::MaterialCast(quad),
candidate);
default:
break;
@@ -223,12 +224,12 @@ bool OverlayCandidate::FromDrawQuad(DisplayResourceProvider* resource_provider,
}
// static
-bool OverlayCandidate::IsInvisibleQuad(const DrawQuad* quad) {
+bool OverlayCandidate::IsInvisibleQuad(const viz::DrawQuad* quad) {
float opacity = quad->shared_quad_state->opacity;
if (opacity < std::numeric_limits<float>::epsilon())
return true;
- if (quad->material == DrawQuad::SOLID_COLOR) {
- SkColor color = SolidColorDrawQuad::MaterialCast(quad)->color;
+ if (quad->material == viz::DrawQuad::SOLID_COLOR) {
+ SkColor color = viz::SolidColorDrawQuad::MaterialCast(quad)->color;
float alpha = (SkColorGetA(color) * (1.0f / 255.0f)) * opacity;
return quad->ShouldDrawWithBlending() &&
alpha < std::numeric_limits<float>::epsilon();
@@ -238,8 +239,8 @@ bool OverlayCandidate::IsInvisibleQuad(const DrawQuad* quad) {
// static
bool OverlayCandidate::IsOccluded(const OverlayCandidate& candidate,
- QuadList::ConstIterator quad_list_begin,
- QuadList::ConstIterator quad_list_end) {
+ viz::QuadList::ConstIterator quad_list_begin,
+ viz::QuadList::ConstIterator quad_list_end) {
// Check that no visible quad overlaps the candidate.
for (auto overlap_iter = quad_list_begin; overlap_iter != quad_list_end;
++overlap_iter) {
@@ -256,7 +257,7 @@ bool OverlayCandidate::IsOccluded(const OverlayCandidate& candidate,
// static
bool OverlayCandidate::FromDrawQuadResource(
DisplayResourceProvider* resource_provider,
- const DrawQuad* quad,
+ const viz::DrawQuad* quad,
viz::ResourceId resource_id,
bool y_flipped,
OverlayCandidate* candidate) {
@@ -290,7 +291,7 @@ bool OverlayCandidate::FromDrawQuadResource(
// static
bool OverlayCandidate::FromTextureQuad(
DisplayResourceProvider* resource_provider,
- const TextureDrawQuad* quad,
+ const viz::TextureDrawQuad* quad,
OverlayCandidate* candidate) {
if (quad->background_color != SK_ColorTRANSPARENT)
return false;
@@ -305,7 +306,7 @@ bool OverlayCandidate::FromTextureQuad(
// static
bool OverlayCandidate::FromTileQuad(DisplayResourceProvider* resource_provider,
- const TileDrawQuad* quad,
+ const viz::TileDrawQuad* quad,
OverlayCandidate* candidate) {
if (!FromDrawQuadResource(resource_provider, quad, quad->resource_id(), false,
candidate)) {
@@ -319,7 +320,7 @@ bool OverlayCandidate::FromTileQuad(DisplayResourceProvider* resource_provider,
// static
bool OverlayCandidate::FromStreamVideoQuad(
DisplayResourceProvider* resource_provider,
- const StreamVideoDrawQuad* quad,
+ const viz::StreamVideoDrawQuad* quad,
OverlayCandidate* candidate) {
if (!FromDrawQuadResource(resource_provider, quad, quad->resource_id(), false,
candidate)) {
diff --git a/chromium/cc/output/overlay_candidate.h b/chromium/cc/output/overlay_candidate.h
index fdd0f7e603b..91b720a8b55 100644
--- a/chromium/cc/output/overlay_candidate.h
+++ b/chromium/cc/output/overlay_candidate.h
@@ -9,7 +9,7 @@
#include <vector>
#include "cc/cc_export.h"
-#include "cc/quads/render_pass.h"
+#include "components/viz/common/quads/render_pass.h"
#include "components/viz/common/resources/resource_id.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/rect.h"
@@ -22,30 +22,31 @@ namespace gfx {
class Rect;
}
-namespace cc {
-
-class DisplayResourceProvider;
-class DrawQuad;
+namespace viz {
class StreamVideoDrawQuad;
class TextureDrawQuad;
class TileDrawQuad;
+} // namespace viz
+
+namespace cc {
+class DisplayResourceProvider;
class CC_EXPORT OverlayCandidate {
public:
// Returns true and fills in |candidate| if |draw_quad| is of a known quad
// type and contains an overlayable resource.
static bool FromDrawQuad(DisplayResourceProvider* resource_provider,
- const DrawQuad* quad,
+ const viz::DrawQuad* quad,
OverlayCandidate* candidate);
// Returns true if |quad| will not block quads underneath from becoming
// an overlay.
- static bool IsInvisibleQuad(const DrawQuad* quad);
+ static bool IsInvisibleQuad(const viz::DrawQuad* quad);
// Returns true if any any of the quads in the list given by |quad_list_begin|
// and |quad_list_end| are visible and on top of |candidate|.
static bool IsOccluded(const OverlayCandidate& candidate,
- QuadList::ConstIterator quad_list_begin,
- QuadList::ConstIterator quad_list_end);
+ viz::QuadList::ConstIterator quad_list_begin,
+ viz::QuadList::ConstIterator quad_list_end);
OverlayCandidate();
OverlayCandidate(const OverlayCandidate& other);
@@ -99,18 +100,18 @@ class CC_EXPORT OverlayCandidate {
private:
static bool FromDrawQuadResource(DisplayResourceProvider* resource_provider,
- const DrawQuad* quad,
+ const viz::DrawQuad* quad,
viz::ResourceId resource_id,
bool y_flipped,
OverlayCandidate* candidate);
static bool FromTextureQuad(DisplayResourceProvider* resource_provider,
- const TextureDrawQuad* quad,
+ const viz::TextureDrawQuad* quad,
OverlayCandidate* candidate);
static bool FromTileQuad(DisplayResourceProvider* resource_provider,
- const TileDrawQuad* quad,
+ const viz::TileDrawQuad* quad,
OverlayCandidate* candidate);
static bool FromStreamVideoQuad(DisplayResourceProvider* resource_provider,
- const StreamVideoDrawQuad* quad,
+ const viz::StreamVideoDrawQuad* quad,
OverlayCandidate* candidate);
};
diff --git a/chromium/cc/output/overlay_candidate_validator.h b/chromium/cc/output/overlay_candidate_validator.h
deleted file mode 100644
index 9c01486d284..00000000000
--- a/chromium/cc/output/overlay_candidate_validator.h
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_OVERLAY_CANDIDATE_VALIDATOR_H_
-#define CC_OUTPUT_OVERLAY_CANDIDATE_VALIDATOR_H_
-
-#include <vector>
-
-#include "cc/cc_export.h"
-#include "cc/output/overlay_candidate.h"
-#include "cc/output/overlay_processor.h"
-
-namespace cc {
-
-// This class that can be used to answer questions about possible overlay
-// configurations for a particular output device.
-class CC_EXPORT OverlayCandidateValidator {
- public:
- // Populates a list of strategies that may work with this validator.
- virtual void GetStrategies(OverlayProcessor::StrategyList* strategies) = 0;
-
- // Returns true if draw quads can be represented as CALayers (Mac only).
- virtual bool AllowCALayerOverlays() = 0;
-
- // Returns true if draw quads can be represented as Direct Composition
- // Visuals (Windows only).
- virtual bool AllowDCLayerOverlays() = 0;
-
- // A list of possible overlay candidates is presented to this function.
- // The expected result is that those candidates that can be in a separate
- // plane are marked with |overlay_handled| set to true, otherwise they are
- // to be traditionally composited. Candidates with |overlay_handled| set to
- // true must also have their |display_rect| converted to integer
- // coordinates if necessary.
- virtual void CheckOverlaySupport(OverlayCandidateList* surfaces) = 0;
-
- virtual ~OverlayCandidateValidator() {}
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_OVERLAY_CANDIDATE_VALIDATOR_H_
diff --git a/chromium/cc/output/overlay_processor.cc b/chromium/cc/output/overlay_processor.cc
deleted file mode 100644
index 5a1ee11f7df..00000000000
--- a/chromium/cc/output/overlay_processor.cc
+++ /dev/null
@@ -1,206 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/overlay_processor.h"
-
-#include "cc/output/dc_layer_overlay.h"
-#include "cc/output/output_surface.h"
-#include "cc/output/overlay_strategy_single_on_top.h"
-#include "cc/output/overlay_strategy_underlay.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/resources/display_resource_provider.h"
-#include "ui/gfx/geometry/rect_conversions.h"
-#include "ui/gfx/transform.h"
-
-namespace {
-
-#if defined(OS_ANDROID)
-// Utility class to make sure that we notify resource that they're promotable
-// before returning from ProcessForOverlays.
-class SendPromotionHintsBeforeReturning {
- public:
- SendPromotionHintsBeforeReturning(
- cc::DisplayResourceProvider* resource_provider,
- cc::OverlayCandidateList* candidates)
- : resource_provider_(resource_provider), candidates_(candidates) {}
- ~SendPromotionHintsBeforeReturning() {
- resource_provider_->SendPromotionHints(
- candidates_->promotion_hint_info_map_);
- }
-
- private:
- cc::DisplayResourceProvider* resource_provider_;
- cc::OverlayCandidateList* candidates_;
-
- DISALLOW_COPY_AND_ASSIGN(SendPromotionHintsBeforeReturning);
-};
-#endif
-
-} // namespace
-
-namespace cc {
-
-OverlayProcessor::OverlayProcessor(OutputSurface* surface) : surface_(surface) {
-}
-
-void OverlayProcessor::Initialize() {
- DCHECK(surface_);
- OverlayCandidateValidator* validator =
- surface_->GetOverlayCandidateValidator();
- if (validator)
- validator->GetStrategies(&strategies_);
-}
-
-OverlayProcessor::~OverlayProcessor() {}
-
-gfx::Rect OverlayProcessor::GetAndResetOverlayDamage() {
- gfx::Rect result = overlay_damage_rect_;
- overlay_damage_rect_ = gfx::Rect();
- return result;
-}
-
-bool OverlayProcessor::ProcessForCALayers(
- DisplayResourceProvider* resource_provider,
- RenderPass* render_pass,
- const OverlayProcessor::FilterOperationsMap& render_pass_filters,
- const OverlayProcessor::FilterOperationsMap& render_pass_background_filters,
- OverlayCandidateList* overlay_candidates,
- CALayerOverlayList* ca_layer_overlays,
- gfx::Rect* damage_rect) {
- OverlayCandidateValidator* overlay_validator =
- surface_->GetOverlayCandidateValidator();
- if (!overlay_validator || !overlay_validator->AllowCALayerOverlays())
- return false;
-
- if (!ProcessForCALayerOverlays(
- resource_provider, gfx::RectF(render_pass->output_rect),
- render_pass->quad_list, render_pass_filters,
- render_pass_background_filters, ca_layer_overlays))
- return false;
-
- // CALayer overlays are all-or-nothing. If all quads were replaced with
- // layers then clear the list and remove the backbuffer from the overcandidate
- // list.
- overlay_candidates->clear();
- overlay_damage_rect_ = render_pass->output_rect;
- *damage_rect = gfx::Rect();
- return true;
-}
-
-bool OverlayProcessor::ProcessForDCLayers(
- DisplayResourceProvider* resource_provider,
- RenderPassList* render_passes,
- const OverlayProcessor::FilterOperationsMap& render_pass_filters,
- const OverlayProcessor::FilterOperationsMap& render_pass_background_filters,
- OverlayCandidateList* overlay_candidates,
- DCLayerOverlayList* dc_layer_overlays,
- gfx::Rect* damage_rect) {
- OverlayCandidateValidator* overlay_validator =
- surface_->GetOverlayCandidateValidator();
- if (!overlay_validator || !overlay_validator->AllowDCLayerOverlays())
- return false;
-
- dc_processor_.Process(
- resource_provider, gfx::RectF(render_passes->back()->output_rect),
- render_passes, &overlay_damage_rect_, damage_rect, dc_layer_overlays);
-
- DCHECK(overlay_candidates->empty());
- return true;
-}
-
-void OverlayProcessor::ProcessForOverlays(
- DisplayResourceProvider* resource_provider,
- RenderPassList* render_passes,
- const OverlayProcessor::FilterOperationsMap& render_pass_filters,
- const OverlayProcessor::FilterOperationsMap& render_pass_background_filters,
- OverlayCandidateList* candidates,
- CALayerOverlayList* ca_layer_overlays,
- DCLayerOverlayList* dc_layer_overlays,
- gfx::Rect* damage_rect,
- std::vector<gfx::Rect>* content_bounds) {
-#if defined(OS_ANDROID)
- // Be sure to send out notifications, regardless of whether we get to
- // processing for overlays or not. If we don't, then we should notify that
- // they are not promotable.
- SendPromotionHintsBeforeReturning notifier(resource_provider, candidates);
-#endif
-
- // Reset |previous_frame_underlay_rect_| in case UpdateDamageRect() not being
- // invoked.
- const gfx::Rect previous_frame_underlay_rect = previous_frame_underlay_rect_;
- previous_frame_underlay_rect_ = gfx::Rect();
-
- RenderPass* render_pass = render_passes->back().get();
-
- // If we have any copy requests, we can't remove any quads for overlays or
- // CALayers because the framebuffer would be missing the removed quads'
- // contents.
- if (!render_pass->copy_requests.empty()) {
- dc_processor_.ClearOverlayState();
- return;
- }
-
- // First attempt to process for CALayers.
- if (ProcessForCALayers(resource_provider, render_passes->back().get(),
- render_pass_filters, render_pass_background_filters,
- candidates, ca_layer_overlays, damage_rect)) {
- return;
- }
-
- if (ProcessForDCLayers(resource_provider, render_passes, render_pass_filters,
- render_pass_background_filters, candidates,
- dc_layer_overlays, damage_rect)) {
- return;
- }
-
- // Only if that fails, attempt hardware overlay strategies.
- for (const auto& strategy : strategies_) {
- if (!strategy->Attempt(resource_provider, render_passes->back().get(),
- candidates, content_bounds))
- continue;
-
- UpdateDamageRect(candidates, previous_frame_underlay_rect, damage_rect);
- return;
- }
-}
-
-// Subtract on-top opaque overlays from the damage rect, unless the overlays use
-// the backbuffer as their content (in which case, add their combined rect
-// back to the damage at the end).
-// Also subtract unoccluded underlays from the damage rect if we know that the
-// same underlay was scheduled on the previous frame. If the renderer decides
-// not to swap the framebuffer there will still be a transparent hole in the
-// previous frame. This only handles the common case of a single underlay quad
-// for fullscreen video.
-void OverlayProcessor::UpdateDamageRect(
- OverlayCandidateList* candidates,
- const gfx::Rect& previous_frame_underlay_rect,
- gfx::Rect* damage_rect) {
- gfx::Rect output_surface_overlay_damage_rect;
- gfx::Rect this_frame_underlay_rect;
- for (const OverlayCandidate& overlay : *candidates) {
- if (overlay.plane_z_order >= 0) {
- const gfx::Rect overlay_display_rect =
- ToEnclosedRect(overlay.display_rect);
- if (overlay.use_output_surface_for_resource) {
- if (overlay.plane_z_order > 0)
- output_surface_overlay_damage_rect.Union(overlay_display_rect);
- } else {
- overlay_damage_rect_.Union(overlay_display_rect);
- if (overlay.is_opaque)
- damage_rect->Subtract(overlay_display_rect);
- }
- } else if (overlay.is_unoccluded && this_frame_underlay_rect.IsEmpty()) {
- this_frame_underlay_rect = ToEnclosedRect(overlay.display_rect);
- }
- }
-
- if (this_frame_underlay_rect == previous_frame_underlay_rect)
- damage_rect->Subtract(this_frame_underlay_rect);
- previous_frame_underlay_rect_ = this_frame_underlay_rect;
-
- damage_rect->Union(output_surface_overlay_damage_rect);
-}
-
-} // namespace cc
diff --git a/chromium/cc/output/overlay_processor.h b/chromium/cc/output/overlay_processor.h
deleted file mode 100644
index 3b558bf63b2..00000000000
--- a/chromium/cc/output/overlay_processor.h
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_OVERLAY_PROCESSOR_H_
-#define CC_OUTPUT_OVERLAY_PROCESSOR_H_
-
-#include <memory>
-
-#include "base/containers/flat_map.h"
-#include "base/macros.h"
-#include "cc/cc_export.h"
-#include "cc/output/ca_layer_overlay.h"
-#include "cc/output/dc_layer_overlay.h"
-#include "cc/output/overlay_candidate.h"
-#include "cc/quads/render_pass.h"
-
-namespace cc {
-class DisplayResourceProvider;
-class OutputSurface;
-
-class CC_EXPORT OverlayProcessor {
- public:
- class CC_EXPORT Strategy {
- public:
- virtual ~Strategy() {}
- // Returns false if the strategy cannot be made to work with the
- // current set of render passes. Returns true if the strategy was successful
- // and adds any additional passes necessary to represent overlays to
- // |render_passes|.
- virtual bool Attempt(DisplayResourceProvider* resource_provider,
- RenderPass* render_pass,
- OverlayCandidateList* candidates,
- std::vector<gfx::Rect>* content_bounds) = 0;
- };
- using StrategyList = std::vector<std::unique_ptr<Strategy>>;
-
- explicit OverlayProcessor(OutputSurface* surface);
- virtual ~OverlayProcessor();
- // Virtual to allow testing different strategies.
- virtual void Initialize();
-
- gfx::Rect GetAndResetOverlayDamage();
-
- using FilterOperationsMap = base::flat_map<RenderPassId, FilterOperations*>;
-
- // Attempt to replace quads from the specified root render pass with overlays
- // or CALayers. This must be called every frame.
- void ProcessForOverlays(
- DisplayResourceProvider* resource_provider,
- RenderPassList* render_passes,
- const FilterOperationsMap& render_pass_filters,
- const FilterOperationsMap& render_pass_background_filters,
- OverlayCandidateList* overlay_candidates,
- CALayerOverlayList* ca_layer_overlays,
- DCLayerOverlayList* dc_layer_overlays,
- gfx::Rect* damage_rect,
- std::vector<gfx::Rect>* content_bounds);
-
- protected:
- StrategyList strategies_;
- OutputSurface* surface_;
- gfx::Rect overlay_damage_rect_;
- gfx::Rect previous_frame_underlay_rect_;
-
- private:
- bool ProcessForCALayers(
- DisplayResourceProvider* resource_provider,
- RenderPass* render_pass,
- const FilterOperationsMap& render_pass_filters,
- const FilterOperationsMap& render_pass_background_filters,
- OverlayCandidateList* overlay_candidates,
- CALayerOverlayList* ca_layer_overlays,
- gfx::Rect* damage_rect);
- bool ProcessForDCLayers(
- DisplayResourceProvider* resource_provider,
- RenderPassList* render_passes,
- const FilterOperationsMap& render_pass_filters,
- const FilterOperationsMap& render_pass_background_filters,
- OverlayCandidateList* overlay_candidates,
- DCLayerOverlayList* dc_layer_overlays,
- gfx::Rect* damage_rect);
- // Update |damage_rect| by removing damage casued by |candidates|.
- void UpdateDamageRect(OverlayCandidateList* candidates,
- const gfx::Rect& previous_frame_underlay_rect,
- gfx::Rect* damage_rect);
-
- DCLayerOverlayProcessor dc_processor_;
-
- DISALLOW_COPY_AND_ASSIGN(OverlayProcessor);
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_OVERLAY_PROCESSOR_H_
diff --git a/chromium/cc/output/overlay_strategy_fullscreen.cc b/chromium/cc/output/overlay_strategy_fullscreen.cc
deleted file mode 100644
index eedd2d3c4eb..00000000000
--- a/chromium/cc/output/overlay_strategy_fullscreen.cc
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/overlay_strategy_fullscreen.h"
-
-#include "cc/base/math_util.h"
-#include "cc/output/overlay_candidate_validator.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "ui/gfx/geometry/rect_conversions.h"
-#include "ui/gfx/geometry/size_conversions.h"
-
-namespace cc {
-
-OverlayStrategyFullscreen::OverlayStrategyFullscreen(
- OverlayCandidateValidator* capability_checker)
- : capability_checker_(capability_checker) {
- DCHECK(capability_checker);
-}
-
-OverlayStrategyFullscreen::~OverlayStrategyFullscreen() {}
-
-bool OverlayStrategyFullscreen::Attempt(
- DisplayResourceProvider* resource_provider,
- RenderPass* render_pass,
- OverlayCandidateList* candidate_list,
- std::vector<gfx::Rect>* content_bounds) {
- QuadList* quad_list = &render_pass->quad_list;
- // First quad of quad_list is the top most quad.
- auto front = quad_list->begin();
- while (front != quad_list->end()) {
- if (!OverlayCandidate::IsInvisibleQuad(*front))
- break;
- front++;
- }
-
- if (front == quad_list->end())
- return false;
-
- const DrawQuad* quad = *front;
- if (quad->ShouldDrawWithBlending())
- return false;
-
- OverlayCandidate candidate;
- if (!OverlayCandidate::FromDrawQuad(resource_provider, quad, &candidate)) {
- return false;
- }
-
- if (!candidate.display_rect.origin().IsOrigin() ||
- gfx::ToRoundedSize(candidate.display_rect.size()) !=
- render_pass->output_rect.size() ||
- render_pass->output_rect.size() != candidate.resource_size_in_pixels) {
- return false;
- }
-
- candidate.plane_z_order = 0;
- candidate.overlay_handled = true;
- OverlayCandidateList new_candidate_list;
- new_candidate_list.push_back(candidate);
- capability_checker_->CheckOverlaySupport(&new_candidate_list);
- if (!new_candidate_list.front().overlay_handled)
- return false;
-
- candidate_list->swap(new_candidate_list);
-
- render_pass->quad_list = QuadList(); // Remove all the quads
- return true;
-}
-
-} // namespace cc
diff --git a/chromium/cc/output/overlay_strategy_fullscreen.h b/chromium/cc/output/overlay_strategy_fullscreen.h
deleted file mode 100644
index f8158d928fd..00000000000
--- a/chromium/cc/output/overlay_strategy_fullscreen.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_OVERLAY_STRATEGY_FULLSCREEN_H_
-#define CC_OUTPUT_OVERLAY_STRATEGY_FULLSCREEN_H_
-
-#include "base/macros.h"
-#include "cc/output/overlay_processor.h"
-
-namespace cc {
-
-class OverlayCandidateValidator;
-// Overlay strategy to promote a single full screen quad to an overlay.
-// The promoted quad should have all the property of the framebuffer and it
-// should be possible to use it as such.
-class CC_EXPORT OverlayStrategyFullscreen : public OverlayProcessor::Strategy {
- public:
- explicit OverlayStrategyFullscreen(
- OverlayCandidateValidator* capability_checker);
- ~OverlayStrategyFullscreen() override;
-
- bool Attempt(DisplayResourceProvider* resource_provider,
- RenderPass* render_pass,
- OverlayCandidateList* candidate_list,
- std::vector<gfx::Rect>* content_bounds) override;
-
- private:
- OverlayCandidateValidator* capability_checker_; // Weak.
-
- DISALLOW_COPY_AND_ASSIGN(OverlayStrategyFullscreen);
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_OVERLAY_STRATEGY_FULLSCREEN_H_
diff --git a/chromium/cc/output/overlay_strategy_single_on_top.cc b/chromium/cc/output/overlay_strategy_single_on_top.cc
deleted file mode 100644
index 138a889e921..00000000000
--- a/chromium/cc/output/overlay_strategy_single_on_top.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/overlay_strategy_single_on_top.h"
-
-#include "cc/base/math_util.h"
-#include "cc/output/overlay_candidate_validator.h"
-#include "cc/quads/draw_quad.h"
-#include "ui/gfx/buffer_types.h"
-#include "ui/gfx/geometry/rect_conversions.h"
-
-namespace cc {
-namespace {
-
-const gfx::BufferFormat kOverlayFormatsWithAlpha[] = {
- gfx::BufferFormat::RGBA_8888, gfx::BufferFormat::BGRA_8888};
-}
-
-OverlayStrategySingleOnTop::OverlayStrategySingleOnTop(
- OverlayCandidateValidator* capability_checker)
- : capability_checker_(capability_checker) {
- DCHECK(capability_checker);
-}
-
-OverlayStrategySingleOnTop::~OverlayStrategySingleOnTop() {}
-
-bool OverlayStrategySingleOnTop::Attempt(
- DisplayResourceProvider* resource_provider,
- RenderPass* render_pass,
- OverlayCandidateList* candidate_list,
- std::vector<gfx::Rect>* content_bounds) {
- QuadList* quad_list = &render_pass->quad_list;
- // Build a list of candidates with the associated quad.
- OverlayCandidate best_candidate;
- QuadList::Iterator best_quad_it = quad_list->end();
- for (auto it = quad_list->begin(); it != quad_list->end(); ++it) {
- OverlayCandidate candidate;
- if (OverlayCandidate::FromDrawQuad(resource_provider, *it, &candidate) &&
- !OverlayCandidate::IsOccluded(candidate, quad_list->cbegin(), it)) {
- // We currently reject quads with alpha that do not request alpha blending
- // since the alpha channel might not be set to 1 and we're not disabling
- // blending when scanning out.
- // TODO(dcastagna): We should support alpha formats without blending using
- // the opaque FB at scanout.
- if (std::find(std::begin(kOverlayFormatsWithAlpha),
- std::end(kOverlayFormatsWithAlpha),
- candidate.format) != std::end(kOverlayFormatsWithAlpha) &&
- it->shared_quad_state->blend_mode == SkBlendMode::kSrc)
- continue;
-
- if (candidate.display_rect.size().GetArea() >
- best_candidate.display_rect.size().GetArea()) {
- best_candidate = candidate;
- best_quad_it = it;
- }
- }
- }
- if (best_quad_it == quad_list->end())
- return false;
-
- if (TryOverlay(quad_list, candidate_list, best_candidate, best_quad_it))
- return true;
-
- return false;
-}
-
-bool OverlayStrategySingleOnTop::TryOverlay(
- QuadList* quad_list,
- OverlayCandidateList* candidate_list,
- const OverlayCandidate& candidate,
- QuadList::Iterator candidate_iterator) {
- // Add the overlay.
- OverlayCandidateList new_candidate_list = *candidate_list;
- new_candidate_list.push_back(candidate);
- new_candidate_list.back().plane_z_order = 1;
-
- // Check for support.
- capability_checker_->CheckOverlaySupport(&new_candidate_list);
-
- const OverlayCandidate& overlay_candidate = new_candidate_list.back();
- // If the candidate can be handled by an overlay, create a pass for it.
- if (overlay_candidate.overlay_handled) {
- quad_list->EraseAndInvalidateAllPointers(candidate_iterator);
- candidate_list->swap(new_candidate_list);
- return true;
- }
-
- return false;
-}
-
-} // namespace cc
diff --git a/chromium/cc/output/overlay_strategy_single_on_top.h b/chromium/cc/output/overlay_strategy_single_on_top.h
deleted file mode 100644
index e8dc61d5729..00000000000
--- a/chromium/cc/output/overlay_strategy_single_on_top.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_OVERLAY_STRATEGY_SINGLE_ON_TOP_H_
-#define CC_OUTPUT_OVERLAY_STRATEGY_SINGLE_ON_TOP_H_
-
-#include "base/macros.h"
-#include "cc/output/overlay_processor.h"
-
-namespace cc {
-
-class OverlayCandidateValidator;
-
-class CC_EXPORT OverlayStrategySingleOnTop : public OverlayProcessor::Strategy {
- public:
- explicit OverlayStrategySingleOnTop(
- OverlayCandidateValidator* capability_checker);
- ~OverlayStrategySingleOnTop() override;
-
- bool Attempt(DisplayResourceProvider* resource_provider,
- RenderPass* render_pass,
- OverlayCandidateList* candidate_list,
- std::vector<gfx::Rect>* content_bounds) override;
-
- private:
- bool TryOverlay(QuadList* quad_list,
- OverlayCandidateList* candidate_list,
- const OverlayCandidate& candidate,
- QuadList::Iterator candidate_iterator);
-
- OverlayCandidateValidator* capability_checker_; // Weak.
-
- DISALLOW_COPY_AND_ASSIGN(OverlayStrategySingleOnTop);
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_OVERLAY_STRATEGY_SINGLE_ON_TOP_H_
diff --git a/chromium/cc/output/overlay_strategy_underlay.cc b/chromium/cc/output/overlay_strategy_underlay.cc
deleted file mode 100644
index 70d2daf32de..00000000000
--- a/chromium/cc/output/overlay_strategy_underlay.cc
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/overlay_strategy_underlay.h"
-
-#include "cc/output/overlay_candidate_validator.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-
-namespace cc {
-
-OverlayStrategyUnderlay::OverlayStrategyUnderlay(
- OverlayCandidateValidator* capability_checker)
- : capability_checker_(capability_checker) {
- DCHECK(capability_checker);
-}
-
-OverlayStrategyUnderlay::~OverlayStrategyUnderlay() {}
-
-bool OverlayStrategyUnderlay::Attempt(
- DisplayResourceProvider* resource_provider,
- RenderPass* render_pass,
- OverlayCandidateList* candidate_list,
- std::vector<gfx::Rect>* content_bounds) {
- QuadList& quad_list = render_pass->quad_list;
- for (auto it = quad_list.begin(); it != quad_list.end(); ++it) {
- OverlayCandidate candidate;
- if (!OverlayCandidate::FromDrawQuad(resource_provider, *it, &candidate))
- continue;
-
- // Add the overlay.
- OverlayCandidateList new_candidate_list = *candidate_list;
- new_candidate_list.push_back(candidate);
- new_candidate_list.back().plane_z_order = -1;
-
- // Check for support.
- capability_checker_->CheckOverlaySupport(&new_candidate_list);
-
- // If the candidate can be handled by an overlay, create a pass for it. We
- // need to switch out the video quad with a black transparent one.
- if (new_candidate_list.back().overlay_handled) {
- new_candidate_list.back().is_unoccluded =
- !OverlayCandidate::IsOccluded(candidate, quad_list.cbegin(), it);
- quad_list.ReplaceExistingQuadWithOpaqueTransparentSolidColor(it);
- candidate_list->swap(new_candidate_list);
-
- // This quad will be promoted. We clear the promotable hints here, since
- // we can only promote a single quad. Otherwise, somebody might try to
- // back one of the promotable quads with a SurfaceView, and either it or
- // |candidate| would have to fall back to a texture.
- candidate_list->promotion_hint_info_map_.clear();
- candidate_list->AddPromotionHint(candidate);
- return true;
- } else {
- // If |candidate| should get a promotion hint, then rememeber that now.
- candidate_list->promotion_hint_info_map_.insert(
- new_candidate_list.promotion_hint_info_map_.begin(),
- new_candidate_list.promotion_hint_info_map_.end());
- }
- }
-
- return false;
-}
-
-} // namespace cc
diff --git a/chromium/cc/output/overlay_strategy_underlay.h b/chromium/cc/output/overlay_strategy_underlay.h
deleted file mode 100644
index fa91cdab033..00000000000
--- a/chromium/cc/output/overlay_strategy_underlay.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_OVERLAY_STRATEGY_UNDERLAY_H_
-#define CC_OUTPUT_OVERLAY_STRATEGY_UNDERLAY_H_
-
-#include "base/macros.h"
-#include "cc/output/overlay_processor.h"
-
-namespace cc {
-
-class OverlayCandidateValidator;
-
-// The underlay strategy looks for a video quad without regard to quads above
-// it. The video is "underlaid" through a black transparent quad substituted
-// for the video quad. The overlay content can then be blended in by the
-// hardware under the the scene. This is only valid for overlay contents that
-// are fully opaque.
-class CC_EXPORT OverlayStrategyUnderlay : public OverlayProcessor::Strategy {
- public:
- explicit OverlayStrategyUnderlay(
- OverlayCandidateValidator* capability_checker);
- ~OverlayStrategyUnderlay() override;
-
- bool Attempt(DisplayResourceProvider* resource_provider,
- RenderPass* render_pass,
- OverlayCandidateList* candidate_list,
- std::vector<gfx::Rect>* content_bounds) override;
-
- private:
- OverlayCandidateValidator* capability_checker_; // Weak.
-
- DISALLOW_COPY_AND_ASSIGN(OverlayStrategyUnderlay);
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_OVERLAY_STRATEGY_UNDERLAY_H_
diff --git a/chromium/cc/output/overlay_strategy_underlay_cast.cc b/chromium/cc/output/overlay_strategy_underlay_cast.cc
deleted file mode 100644
index bbe3fac8656..00000000000
--- a/chromium/cc/output/overlay_strategy_underlay_cast.cc
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/overlay_strategy_underlay_cast.h"
-
-#include "base/containers/adapters.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "ui/gfx/geometry/rect_conversions.h"
-
-namespace cc {
-
-OverlayStrategyUnderlayCast::OverlayStrategyUnderlayCast(
- OverlayCandidateValidator* capability_checker)
- : OverlayStrategyUnderlay(capability_checker) {}
-
-OverlayStrategyUnderlayCast::~OverlayStrategyUnderlayCast() {}
-
-bool OverlayStrategyUnderlayCast::Attempt(
- DisplayResourceProvider* resource_provider,
- RenderPass* render_pass,
- OverlayCandidateList* candidate_list,
- std::vector<gfx::Rect>* content_bounds) {
- const QuadList& const_quad_list = render_pass->quad_list;
- bool found_underlay = false;
- gfx::Rect content_rect;
- for (const auto* quad : base::Reversed(const_quad_list)) {
- if (OverlayCandidate::IsInvisibleQuad(quad))
- continue;
-
- const auto& transform = quad->shared_quad_state->quad_to_target_transform;
- gfx::RectF quad_rect = gfx::RectF(quad->rect);
- transform.TransformRect(&quad_rect);
-
- bool is_underlay = false;
- if (!found_underlay) {
- OverlayCandidate candidate;
- is_underlay =
- OverlayCandidate::FromDrawQuad(resource_provider, quad, &candidate);
- found_underlay = is_underlay;
- }
-
- if (!found_underlay && quad->material == DrawQuad::SOLID_COLOR) {
- const SolidColorDrawQuad* solid = SolidColorDrawQuad::MaterialCast(quad);
- if (solid->color == SK_ColorBLACK)
- continue;
- }
-
- if (is_underlay) {
- content_rect.Subtract(gfx::ToEnclosedRect(quad_rect));
- } else {
- content_rect.Union(gfx::ToEnclosingRect(quad_rect));
- }
- }
-
- const bool result = OverlayStrategyUnderlay::Attempt(
- resource_provider, render_pass, candidate_list, content_bounds);
- DCHECK(content_bounds && content_bounds->empty());
- DCHECK(result == found_underlay);
- if (found_underlay) {
- content_bounds->push_back(content_rect);
- }
- return result;
-}
-
-} // namespace cc
diff --git a/chromium/cc/output/overlay_strategy_underlay_cast.h b/chromium/cc/output/overlay_strategy_underlay_cast.h
deleted file mode 100644
index 09b7e1cfa7a..00000000000
--- a/chromium/cc/output/overlay_strategy_underlay_cast.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_OVERLAY_STRATEGY_UNDERLAY_CAST_H_
-#define CC_OUTPUT_OVERLAY_STRATEGY_UNDERLAY_CAST_H_
-
-#include "base/macros.h"
-#include "cc/output/overlay_strategy_underlay.h"
-
-namespace cc {
-
-class OverlayCandidateValidator;
-
-// Similar to underlay strategy plus Cast-specific handling of content bounds.
-class CC_EXPORT OverlayStrategyUnderlayCast : public OverlayStrategyUnderlay {
- public:
- explicit OverlayStrategyUnderlayCast(
- OverlayCandidateValidator* capability_checker);
- ~OverlayStrategyUnderlayCast() override;
-
- bool Attempt(DisplayResourceProvider* resource_provider,
- RenderPass* render_pass,
- OverlayCandidateList* candidate_list,
- std::vector<gfx::Rect>* content_bounds) override;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(OverlayStrategyUnderlayCast);
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_OVERLAY_STRATEGY_UNDERLAY_CAST_H_
diff --git a/chromium/cc/output/overlay_unittest.cc b/chromium/cc/output/overlay_unittest.cc
deleted file mode 100644
index c4cad0e33c5..00000000000
--- a/chromium/cc/output/overlay_unittest.cc
+++ /dev/null
@@ -1,2925 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <stddef.h>
-
-#include <utility>
-#include <vector>
-
-#include "base/containers/flat_map.h"
-#include "base/memory/ptr_util.h"
-#include "base/test/scoped_feature_list.h"
-#include "cc/base/filter_operation.h"
-#include "cc/base/region.h"
-#include "cc/output/ca_layer_overlay.h"
-#include "cc/output/output_surface.h"
-#include "cc/output/output_surface_client.h"
-#include "cc/output/output_surface_frame.h"
-#include "cc/output/overlay_candidate_validator.h"
-#include "cc/output/overlay_processor.h"
-#include "cc/output/overlay_strategy_fullscreen.h"
-#include "cc/output/overlay_strategy_single_on_top.h"
-#include "cc/output/overlay_strategy_underlay.h"
-#include "cc/output/overlay_strategy_underlay_cast.h"
-#include "cc/quads/render_pass.h"
-#include "cc/quads/render_pass_draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/stream_video_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
-#include "cc/resources/display_resource_provider.h"
-#include "cc/test/fake_output_surface_client.h"
-#include "cc/test/fake_resource_provider.h"
-#include "cc/test/geometry_test_utils.h"
-#include "cc/test/test_context_provider.h"
-#include "cc/test/test_shared_bitmap_manager.h"
-#include "cc/test/test_web_graphics_context_3d.h"
-#include "components/viz/common/quads/texture_mailbox.h"
-#include "components/viz/service/display/gl_renderer.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/geometry/rect_conversions.h"
-#include "ui/gl/gl_switches.h"
-#include "ui/latency/latency_info.h"
-
-using testing::_;
-using testing::Mock;
-using viz::SharedQuadState;
-
-namespace cc {
-namespace {
-
-const gfx::Size kDisplaySize(256, 256);
-const gfx::Rect kOverlayRect(0, 0, 256, 256);
-const gfx::Rect kOverlayTopLeftRect(0, 0, 128, 128);
-const gfx::Rect kOverlayBottomRightRect(128, 128, 128, 128);
-const gfx::Rect kOverlayClipRect(0, 0, 128, 128);
-const gfx::PointF kUVTopLeft(0.1f, 0.2f);
-const gfx::PointF kUVBottomRight(1.0f, 1.0f);
-const gfx::Transform kNormalTransform =
- gfx::Transform(0.9f, 0, 0, 0.8f, 0.1f, 0.2f); // x,y -> x,y.
-const gfx::Transform kXMirrorTransform =
- gfx::Transform(-0.9f, 0, 0, 0.8f, 1.0f, 0.2f); // x,y -> 1-x,y.
-const gfx::Transform kYMirrorTransform =
- gfx::Transform(0.9f, 0, 0, -0.8f, 0.1f, 1.0f); // x,y -> x,1-y.
-const gfx::Transform kBothMirrorTransform =
- gfx::Transform(-0.9f, 0, 0, -0.8f, 1.0f, 1.0f); // x,y -> 1-x,1-y.
-const gfx::Transform kSwapTransform =
- gfx::Transform(0, 1, 1, 0, 0, 0); // x,y -> y,x.
-
-void MailboxReleased(const gpu::SyncToken& sync_token,
- bool lost_resource,
- BlockingTaskRunner* main_thread_task_runner) {}
-
-class FullscreenOverlayValidator : public OverlayCandidateValidator {
- public:
- void GetStrategies(OverlayProcessor::StrategyList* strategies) override {
- strategies->push_back(std::make_unique<OverlayStrategyFullscreen>(this));
- }
- bool AllowCALayerOverlays() override { return false; }
- bool AllowDCLayerOverlays() override { return false; }
- void CheckOverlaySupport(OverlayCandidateList* surfaces) override {}
-};
-
-class SingleOverlayValidator : public OverlayCandidateValidator {
- public:
- SingleOverlayValidator() : expected_rects_(1, gfx::RectF(kOverlayRect)) {}
-
- void GetStrategies(OverlayProcessor::StrategyList* strategies) override {
- strategies->push_back(std::make_unique<OverlayStrategySingleOnTop>(this));
- strategies->push_back(std::make_unique<OverlayStrategyUnderlay>(this));
- }
-
- bool AllowCALayerOverlays() override { return false; }
- bool AllowDCLayerOverlays() override { return false; }
- void CheckOverlaySupport(OverlayCandidateList* surfaces) override {
- // We may have 1 or 2 surfaces depending on whether this ran through the
- // full renderer and picked up the output surface, or not.
- ASSERT_LE(1U, surfaces->size());
- ASSERT_GE(2U, surfaces->size());
-
- OverlayCandidate& candidate = surfaces->back();
- EXPECT_TRUE(!candidate.use_output_surface_for_resource);
- for (const auto& r : expected_rects_) {
- const float kAbsoluteError = 0.01f;
- if (std::abs(r.x() - candidate.display_rect.x()) <= kAbsoluteError &&
- std::abs(r.y() - candidate.display_rect.y()) <= kAbsoluteError &&
- std::abs(r.width() - candidate.display_rect.width()) <=
- kAbsoluteError &&
- std::abs(r.height() - candidate.display_rect.height()) <=
- kAbsoluteError) {
- EXPECT_FLOAT_RECT_EQ(BoundingRect(kUVTopLeft, kUVBottomRight),
- candidate.uv_rect);
- if (!candidate.clip_rect.IsEmpty()) {
- EXPECT_EQ(true, candidate.is_clipped);
- EXPECT_EQ(kOverlayClipRect, candidate.clip_rect);
- }
- candidate.overlay_handled = true;
- return;
- }
- }
- // We should find one rect in expected_rects_that matches candidate.
- EXPECT_TRUE(false);
- }
-
- void AddExpectedRect(const gfx::RectF& rect) {
- expected_rects_.push_back(rect);
- }
-
- private:
- std::vector<gfx::RectF> expected_rects_;
-};
-
-class CALayerValidator : public OverlayCandidateValidator {
- public:
- void GetStrategies(OverlayProcessor::StrategyList* strategies) override {}
- bool AllowCALayerOverlays() override { return true; }
- bool AllowDCLayerOverlays() override { return false; }
- void CheckOverlaySupport(OverlayCandidateList* surfaces) override {}
-};
-
-class DCLayerValidator : public OverlayCandidateValidator {
- public:
- void GetStrategies(OverlayProcessor::StrategyList* strategies) override {}
- bool AllowCALayerOverlays() override { return false; }
- bool AllowDCLayerOverlays() override { return true; }
- void CheckOverlaySupport(OverlayCandidateList* surfaces) override {}
-};
-
-class SingleOnTopOverlayValidator : public SingleOverlayValidator {
- public:
- void GetStrategies(OverlayProcessor::StrategyList* strategies) override {
- strategies->push_back(std::make_unique<OverlayStrategySingleOnTop>(this));
- }
-};
-
-class UnderlayOverlayValidator : public SingleOverlayValidator {
- public:
- void GetStrategies(OverlayProcessor::StrategyList* strategies) override {
- strategies->push_back(std::make_unique<OverlayStrategyUnderlay>(this));
- }
-};
-
-class UnderlayCastOverlayValidator : public SingleOverlayValidator {
- public:
- void GetStrategies(OverlayProcessor::StrategyList* strategies) override {
- strategies->push_back(std::make_unique<OverlayStrategyUnderlayCast>(this));
- }
-};
-
-class DefaultOverlayProcessor : public OverlayProcessor {
- public:
- explicit DefaultOverlayProcessor(OutputSurface* surface);
- size_t GetStrategyCount();
-};
-
-DefaultOverlayProcessor::DefaultOverlayProcessor(OutputSurface* surface)
- : OverlayProcessor(surface) {
-}
-
-size_t DefaultOverlayProcessor::GetStrategyCount() {
- return strategies_.size();
-}
-
-template <typename OverlayCandidateValidatorType>
-class OverlayOutputSurface : public OutputSurface {
- public:
- explicit OverlayOutputSurface(
- scoped_refptr<TestContextProvider> context_provider)
- : OutputSurface(std::move(context_provider)) {
- is_displayed_as_overlay_plane_ = true;
- }
-
- // OutputSurface implementation.
- void BindToClient(OutputSurfaceClient* client) override {}
- void EnsureBackbuffer() override {}
- void DiscardBackbuffer() override {}
- void BindFramebuffer() override {
- bind_framebuffer_count_ += 1;
- }
- void SetDrawRectangle(const gfx::Rect& rect) override {}
- void Reshape(const gfx::Size& size,
- float device_scale_factor,
- const gfx::ColorSpace& color_space,
- bool has_alpha,
- bool use_stencil) override {}
- void SwapBuffers(OutputSurfaceFrame frame) override {}
- uint32_t GetFramebufferCopyTextureFormat() override {
- // TestContextProvider has no real framebuffer, just use RGB.
- return GL_RGB;
- }
- bool HasExternalStencilTest() const override { return false; }
- void ApplyExternalStencil() override {}
- OverlayCandidateValidatorType* GetOverlayCandidateValidator() const override {
- return overlay_candidate_validator_.get();
- }
- bool IsDisplayedAsOverlayPlane() const override {
- return is_displayed_as_overlay_plane_;
- }
- unsigned GetOverlayTextureId() const override { return 10000; }
- gfx::BufferFormat GetOverlayBufferFormat() const override {
- return gfx::BufferFormat::RGBX_8888;
- }
- bool SurfaceIsSuspendForRecycle() const override { return false; }
-
- void set_is_displayed_as_overlay_plane(bool value) {
- is_displayed_as_overlay_plane_ = value;
- }
-
- void SetOverlayCandidateValidator(OverlayCandidateValidatorType* validator) {
- overlay_candidate_validator_.reset(validator);
- }
-
- unsigned bind_framebuffer_count() const { return bind_framebuffer_count_; }
-
- private:
- std::unique_ptr<OverlayCandidateValidatorType> overlay_candidate_validator_;
- bool is_displayed_as_overlay_plane_;
- unsigned bind_framebuffer_count_ = 0;
-};
-
-std::unique_ptr<RenderPass> CreateRenderPass() {
- int render_pass_id = 1;
- gfx::Rect output_rect(0, 0, 256, 256);
-
- std::unique_ptr<RenderPass> pass = RenderPass::Create();
- pass->SetNew(render_pass_id, output_rect, output_rect, gfx::Transform());
-
- SharedQuadState* shared_state = pass->CreateAndAppendSharedQuadState();
- shared_state->opacity = 1.f;
- return pass;
-}
-
-std::unique_ptr<RenderPass> CreateRenderPassWithTransform(
- const gfx::Transform& transform) {
- int render_pass_id = 1;
- gfx::Rect output_rect(0, 0, 256, 256);
-
- std::unique_ptr<RenderPass> pass = RenderPass::Create();
- pass->SetNew(render_pass_id, output_rect, output_rect, gfx::Transform());
-
- SharedQuadState* shared_state = pass->CreateAndAppendSharedQuadState();
- shared_state->opacity = 1.f;
- shared_state->quad_to_target_transform = transform;
- return pass;
-}
-
-viz::ResourceId CreateResource(ResourceProvider* resource_provider,
- const gfx::Size& size,
- bool is_overlay_candidate) {
- viz::TextureMailbox mailbox =
- viz::TextureMailbox(gpu::Mailbox::Generate(), gpu::SyncToken(),
- GL_TEXTURE_2D, size, is_overlay_candidate, false);
- std::unique_ptr<SingleReleaseCallbackImpl> release_callback =
- SingleReleaseCallbackImpl::Create(base::Bind(&MailboxReleased));
-
- return resource_provider->CreateResourceFromTextureMailbox(
- mailbox, std::move(release_callback));
-}
-
-SolidColorDrawQuad* CreateSolidColorQuadAt(
- const SharedQuadState* shared_quad_state,
- SkColor color,
- RenderPass* render_pass,
- const gfx::Rect& rect) {
- SolidColorDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- quad->SetNew(shared_quad_state, rect, rect, color, false);
- return quad;
-}
-
-TextureDrawQuad* CreateCandidateQuadAt(ResourceProvider* resource_provider,
- const SharedQuadState* shared_quad_state,
- RenderPass* render_pass,
- const gfx::Rect& rect) {
- bool needs_blending = false;
- bool premultiplied_alpha = false;
- bool flipped = false;
- bool nearest_neighbor = false;
- float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f};
- gfx::Size resource_size_in_pixels = rect.size();
- bool is_overlay_candidate = true;
- viz::ResourceId resource_id = CreateResource(
- resource_provider, resource_size_in_pixels, is_overlay_candidate);
-
- TextureDrawQuad* overlay_quad =
- render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
- overlay_quad->SetNew(shared_quad_state, rect, rect, needs_blending,
- resource_id, premultiplied_alpha, kUVTopLeft,
- kUVBottomRight, SK_ColorTRANSPARENT, vertex_opacity,
- flipped, nearest_neighbor, false);
- overlay_quad->set_resource_size_in_pixels(resource_size_in_pixels);
-
- return overlay_quad;
-}
-
-TextureDrawQuad* CreateTransparentCandidateQuadAt(
- ResourceProvider* resource_provider,
- const SharedQuadState* shared_quad_state,
- RenderPass* render_pass,
- const gfx::Rect& rect) {
- bool needs_blending = true;
- bool premultiplied_alpha = false;
- bool flipped = false;
- bool nearest_neighbor = false;
- float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f};
- gfx::Size resource_size_in_pixels = rect.size();
- bool is_overlay_candidate = true;
- viz::ResourceId resource_id = CreateResource(
- resource_provider, resource_size_in_pixels, is_overlay_candidate);
-
- TextureDrawQuad* overlay_quad =
- render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
- overlay_quad->SetNew(shared_quad_state, rect, rect, needs_blending,
- resource_id, premultiplied_alpha, kUVTopLeft,
- kUVBottomRight, SK_ColorTRANSPARENT, vertex_opacity,
- flipped, nearest_neighbor, false);
- overlay_quad->set_resource_size_in_pixels(resource_size_in_pixels);
-
- return overlay_quad;
-}
-
-StreamVideoDrawQuad* CreateCandidateVideoQuadAt(
- ResourceProvider* resource_provider,
- const SharedQuadState* shared_quad_state,
- RenderPass* render_pass,
- const gfx::Rect& rect,
- const gfx::Transform& transform) {
- bool needs_blending = false;
- gfx::Size resource_size_in_pixels = rect.size();
- bool is_overlay_candidate = true;
- viz::ResourceId resource_id = CreateResource(
- resource_provider, resource_size_in_pixels, is_overlay_candidate);
-
- StreamVideoDrawQuad* overlay_quad =
- render_pass->CreateAndAppendDrawQuad<StreamVideoDrawQuad>();
- overlay_quad->SetNew(shared_quad_state, rect, rect, needs_blending,
- resource_id, resource_size_in_pixels, transform);
-
- return overlay_quad;
-}
-
-TextureDrawQuad* CreateFullscreenCandidateQuad(
- ResourceProvider* resource_provider,
- const SharedQuadState* shared_quad_state,
- RenderPass* render_pass) {
- return CreateCandidateQuadAt(resource_provider, shared_quad_state,
- render_pass, render_pass->output_rect);
-}
-
-StreamVideoDrawQuad* CreateFullscreenCandidateVideoQuad(
- ResourceProvider* resource_provider,
- const SharedQuadState* shared_quad_state,
- RenderPass* render_pass,
- const gfx::Transform& transform) {
- return CreateCandidateVideoQuadAt(resource_provider, shared_quad_state,
- render_pass, render_pass->output_rect,
- transform);
-}
-
-YUVVideoDrawQuad* CreateFullscreenCandidateYUVVideoQuad(
- ResourceProvider* resource_provider,
- const SharedQuadState* shared_quad_state,
- RenderPass* render_pass) {
- bool needs_blending = false;
- gfx::RectF tex_coord_rect(0, 0, 1, 1);
- gfx::Rect rect = render_pass->output_rect;
- gfx::Size resource_size_in_pixels = rect.size();
- bool is_overlay_candidate = true;
- viz::ResourceId resource_id = CreateResource(
- resource_provider, resource_size_in_pixels, is_overlay_candidate);
-
- YUVVideoDrawQuad* overlay_quad =
- render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>();
- overlay_quad->SetNew(shared_quad_state, rect, rect, needs_blending,
- tex_coord_rect, tex_coord_rect, resource_size_in_pixels,
- resource_size_in_pixels, resource_id, resource_id,
- resource_id, resource_id, YUVVideoDrawQuad::REC_601,
- gfx::ColorSpace(), 0, 1.0, 8);
-
- return overlay_quad;
-}
-
-void CreateOpaqueQuadAt(ResourceProvider* resource_provider,
- const SharedQuadState* shared_quad_state,
- RenderPass* render_pass,
- const gfx::Rect& rect) {
- SolidColorDrawQuad* color_quad =
- render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(shared_quad_state, rect, rect, SK_ColorBLACK, false);
-}
-
-void CreateOpaqueQuadAt(ResourceProvider* resource_provider,
- const SharedQuadState* shared_quad_state,
- RenderPass* render_pass,
- const gfx::Rect& rect,
- SkColor color) {
- DCHECK_EQ(255u, SkColorGetA(color));
- SolidColorDrawQuad* color_quad =
- render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(shared_quad_state, rect, rect, color, false);
-}
-
-void CreateFullscreenOpaqueQuad(ResourceProvider* resource_provider,
- const SharedQuadState* shared_quad_state,
- RenderPass* render_pass) {
- CreateOpaqueQuadAt(resource_provider, shared_quad_state, render_pass,
- render_pass->output_rect);
-}
-
-static void CompareRenderPassLists(const RenderPassList& expected_list,
- const RenderPassList& actual_list) {
- EXPECT_EQ(expected_list.size(), actual_list.size());
- for (size_t i = 0; i < actual_list.size(); ++i) {
- RenderPass* expected = expected_list[i].get();
- RenderPass* actual = actual_list[i].get();
-
- EXPECT_EQ(expected->id, actual->id);
- EXPECT_EQ(expected->output_rect, actual->output_rect);
- EXPECT_EQ(expected->transform_to_root_target,
- actual->transform_to_root_target);
- EXPECT_EQ(expected->damage_rect, actual->damage_rect);
- EXPECT_EQ(expected->has_transparent_background,
- actual->has_transparent_background);
-
- EXPECT_EQ(expected->shared_quad_state_list.size(),
- actual->shared_quad_state_list.size());
- EXPECT_EQ(expected->quad_list.size(), actual->quad_list.size());
-
- for (auto exp_iter = expected->quad_list.cbegin(),
- act_iter = actual->quad_list.cbegin();
- exp_iter != expected->quad_list.cend();
- ++exp_iter, ++act_iter) {
- EXPECT_EQ(exp_iter->rect.ToString(), act_iter->rect.ToString());
- EXPECT_EQ(exp_iter->shared_quad_state->quad_layer_rect.ToString(),
- act_iter->shared_quad_state->quad_layer_rect.ToString());
- }
- }
-}
-
-template <typename OverlayCandidateValidatorType>
-class OverlayTest : public testing::Test {
- using OutputSurfaceType = OverlayOutputSurface<OverlayCandidateValidatorType>;
-
- protected:
- void SetUp() override {
- provider_ = TestContextProvider::Create();
- provider_->BindToCurrentThread();
- output_surface_ = std::make_unique<OutputSurfaceType>(provider_);
- output_surface_->BindToClient(&client_);
- output_surface_->SetOverlayCandidateValidator(
- new OverlayCandidateValidatorType);
-
- shared_bitmap_manager_.reset(new TestSharedBitmapManager());
- resource_provider_ = FakeResourceProvider::Create<DisplayResourceProvider>(
- provider_.get(), shared_bitmap_manager_.get());
-
- overlay_processor_.reset(new OverlayProcessor(output_surface_.get()));
- overlay_processor_->Initialize();
- }
-
- scoped_refptr<TestContextProvider> provider_;
- std::unique_ptr<OutputSurfaceType> output_surface_;
- FakeOutputSurfaceClient client_;
- std::unique_ptr<viz::SharedBitmapManager> shared_bitmap_manager_;
- std::unique_ptr<DisplayResourceProvider> resource_provider_;
- std::unique_ptr<OverlayProcessor> overlay_processor_;
- gfx::Rect damage_rect_;
- std::vector<gfx::Rect> content_bounds_;
-};
-
-using FullscreenOverlayTest = OverlayTest<FullscreenOverlayValidator>;
-using SingleOverlayOnTopTest = OverlayTest<SingleOnTopOverlayValidator>;
-using UnderlayTest = OverlayTest<UnderlayOverlayValidator>;
-using UnderlayCastTest = OverlayTest<UnderlayCastOverlayValidator>;
-using CALayerOverlayTest = OverlayTest<CALayerValidator>;
-
-TEST(OverlayTest, NoOverlaysByDefault) {
- scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
- OverlayOutputSurface<OverlayCandidateValidator> output_surface(provider);
- EXPECT_EQ(NULL, output_surface.GetOverlayCandidateValidator());
-
- output_surface.SetOverlayCandidateValidator(new SingleOverlayValidator);
- EXPECT_TRUE(output_surface.GetOverlayCandidateValidator() != NULL);
-}
-
-TEST(OverlayTest, OverlaysProcessorHasStrategy) {
- scoped_refptr<TestContextProvider> provider = TestContextProvider::Create();
- provider->BindToCurrentThread();
- OverlayOutputSurface<OverlayCandidateValidator> output_surface(provider);
- FakeOutputSurfaceClient client;
- output_surface.BindToClient(&client);
- output_surface.SetOverlayCandidateValidator(new SingleOverlayValidator);
-
- std::unique_ptr<viz::SharedBitmapManager> shared_bitmap_manager(
- new TestSharedBitmapManager());
- std::unique_ptr<DisplayResourceProvider> resource_provider =
- FakeResourceProvider::Create<DisplayResourceProvider>(
- provider.get(), shared_bitmap_manager.get());
-
- std::unique_ptr<DefaultOverlayProcessor> overlay_processor(
- new DefaultOverlayProcessor(&output_surface));
- overlay_processor->Initialize();
- EXPECT_GE(2U, overlay_processor->GetStrategyCount());
-}
-
-TEST_F(FullscreenOverlayTest, SuccessfulOverlay) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- gfx::Rect output_rect = pass->output_rect;
- TextureDrawQuad* original_quad = CreateFullscreenCandidateQuad(
- resource_provider_.get(), pass->shared_quad_state_list.back(),
- pass.get());
- unsigned original_resource_id = original_quad->resource_id();
-
- // Add something behind it.
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
-
- // Check for potential candidates.
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- RenderPass* main_pass = pass.get();
- pass_list.push_back(std::move(pass));
-
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- ASSERT_EQ(1U, candidate_list.size());
-
- // Check that all the quads are gone.
- EXPECT_EQ(0U, main_pass->quad_list.size());
- // Check that we have only one overlay.
- EXPECT_EQ(1U, candidate_list.size());
- // Check that the right resource id got extracted.
- EXPECT_EQ(original_resource_id, candidate_list.front().resource_id);
- gfx::Rect overlay_damage_rect =
- overlay_processor_->GetAndResetOverlayDamage();
- EXPECT_EQ(output_rect, overlay_damage_rect);
-}
-
-TEST_F(FullscreenOverlayTest, AlphaFail) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateTransparentCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get(), pass.get()->output_rect);
-
- // Check for potential candidates.
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- RenderPass* main_pass = pass.get();
- pass_list.push_back(std::move(pass));
-
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
-
- // Check that all the quads are gone.
- EXPECT_EQ(1U, main_pass->quad_list.size());
- // Check that we have only one overlay.
- EXPECT_EQ(0U, candidate_list.size());
-}
-
-TEST_F(FullscreenOverlayTest, ResourceSizeInPixelsFail) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- TextureDrawQuad* original_quad = CreateFullscreenCandidateQuad(
- resource_provider_.get(), pass->shared_quad_state_list.back(),
- pass.get());
- original_quad->set_resource_size_in_pixels(gfx::Size(64, 64));
-
- // Check for potential candidates.
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- RenderPass* main_pass = pass.get();
- pass_list.push_back(std::move(pass));
-
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- ASSERT_EQ(0U, candidate_list.size());
-
- // Check that the quad is not gone.
- EXPECT_EQ(1U, main_pass->quad_list.size());
-}
-
-TEST_F(FullscreenOverlayTest, OnTopFail) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
-
- // Add something in front of it.
- CreateOpaqueQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayTopLeftRect);
-
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
-
- // Check for potential candidates.
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- RenderPass* main_pass = pass.get();
- pass_list.push_back(std::move(pass));
-
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- ASSERT_EQ(0U, candidate_list.size());
-
- // Check that the 2 quads are not gone.
- EXPECT_EQ(2U, main_pass->quad_list.size());
-}
-
-TEST_F(FullscreenOverlayTest, NotCoveringFullscreenFail) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- gfx::Rect inset_rect = pass->output_rect;
- inset_rect.Inset(0, 1, 0, 1);
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- inset_rect);
-
- // Check for potential candidates.
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- RenderPass* main_pass = pass.get();
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- ASSERT_EQ(0U, candidate_list.size());
-
- // Check that the quad is not gone.
- EXPECT_EQ(1U, main_pass->quad_list.size());
-}
-
-TEST_F(FullscreenOverlayTest, RemoveFullscreenQuadFromQuadList) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
-
- // Add something in front of it that is fully transparent.
- pass->shared_quad_state_list.back()->opacity = 0.0f;
- CreateOpaqueQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayTopLeftRect);
-
- SharedQuadState* shared_state = pass->CreateAndAppendSharedQuadState();
- shared_state->opacity = 1.f;
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
-
- // Check for potential candidates.
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- RenderPass* main_pass = pass.get();
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- ASSERT_EQ(1U, candidate_list.size());
-
- // Check that the fullscreen quad is gone.
- for (const DrawQuad* quad : main_pass->quad_list) {
- EXPECT_NE(main_pass->output_rect, quad->rect);
- }
-}
-
-TEST_F(SingleOverlayOnTopTest, SuccessfulOverlay) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- TextureDrawQuad* original_quad =
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- unsigned original_resource_id = original_quad->resource_id();
-
- // Add something behind it.
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
-
- // Check for potential candidates.
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- RenderPass* main_pass = pass.get();
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- ASSERT_EQ(1U, candidate_list.size());
-
- // Check that the quad is gone.
- EXPECT_EQ(2U, main_pass->quad_list.size());
- const QuadList& quad_list = main_pass->quad_list;
- for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin();
- it != quad_list.BackToFrontEnd();
- ++it) {
- EXPECT_NE(DrawQuad::TEXTURE_CONTENT, it->material);
- }
-
- // Check that the right resource id got extracted.
- EXPECT_EQ(original_resource_id, candidate_list.back().resource_id);
-}
-
-TEST_F(SingleOverlayOnTopTest, PrioritizeBiggerOne) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- // Add a small quad.
- const auto kSmallCandidateRect = gfx::Rect(0, 0, 16, 16);
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kSmallCandidateRect);
- output_surface_->GetOverlayCandidateValidator()->AddExpectedRect(
- gfx::RectF(kSmallCandidateRect));
-
- // Add a bigger quad below the previous one, but not occluded.
- const auto kBigCandidateRect = gfx::Rect(20, 20, 32, 32);
- TextureDrawQuad* quad_big = CreateCandidateQuadAt(
- resource_provider_.get(), pass->shared_quad_state_list.back(), pass.get(),
- kBigCandidateRect);
- output_surface_->GetOverlayCandidateValidator()->AddExpectedRect(
- gfx::RectF(kBigCandidateRect));
-
- unsigned resource_big = quad_big->resource_id();
-
- // Add something behind it.
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
-
- // Check for potential candidates.
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- RenderPass* main_pass = pass.get();
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- ASSERT_EQ(1U, candidate_list.size());
-
- // Check that one quad is gone.
- EXPECT_EQ(2U, main_pass->quad_list.size());
- // Check that we have only one overlay.
- EXPECT_EQ(1U, candidate_list.size());
- // Check that the right resource id (bigger quad) got extracted.
- EXPECT_EQ(resource_big, candidate_list.front().resource_id);
-}
-
-TEST_F(SingleOverlayOnTopTest, DamageRect) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- damage_rect_ = kOverlayRect;
-
- // Add something behind it.
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
-
- // Check for potential candidates.
- OverlayCandidateList candidate_list;
-
- // Primary plane.
- OverlayCandidate output_surface_plane;
- output_surface_plane.display_rect = gfx::RectF(kOverlayRect);
- output_surface_plane.use_output_surface_for_resource = true;
- output_surface_plane.overlay_handled = true;
- candidate_list.push_back(output_surface_plane);
-
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_TRUE(damage_rect_.IsEmpty());
-}
-
-TEST_F(SingleOverlayOnTopTest, NoCandidates) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- RenderPassList original_pass_list;
- RenderPass::CopyAll(pass_list, &original_pass_list);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(0U, candidate_list.size());
- // There should be nothing new here.
- CompareRenderPassLists(pass_list, original_pass_list);
-}
-
-TEST_F(SingleOverlayOnTopTest, OccludedCandidates) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
-
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- RenderPassList original_pass_list;
- RenderPass::CopyAll(pass_list, &original_pass_list);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(0U, candidate_list.size());
- // There should be nothing new here.
- CompareRenderPassLists(pass_list, original_pass_list);
-}
-
-// Test with multiple render passes.
-TEST_F(SingleOverlayOnTopTest, MultipleRenderPasses) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
-
- // Add something behind it.
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
-
- // Check for potential candidates.
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(1U, candidate_list.size());
-}
-
-TEST_F(SingleOverlayOnTopTest, AcceptBlending) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- TextureDrawQuad* quad =
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- quad->needs_blending = true;
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- damage_rect_ = quad->rect;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(1U, candidate_list.size());
- EXPECT_FALSE(damage_rect_.IsEmpty());
- gfx::Rect overlay_damage_rect =
- overlay_processor_->GetAndResetOverlayDamage();
- EXPECT_FALSE(overlay_damage_rect.IsEmpty());
-}
-
-TEST_F(SingleOverlayOnTopTest, RejectBackgroundColor) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- TextureDrawQuad* quad =
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- quad->background_color = SK_ColorBLACK;
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(0U, candidate_list.size());
-}
-
-TEST_F(SingleOverlayOnTopTest, RejectBlendMode) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- pass->shared_quad_state_list.back()->blend_mode = SkBlendMode::kScreen;
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(0U, candidate_list.size());
-}
-
-TEST_F(SingleOverlayOnTopTest, RejectOpacity) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- pass->shared_quad_state_list.back()->opacity = 0.5f;
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(0U, candidate_list.size());
-}
-
-TEST_F(SingleOverlayOnTopTest, RejectNonAxisAlignedTransform) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- pass->shared_quad_state_list.back()
- ->quad_to_target_transform.RotateAboutXAxis(45.f);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(0U, candidate_list.size());
-}
-
-TEST_F(SingleOverlayOnTopTest, AllowClipped) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- pass->shared_quad_state_list.back()->is_clipped = true;
- pass->shared_quad_state_list.back()->clip_rect = kOverlayClipRect;
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(1U, candidate_list.size());
-}
-
-TEST_F(UnderlayTest, AllowVerticalFlip) {
- gfx::Rect rect = kOverlayRect;
- rect.set_width(rect.width() / 2);
- rect.Offset(0, -rect.height());
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(), rect);
- pass->shared_quad_state_list.back()->quad_to_target_transform.Scale(2.0f,
- -1.0f);
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- ASSERT_EQ(1U, candidate_list.size());
- EXPECT_EQ(gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL,
- candidate_list.back().transform);
-}
-
-TEST_F(UnderlayTest, AllowHorizontalFlip) {
- gfx::Rect rect = kOverlayRect;
- rect.set_height(rect.height() / 2);
- rect.Offset(-rect.width(), 0);
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(), rect);
- pass->shared_quad_state_list.back()->quad_to_target_transform.Scale(-1.0f,
- 2.0f);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- ASSERT_EQ(1U, candidate_list.size());
- EXPECT_EQ(gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL,
- candidate_list.back().transform);
-}
-
-TEST_F(SingleOverlayOnTopTest, AllowPositiveScaleTransform) {
- gfx::Rect rect = kOverlayRect;
- rect.set_width(rect.width() / 2);
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(), rect);
- pass->shared_quad_state_list.back()->quad_to_target_transform.Scale(2.0f,
- 1.0f);
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(1U, candidate_list.size());
-}
-
-TEST_F(SingleOverlayOnTopTest, AcceptMirrorYTransform) {
- gfx::Rect rect = kOverlayRect;
- rect.Offset(0, -rect.height());
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(), rect);
- pass->shared_quad_state_list.back()->quad_to_target_transform.Scale(1.f,
- -1.f);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- ASSERT_EQ(1U, candidate_list.size());
-}
-
-TEST_F(UnderlayTest, Allow90DegreeRotation) {
- gfx::Rect rect = kOverlayRect;
- rect.Offset(0, -rect.height());
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(), rect);
- pass->shared_quad_state_list.back()
- ->quad_to_target_transform.RotateAboutZAxis(90.f);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- ASSERT_EQ(1U, candidate_list.size());
- EXPECT_EQ(gfx::OVERLAY_TRANSFORM_ROTATE_90, candidate_list.back().transform);
-}
-
-TEST_F(UnderlayTest, Allow180DegreeRotation) {
- gfx::Rect rect = kOverlayRect;
- rect.Offset(-rect.width(), -rect.height());
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(), rect);
- pass->shared_quad_state_list.back()
- ->quad_to_target_transform.RotateAboutZAxis(180.f);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- ASSERT_EQ(1U, candidate_list.size());
- EXPECT_EQ(gfx::OVERLAY_TRANSFORM_ROTATE_180, candidate_list.back().transform);
-}
-
-TEST_F(UnderlayTest, Allow270DegreeRotation) {
- gfx::Rect rect = kOverlayRect;
- rect.Offset(-rect.width(), 0);
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(), rect);
- pass->shared_quad_state_list.back()
- ->quad_to_target_transform.RotateAboutZAxis(270.f);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- ASSERT_EQ(1U, candidate_list.size());
- EXPECT_EQ(gfx::OVERLAY_TRANSFORM_ROTATE_270, candidate_list.back().transform);
-}
-
-TEST_F(SingleOverlayOnTopTest, AllowNotTopIfNotOccluded) {
- output_surface_->GetOverlayCandidateValidator()->AddExpectedRect(
- gfx::RectF(kOverlayBottomRightRect));
-
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateOpaqueQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayTopLeftRect);
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get(),
- kOverlayBottomRightRect);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(1U, candidate_list.size());
-}
-
-TEST_F(SingleOverlayOnTopTest, AllowTransparentOnTop) {
- output_surface_->GetOverlayCandidateValidator()->AddExpectedRect(
- gfx::RectF(kOverlayBottomRightRect));
-
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- SharedQuadState* shared_state = pass->CreateAndAppendSharedQuadState();
- shared_state->opacity = 0.f;
- CreateSolidColorQuadAt(shared_state, SK_ColorBLACK, pass.get(),
- kOverlayBottomRightRect);
- shared_state = pass->CreateAndAppendSharedQuadState();
- shared_state->opacity = 1.f;
- CreateCandidateQuadAt(resource_provider_.get(), shared_state, pass.get(),
- kOverlayBottomRightRect);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(1U, candidate_list.size());
-}
-
-TEST_F(SingleOverlayOnTopTest, AllowTransparentColorOnTop) {
- output_surface_->GetOverlayCandidateValidator()->AddExpectedRect(
- gfx::RectF(kOverlayBottomRightRect));
-
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateSolidColorQuadAt(pass->shared_quad_state_list.back(),
- SK_ColorTRANSPARENT, pass.get(),
- kOverlayBottomRightRect);
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayBottomRightRect);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(1U, candidate_list.size());
-}
-
-TEST_F(SingleOverlayOnTopTest, RejectOpaqueColorOnTop) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- SharedQuadState* shared_state = pass->CreateAndAppendSharedQuadState();
- shared_state->opacity = 0.5f;
- CreateSolidColorQuadAt(shared_state, SK_ColorBLACK, pass.get(),
- kOverlayBottomRightRect);
- shared_state = pass->CreateAndAppendSharedQuadState();
- shared_state->opacity = 1.f;
- CreateCandidateQuadAt(resource_provider_.get(), shared_state, pass.get(),
- kOverlayBottomRightRect);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(0U, candidate_list.size());
-}
-
-TEST_F(SingleOverlayOnTopTest, RejectTransparentColorOnTopWithoutBlending) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- SharedQuadState* shared_state = pass->CreateAndAppendSharedQuadState();
- CreateSolidColorQuadAt(shared_state, SK_ColorTRANSPARENT, pass.get(),
- kOverlayBottomRightRect)
- ->needs_blending = false;
- CreateCandidateQuadAt(resource_provider_.get(), shared_state, pass.get(),
- kOverlayBottomRightRect);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(0U, candidate_list.size());
-}
-
-TEST_F(SingleOverlayOnTopTest, RejectVideoSwapTransform) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateVideoQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get(), kSwapTransform);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(0U, candidate_list.size());
-}
-
-TEST_F(UnderlayTest, AllowVideoXMirrorTransform) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateVideoQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get(), kXMirrorTransform);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(1U, candidate_list.size());
-}
-
-TEST_F(UnderlayTest, AllowVideoBothMirrorTransform) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateVideoQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get(), kBothMirrorTransform);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(1U, candidate_list.size());
-}
-
-TEST_F(UnderlayTest, AllowVideoNormalTransform) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateVideoQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get(), kNormalTransform);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(1U, candidate_list.size());
-}
-
-TEST_F(SingleOverlayOnTopTest, AllowVideoYMirrorTransform) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateVideoQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get(), kYMirrorTransform);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(1U, candidate_list.size());
-}
-
-TEST_F(UnderlayTest, OverlayLayerUnderMainLayer) {
- output_surface_->GetOverlayCandidateValidator()->AddExpectedRect(
- gfx::RectF(kOverlayBottomRightRect));
-
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayBottomRightRect);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- RenderPass* main_pass = pass.get();
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- ASSERT_EQ(1U, candidate_list.size());
- EXPECT_EQ(-1, candidate_list[0].plane_z_order);
- EXPECT_EQ(2U, main_pass->quad_list.size());
- // The overlay quad should have changed to a SOLID_COLOR quad.
- EXPECT_EQ(main_pass->quad_list.back()->material, DrawQuad::SOLID_COLOR);
- SolidColorDrawQuad* quad =
- static_cast<SolidColorDrawQuad*>(main_pass->quad_list.back());
- EXPECT_EQ(quad->rect, quad->visible_rect);
- EXPECT_EQ(false, quad->needs_blending);
- EXPECT_EQ(SK_ColorTRANSPARENT, quad->color);
-}
-
-TEST_F(UnderlayTest, AllowOnTop) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- pass->CreateAndAppendSharedQuadState()->opacity = 0.5f;
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- RenderPass* main_pass = pass.get();
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- ASSERT_EQ(1U, candidate_list.size());
- EXPECT_EQ(-1, candidate_list[0].plane_z_order);
- // The overlay quad should have changed to a SOLID_COLOR quad.
- EXPECT_EQ(main_pass->quad_list.front()->material, DrawQuad::SOLID_COLOR);
- SolidColorDrawQuad* quad =
- static_cast<SolidColorDrawQuad*>(main_pass->quad_list.front());
- EXPECT_EQ(quad->rect, quad->visible_rect);
- EXPECT_EQ(false, quad->needs_blending);
- EXPECT_EQ(SK_ColorTRANSPARENT, quad->color);
-}
-
-// The first time an underlay is scheduled its damage must not be subtracted.
-TEST_F(UnderlayTest, InitialUnderlayDamageNotSubtracted) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
-
- damage_rect_ = kOverlayRect;
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
-
- EXPECT_EQ(kOverlayRect, damage_rect_);
-}
-
-// An identical underlay for two frames in a row means the damage can be
-// subtracted the second time.
-TEST_F(UnderlayTest, DamageSubtractedForConsecutiveIdenticalUnderlays) {
- for (int i = 0; i < 2; ++i) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
-
- damage_rect_ = kOverlayRect;
-
- // Add something behind it.
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- }
-
- // The second time the same overlay rect is scheduled it will be subtracted
- // from the damage rect.
- EXPECT_TRUE(damage_rect_.IsEmpty());
-}
-
-// Underlay damage can only be subtracted if the previous frame's underlay
-// was the same rect.
-TEST_F(UnderlayTest, DamageNotSubtractedForNonIdenticalConsecutiveUnderlays) {
- gfx::Rect overlay_rects[] = {kOverlayBottomRightRect, kOverlayRect};
- for (int i = 0; i < 2; ++i) {
- output_surface_->GetOverlayCandidateValidator()->AddExpectedRect(
- gfx::RectF(overlay_rects[i]));
-
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
-
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- overlay_rects[i]);
-
- damage_rect_ = overlay_rects[i];
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
-
- EXPECT_EQ(overlay_rects[i], damage_rect_);
- }
-}
-
-// Underlay damage can only be subtracted if the previous frame's underlay
-// exists.
-TEST_F(UnderlayTest, DamageNotSubtractedForNonConsecutiveIdenticalUnderlays) {
- bool has_fullscreen_candidate[] = {true, false, true};
-
- for (int i = 0; i < 3; ++i) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
-
- if (has_fullscreen_candidate[i]) {
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- }
-
- damage_rect_ = kOverlayRect;
-
- // Add something behind it.
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- }
-
- EXPECT_EQ(kOverlayRect, damage_rect_);
-}
-
-TEST_F(UnderlayTest, DamageNotSubtractedWhenQuadsAboveOverlap) {
- for (int i = 0; i < 2; ++i) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- // Add an overlapping quad above the candidate.
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
-
- damage_rect_ = kOverlayRect;
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- }
-
- EXPECT_EQ(kOverlayRect, damage_rect_);
-}
-
-TEST_F(UnderlayTest, DamageSubtractedWhenQuadsAboveDontOverlap) {
- output_surface_->GetOverlayCandidateValidator()->AddExpectedRect(
- gfx::RectF(kOverlayBottomRightRect));
-
- for (int i = 0; i < 2; ++i) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- // Add a non-overlapping quad above the candidate.
- CreateOpaqueQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayTopLeftRect);
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayBottomRightRect);
-
- damage_rect_ = kOverlayBottomRightRect;
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- }
-
- EXPECT_TRUE(damage_rect_.IsEmpty());
-}
-
-TEST_F(UnderlayCastTest, NoOverlayContentBounds) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
-
- CreateOpaqueQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayTopLeftRect);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(0U, content_bounds_.size());
-}
-
-TEST_F(UnderlayCastTest, FullScreenOverlayContentBounds) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayRect);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
-
- EXPECT_EQ(1U, content_bounds_.size());
- EXPECT_TRUE(content_bounds_[0].IsEmpty());
-}
-
-TEST_F(UnderlayCastTest, BlackOutsideOverlayContentBounds) {
- output_surface_->GetOverlayCandidateValidator()->AddExpectedRect(
- gfx::RectF(kOverlayBottomRightRect));
-
- const gfx::Rect kLeftSide(0, 0, 128, 256);
- const gfx::Rect kTopRight(128, 0, 128, 128);
-
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayBottomRightRect);
- CreateOpaqueQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(), kLeftSide,
- SK_ColorBLACK);
- CreateOpaqueQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(), kTopRight,
- SK_ColorBLACK);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
-
- EXPECT_EQ(1U, content_bounds_.size());
- EXPECT_TRUE(content_bounds_[0].IsEmpty());
-}
-
-TEST_F(UnderlayCastTest, OverlayOccludedContentBounds) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateOpaqueQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayTopLeftRect);
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayRect);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
-
- EXPECT_EQ(1U, content_bounds_.size());
- EXPECT_EQ(kOverlayTopLeftRect, content_bounds_[0]);
-}
-
-TEST_F(UnderlayCastTest, OverlayOccludedUnionContentBounds) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateOpaqueQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayTopLeftRect);
- CreateOpaqueQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayBottomRightRect);
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayRect);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
-
- EXPECT_EQ(1U, content_bounds_.size());
- EXPECT_EQ(kOverlayRect, content_bounds_[0]);
-}
-
-TEST_F(UnderlayCastTest, RoundOverlayContentBounds) {
- // Check rounding behaviour on overlay quads. Be conservative (content
- // potentially visible on boundary).
- const gfx::Rect overlay_rect(1, 1, 8, 8);
- output_surface_->GetOverlayCandidateValidator()->AddExpectedRect(
- gfx::RectF(1.5f, 1.5f, 8, 8));
-
- gfx::Transform transform;
- transform.Translate(0.5f, 0.5f);
-
- std::unique_ptr<RenderPass> pass = CreateRenderPassWithTransform(transform);
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- overlay_rect);
- CreateOpaqueQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- gfx::Rect(0, 0, 10, 10), SK_ColorWHITE);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
-
- EXPECT_EQ(1U, content_bounds_.size());
- EXPECT_EQ(gfx::Rect(0, 0, 11, 11), content_bounds_[0]);
-}
-
-TEST_F(UnderlayCastTest, RoundContentBounds) {
- // Check rounding behaviour on content quads (bounds should be enclosing
- // rect).
- gfx::Rect overlay_rect = kOverlayRect;
- overlay_rect.Inset(0, 0, 1, 1);
- output_surface_->GetOverlayCandidateValidator()->AddExpectedRect(
- gfx::RectF(0.5f, 0.5f, 255, 255));
-
- gfx::Transform transform;
- transform.Translate(0.5f, 0.5f);
-
- std::unique_ptr<RenderPass> pass = CreateRenderPassWithTransform(transform);
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- overlay_rect);
- CreateOpaqueQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- gfx::Rect(0, 0, 255, 255), SK_ColorWHITE);
-
- OverlayCandidateList candidate_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &candidate_list, nullptr, nullptr,
- &damage_rect_, &content_bounds_);
-
- EXPECT_EQ(1U, content_bounds_.size());
- EXPECT_EQ(kOverlayRect, content_bounds_[0]);
-}
-
-OverlayCandidateList BackbufferOverlayList(const RenderPass* root_render_pass) {
- OverlayCandidateList list;
- OverlayCandidate output_surface_plane;
- output_surface_plane.display_rect = gfx::RectF(root_render_pass->output_rect);
- output_surface_plane.use_output_surface_for_resource = true;
- output_surface_plane.overlay_handled = true;
- list.push_back(output_surface_plane);
- return list;
-}
-
-TEST_F(CALayerOverlayTest, AllowNonAxisAlignedTransform) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- pass->shared_quad_state_list.back()
- ->quad_to_target_transform.RotateAboutZAxis(45.f);
-
- gfx::Rect damage_rect;
- CALayerOverlayList ca_layer_list;
- OverlayCandidateList overlay_list(BackbufferOverlayList(pass.get()));
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &overlay_list, &ca_layer_list, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(gfx::Rect(), damage_rect);
- EXPECT_EQ(0U, overlay_list.size());
- EXPECT_EQ(1U, ca_layer_list.size());
- EXPECT_EQ(0U, output_surface_->bind_framebuffer_count());
-}
-
-TEST_F(CALayerOverlayTest, ThreeDTransform) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- pass->shared_quad_state_list.back()
- ->quad_to_target_transform.RotateAboutXAxis(45.f);
-
- gfx::Rect damage_rect;
- CALayerOverlayList ca_layer_list;
- OverlayCandidateList overlay_list(BackbufferOverlayList(pass.get()));
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &overlay_list, &ca_layer_list, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(0U, overlay_list.size());
- EXPECT_EQ(1U, ca_layer_list.size());
- gfx::Transform expected_transform;
- expected_transform.RotateAboutXAxis(45.f);
- gfx::Transform actual_transform(ca_layer_list.back().shared_state->transform);
- EXPECT_EQ(expected_transform.ToString(), actual_transform.ToString());
- EXPECT_EQ(0U, output_surface_->bind_framebuffer_count());
-}
-
-TEST_F(CALayerOverlayTest, AllowContainingClip) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- pass->shared_quad_state_list.back()->is_clipped = true;
- pass->shared_quad_state_list.back()->clip_rect = kOverlayRect;
-
- gfx::Rect damage_rect;
- CALayerOverlayList ca_layer_list;
- OverlayCandidateList overlay_list(BackbufferOverlayList(pass.get()));
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &overlay_list, &ca_layer_list, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(gfx::Rect(), damage_rect);
- EXPECT_EQ(0U, overlay_list.size());
- EXPECT_EQ(1U, ca_layer_list.size());
- EXPECT_EQ(0U, output_surface_->bind_framebuffer_count());
-}
-
-TEST_F(CALayerOverlayTest, NontrivialClip) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- pass->shared_quad_state_list.back()->is_clipped = true;
- pass->shared_quad_state_list.back()->clip_rect = gfx::Rect(64, 64, 128, 128);
-
- gfx::Rect damage_rect;
- CALayerOverlayList ca_layer_list;
- OverlayCandidateList overlay_list(BackbufferOverlayList(pass.get()));
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &overlay_list, &ca_layer_list, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(gfx::Rect(), damage_rect);
- EXPECT_EQ(0U, overlay_list.size());
- EXPECT_EQ(1U, ca_layer_list.size());
- EXPECT_TRUE(ca_layer_list.back().shared_state->is_clipped);
- EXPECT_EQ(gfx::RectF(64, 64, 128, 128),
- ca_layer_list.back().shared_state->clip_rect);
- EXPECT_EQ(0U, output_surface_->bind_framebuffer_count());
-}
-
-TEST_F(CALayerOverlayTest, SkipTransparent) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- pass->shared_quad_state_list.back()->opacity = 0;
-
- gfx::Rect damage_rect;
- CALayerOverlayList ca_layer_list;
- OverlayCandidateList overlay_list(BackbufferOverlayList(pass.get()));
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &overlay_list, &ca_layer_list, nullptr,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(gfx::Rect(), damage_rect);
- EXPECT_EQ(0U, overlay_list.size());
- EXPECT_EQ(0U, ca_layer_list.size());
- EXPECT_EQ(0U, output_surface_->bind_framebuffer_count());
-}
-
-class DCLayerOverlayTest : public OverlayTest<DCLayerValidator>,
- public ::testing::WithParamInterface<bool> {
- void SetUp() override {
- OverlayTest<DCLayerValidator>::SetUp();
- if (GetParam())
- feature_list_.InitAndEnableFeature(
- features::kDirectCompositionNonrootOverlays);
- }
-
- private:
- base::test::ScopedFeatureList feature_list_;
-};
-
-TEST_P(DCLayerOverlayTest, AllowNonAxisAlignedTransform) {
- base::test::ScopedFeatureList feature_list;
- feature_list.InitAndEnableFeature(
- features::kDirectCompositionComplexOverlays);
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateYUVVideoQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- pass->shared_quad_state_list.back()
- ->quad_to_target_transform.RotateAboutZAxis(45.f);
-
- gfx::Rect damage_rect;
- DCLayerOverlayList dc_layer_list;
- OverlayCandidateList overlay_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- damage_rect_ = gfx::Rect(1, 1, 10, 10);
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &overlay_list, nullptr, &dc_layer_list,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(gfx::Rect(), damage_rect);
- EXPECT_EQ(0U, overlay_list.size());
- EXPECT_EQ(1U, dc_layer_list.size());
- EXPECT_EQ(1, dc_layer_list.back().shared_state->z_order);
- EXPECT_EQ(0U, output_surface_->bind_framebuffer_count());
- EXPECT_EQ(gfx::Rect(1, 1, 10, 10), damage_rect_);
-}
-
-TEST_P(DCLayerOverlayTest, AllowRequiredNonAxisAlignedTransform) {
- base::test::ScopedFeatureList feature_list;
- feature_list.InitAndEnableFeature(
- features::kDirectCompositionNonrootOverlays);
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- YUVVideoDrawQuad* yuv_quad = CreateFullscreenCandidateYUVVideoQuad(
- resource_provider_.get(), pass->shared_quad_state_list.back(),
- pass.get());
- yuv_quad->require_overlay = true;
- pass->shared_quad_state_list.back()
- ->quad_to_target_transform.RotateAboutZAxis(45.f);
-
- gfx::Rect damage_rect;
- DCLayerOverlayList dc_layer_list;
- OverlayCandidateList overlay_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- damage_rect_ = gfx::Rect(1, 1, 10, 10);
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &overlay_list, nullptr, &dc_layer_list,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(gfx::Rect(), damage_rect);
- EXPECT_EQ(0U, overlay_list.size());
- ASSERT_EQ(1U, dc_layer_list.size());
- EXPECT_EQ(1, dc_layer_list.back().shared_state->z_order);
- EXPECT_EQ(0U, output_surface_->bind_framebuffer_count());
- EXPECT_EQ(gfx::Rect(1, 1, 10, 10), damage_rect_);
-}
-
-TEST_P(DCLayerOverlayTest, Occluded) {
- base::test::ScopedFeatureList feature_list;
- feature_list.InitAndEnableFeature(features::kDirectCompositionUnderlays);
- {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateOpaqueQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- gfx::Rect(0, 2, 100, 100), SK_ColorWHITE);
- CreateFullscreenCandidateYUVVideoQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
-
- gfx::Rect damage_rect;
- DCLayerOverlayList dc_layer_list;
- OverlayCandidateList overlay_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- damage_rect_ = gfx::Rect(1, 1, 10, 10);
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &overlay_list, nullptr, &dc_layer_list,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(gfx::Rect(), damage_rect);
- EXPECT_EQ(0U, overlay_list.size());
- EXPECT_EQ(1U, dc_layer_list.size());
- EXPECT_EQ(0U, output_surface_->bind_framebuffer_count());
- EXPECT_EQ(-1, dc_layer_list.back().shared_state->z_order);
- // Entire underlay rect must be redrawn.
- EXPECT_EQ(gfx::Rect(0, 0, 256, 256), damage_rect_);
- }
- {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateOpaqueQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- gfx::Rect(2, 2, 100, 100), SK_ColorWHITE);
- CreateFullscreenCandidateYUVVideoQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
-
- gfx::Rect damage_rect;
- DCLayerOverlayList dc_layer_list;
- OverlayCandidateList overlay_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- damage_rect_ = gfx::Rect(1, 1, 10, 10);
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &overlay_list, nullptr, &dc_layer_list,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(gfx::Rect(), damage_rect);
- EXPECT_EQ(0U, overlay_list.size());
- EXPECT_EQ(1U, dc_layer_list.size());
- EXPECT_EQ(0U, output_surface_->bind_framebuffer_count());
- EXPECT_EQ(-1, dc_layer_list.back().shared_state->z_order);
- // The underlay rectangle is the same, so the damage is contained within
- // the combined occluding rects for this and the last frame.
- EXPECT_EQ(gfx::Rect(1, 2, 10, 9), damage_rect_);
- }
-}
-
-TEST_P(DCLayerOverlayTest, DamageRect) {
- for (int i = 0; i < 2; i++) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateYUVVideoQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
-
- gfx::Rect damage_rect;
- DCLayerOverlayList dc_layer_list;
- OverlayCandidateList overlay_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- damage_rect_ = gfx::Rect(1, 1, 10, 10);
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &overlay_list, nullptr, &dc_layer_list,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(gfx::Rect(), damage_rect);
- EXPECT_EQ(0U, overlay_list.size());
- EXPECT_EQ(1U, dc_layer_list.size());
- EXPECT_EQ(0U, output_surface_->bind_framebuffer_count());
- EXPECT_EQ(1, dc_layer_list.back().shared_state->z_order);
- // Damage rect should be unchanged on initial frame because of resize, but
- // should be empty on the second frame because everything was put in a
- // layer.
- if (i == 1)
- EXPECT_TRUE(damage_rect_.IsEmpty());
- else
- EXPECT_EQ(gfx::Rect(1, 1, 10, 10), damage_rect_);
- }
-}
-
-TEST_P(DCLayerOverlayTest, MultiplePassDamageRect) {
- for (int i = 0; i < 2; i++) {
- RenderPassId child_pass_id(5);
- std::unique_ptr<RenderPass> pass1 = CreateRenderPass();
- pass1->id = child_pass_id;
- YUVVideoDrawQuad* yuv_quad = CreateFullscreenCandidateYUVVideoQuad(
- resource_provider_.get(), pass1->shared_quad_state_list.back(),
- pass1.get());
- yuv_quad->require_overlay = true;
- pass1->damage_rect = gfx::Rect();
- pass1->transform_to_root_target.Translate(0, 100);
- pass1->shared_quad_state_list.back()->opacity = 0.9f;
-
- std::unique_ptr<RenderPass> pass2 = CreateRenderPass();
-
- gfx::Rect rect(0, 0, 1, 1);
- RenderPassDrawQuad* render_pass_quad =
- pass2->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- render_pass_quad->SetNew(pass2->shared_quad_state_list.back(), rect, rect,
- child_pass_id, 0, gfx::RectF(), gfx::Size(),
- gfx::Vector2dF(), gfx::PointF(),
- gfx::RectF(0, 0, 1, 1));
- pass2->shared_quad_state_list.back()->quad_to_target_transform =
- pass1->transform_to_root_target;
- pass2->shared_quad_state_list.back()->opacity = 0.8f;
- pass2->damage_rect = gfx::Rect();
-
- gfx::Rect damage_rect;
- DCLayerOverlayList dc_layer_list;
- OverlayCandidateList overlay_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- damage_rect_ = gfx::Rect();
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass1));
- pass_list.push_back(std::move(pass2));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &overlay_list, nullptr, &dc_layer_list,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(gfx::Rect(), damage_rect);
- EXPECT_EQ(0U, overlay_list.size());
- EXPECT_EQ(0U, output_surface_->bind_framebuffer_count());
- if (GetParam()) {
- // With nonroot overlays enabled, the portions of both RenderPasses
- // corresponding to the overlay should always be damaged.
- ASSERT_EQ(1U, dc_layer_list.size());
- EXPECT_EQ(-1, dc_layer_list.back().shared_state->z_order);
- EXPECT_EQ(gfx::Rect(0, 0, 256, 256), pass_list[0]->damage_rect);
- EXPECT_EQ(gfx::Rect(0, 100, 256, 156), damage_rect_);
- gfx::Rect overlay_damage = overlay_processor_->GetAndResetOverlayDamage();
- EXPECT_EQ(gfx::Rect(0, 100, 256, 256), overlay_damage);
-
- EXPECT_EQ(1u, pass_list[0]->quad_list.size());
- EXPECT_EQ(0.9f,
- pass_list[0]->quad_list.back()->shared_quad_state->opacity);
- EXPECT_EQ(2u, pass_list[1]->quad_list.size());
- EXPECT_EQ(0.9f * 0.8f,
- pass_list[1]->quad_list.back()->shared_quad_state->opacity);
- } else {
- // Without nonroot overlays, no overlays should be created.
- EXPECT_EQ(0U, dc_layer_list.size());
- EXPECT_EQ(1u, pass_list[0]->quad_list.size());
- EXPECT_EQ(1u, pass_list[1]->quad_list.size());
- }
- }
-}
-
-TEST_P(DCLayerOverlayTest, ClipRect) {
- base::test::ScopedFeatureList feature_list;
- feature_list.InitAndEnableFeature(features::kDirectCompositionUnderlays);
-
- // Process twice. The second time through the overlay list shouldn't change,
- // which will allow the damage rect to reflect just the changes in that
- // frame.
- for (size_t i = 0; i < 2; ++i) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateOpaqueQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- gfx::Rect(0, 2, 100, 100), SK_ColorWHITE);
- pass->shared_quad_state_list.back()->is_clipped = true;
- pass->shared_quad_state_list.back()->clip_rect = gfx::Rect(0, 3, 100, 100);
- SharedQuadState* shared_state = pass->CreateAndAppendSharedQuadState();
- shared_state->opacity = 1.f;
- CreateFullscreenCandidateYUVVideoQuad(resource_provider_.get(),
- shared_state, pass.get());
- shared_state->is_clipped = true;
- // Clipped rect shouldn't be overlapped by clipped opaque quad rect.
- shared_state->clip_rect = gfx::Rect(0, 0, 100, 3);
-
- DCLayerOverlayList dc_layer_list;
- OverlayCandidateList overlay_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- damage_rect_ = gfx::Rect(1, 1, 10, 10);
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &overlay_list, nullptr, &dc_layer_list,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(0U, overlay_list.size());
- EXPECT_EQ(1U, dc_layer_list.size());
- // Because of clip rects the overlay isn't occluded and shouldn't be an
- // underlay.
- EXPECT_EQ(1, dc_layer_list.back().shared_state->z_order);
- if (i == 1) {
- // The damage rect should only contain contents that aren't in the
- // clipped overlay rect.
- EXPECT_EQ(gfx::Rect(1, 3, 10, 8), damage_rect_);
- }
- }
-}
-
-TEST_P(DCLayerOverlayTest, TransparentOnTop) {
- base::test::ScopedFeatureList feature_list;
-
- // Process twice. The second time through the overlay list shouldn't change,
- // which will allow the damage rect to reflect just the changes in that
- // frame.
- for (size_t i = 0; i < 2; ++i) {
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- CreateFullscreenCandidateYUVVideoQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- pass->shared_quad_state_list.back()->opacity = 0.5f;
-
- DCLayerOverlayList dc_layer_list;
- OverlayCandidateList overlay_list;
- OverlayProcessor::FilterOperationsMap render_pass_filters;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters;
- damage_rect_ = gfx::Rect(1, 1, 10, 10);
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list, render_pass_filters,
- render_pass_background_filters, &overlay_list, nullptr, &dc_layer_list,
- &damage_rect_, &content_bounds_);
- EXPECT_EQ(0U, overlay_list.size());
- EXPECT_EQ(1U, dc_layer_list.size());
- EXPECT_EQ(1, dc_layer_list.back().shared_state->z_order);
- // Quad isn't opaque, so underlying damage must remain the same.
- EXPECT_EQ(gfx::Rect(1, 1, 10, 10), damage_rect_);
- }
-}
-
-INSTANTIATE_TEST_CASE_P(, DCLayerOverlayTest, ::testing::Bool());
-
-class OverlayInfoRendererGL : public viz::GLRenderer {
- public:
- OverlayInfoRendererGL(const viz::RendererSettings* settings,
- OutputSurface* output_surface,
- DisplayResourceProvider* resource_provider)
- : viz::GLRenderer(settings, output_surface, resource_provider, NULL),
- expect_overlays_(false) {}
-
- MOCK_METHOD2(DoDrawQuad,
- void(const DrawQuad* quad, const gfx::QuadF* draw_region));
-
- void SetCurrentFrame(const DrawingFrame& frame) {
- SetCurrentFrameForTesting(frame);
- }
-
- using viz::GLRenderer::BeginDrawingFrame;
-
- void FinishDrawingFrame() override {
- viz::GLRenderer::FinishDrawingFrame();
-
- if (!expect_overlays_) {
- EXPECT_EQ(0U, current_frame()->overlay_list.size());
- return;
- }
-
- ASSERT_EQ(2U, current_frame()->overlay_list.size());
- EXPECT_GE(current_frame()->overlay_list.back().resource_id, 0U);
- }
-
- void set_expect_overlays(bool expect_overlays) {
- expect_overlays_ = expect_overlays;
- }
-
- private:
- bool expect_overlays_;
-};
-
-class MockOverlayScheduler {
- public:
- MOCK_METHOD5(Schedule,
- void(int plane_z_order,
- gfx::OverlayTransform plane_transform,
- unsigned overlay_texture_id,
- const gfx::Rect& display_bounds,
- const gfx::RectF& uv_rect));
-};
-
-class GLRendererWithOverlaysTest : public testing::Test {
- using OutputSurfaceType = OverlayOutputSurface<SingleOverlayValidator>;
-
- protected:
- GLRendererWithOverlaysTest() {
- provider_ = TestContextProvider::Create();
- provider_->BindToCurrentThread();
- output_surface_.reset(new OutputSurfaceType(provider_));
- output_surface_->BindToClient(&output_surface_client_);
- resource_provider_ = FakeResourceProvider::Create<DisplayResourceProvider>(
- provider_.get(), nullptr);
-
- provider_->support()->SetScheduleOverlayPlaneCallback(base::Bind(
- &MockOverlayScheduler::Schedule, base::Unretained(&scheduler_)));
- }
-
- void Init(bool use_validator) {
- if (use_validator)
- output_surface_->SetOverlayCandidateValidator(new SingleOverlayValidator);
-
- renderer_ = std::make_unique<OverlayInfoRendererGL>(
- &settings_, output_surface_.get(), resource_provider_.get());
- renderer_->Initialize();
- renderer_->SetVisible(true);
- }
-
- void DrawFrame(RenderPassList* pass_list, const gfx::Size& viewport_size) {
- renderer_->DrawFrame(pass_list, 1.f, viewport_size);
- }
- void SwapBuffers() {
- renderer_->SwapBuffers(std::vector<ui::LatencyInfo>());
- renderer_->SwapBuffersComplete();
- }
- void SwapBuffersWithoutComplete() {
- renderer_->SwapBuffers(std::vector<ui::LatencyInfo>());
- }
- void SwapBuffersComplete() {
- renderer_->SwapBuffersComplete();
- }
- void ReturnResourceInUseQuery(viz::ResourceId id) {
- DisplayResourceProvider::ScopedReadLockGL lock(resource_provider_.get(),
- id);
- gpu::TextureInUseResponse response;
- response.texture = lock.texture_id();
- response.in_use = false;
- gpu::TextureInUseResponses responses;
- responses.push_back(response);
- renderer_->DidReceiveTextureInUseResponses(responses);
- }
-
- viz::RendererSettings settings_;
- FakeOutputSurfaceClient output_surface_client_;
- std::unique_ptr<OutputSurfaceType> output_surface_;
- std::unique_ptr<DisplayResourceProvider> resource_provider_;
- std::unique_ptr<OverlayInfoRendererGL> renderer_;
- scoped_refptr<TestContextProvider> provider_;
- MockOverlayScheduler scheduler_;
-};
-
-TEST_F(GLRendererWithOverlaysTest, OverlayQuadNotDrawn) {
- bool use_validator = true;
- Init(use_validator);
- renderer_->set_expect_overlays(true);
- output_surface_->GetOverlayCandidateValidator()->AddExpectedRect(
- gfx::RectF(kOverlayBottomRightRect));
-
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
-
- CreateCandidateQuadAt(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get(),
- kOverlayBottomRightRect);
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- // Candidate pass was taken out and extra skipped pass added,
- // so only draw 2 quads.
- EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(2);
- EXPECT_CALL(scheduler_,
- Schedule(0, gfx::OVERLAY_TRANSFORM_NONE, _,
- gfx::Rect(kDisplaySize), gfx::RectF(0, 0, 1, 1)))
- .Times(1);
- EXPECT_CALL(scheduler_, Schedule(1, gfx::OVERLAY_TRANSFORM_NONE, _,
- kOverlayBottomRightRect,
- BoundingRect(kUVTopLeft, kUVBottomRight)))
- .Times(1);
- DrawFrame(&pass_list, kDisplaySize);
- EXPECT_EQ(1U, output_surface_->bind_framebuffer_count());
-
- SwapBuffers();
-
- Mock::VerifyAndClearExpectations(renderer_.get());
- Mock::VerifyAndClearExpectations(&scheduler_);
-}
-
-TEST_F(GLRendererWithOverlaysTest, OccludedQuadInUnderlay) {
- bool use_validator = true;
- Init(use_validator);
- renderer_->set_expect_overlays(true);
-
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
-
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
-
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- // Candidate quad should fail to be overlaid on top because of occlusion.
- // Expect to be replaced with transparent hole quad and placed in underlay.
- EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(3);
- EXPECT_CALL(scheduler_,
- Schedule(0, gfx::OVERLAY_TRANSFORM_NONE, _,
- gfx::Rect(kDisplaySize), gfx::RectF(0, 0, 1, 1)))
- .Times(1);
- EXPECT_CALL(scheduler_,
- Schedule(-1, gfx::OVERLAY_TRANSFORM_NONE, _, kOverlayRect,
- BoundingRect(kUVTopLeft, kUVBottomRight)))
- .Times(1);
- DrawFrame(&pass_list, kDisplaySize);
- EXPECT_EQ(1U, output_surface_->bind_framebuffer_count());
-
- SwapBuffers();
-
- Mock::VerifyAndClearExpectations(renderer_.get());
- Mock::VerifyAndClearExpectations(&scheduler_);
-}
-
-TEST_F(GLRendererWithOverlaysTest, NoValidatorNoOverlay) {
- bool use_validator = false;
- Init(use_validator);
- renderer_->set_expect_overlays(false);
-
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
-
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
-
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- // Should not see the primary surface's overlay.
- output_surface_->set_is_displayed_as_overlay_plane(false);
- EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(3);
- EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
- DrawFrame(&pass_list, kDisplaySize);
- EXPECT_EQ(1U, output_surface_->bind_framebuffer_count());
- SwapBuffers();
- Mock::VerifyAndClearExpectations(renderer_.get());
- Mock::VerifyAndClearExpectations(&scheduler_);
-}
-
-// viz::GLRenderer skips drawing occluded quads when partial swap is enabled.
-TEST_F(GLRendererWithOverlaysTest, OccludedQuadNotDrawnWhenPartialSwapEnabled) {
- provider_->TestContext3d()->set_have_post_sub_buffer(true);
- settings_.partial_swap_enabled = true;
- bool use_validator = true;
- Init(use_validator);
- renderer_->set_expect_overlays(true);
-
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
-
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- output_surface_->set_is_displayed_as_overlay_plane(true);
- EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(0);
- EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(2);
- DrawFrame(&pass_list, kDisplaySize);
- EXPECT_EQ(0U, output_surface_->bind_framebuffer_count());
- SwapBuffers();
- Mock::VerifyAndClearExpectations(renderer_.get());
- Mock::VerifyAndClearExpectations(&scheduler_);
-}
-
-// viz::GLRenderer skips drawing occluded quads when empty swap is enabled.
-TEST_F(GLRendererWithOverlaysTest, OccludedQuadNotDrawnWhenEmptySwapAllowed) {
- provider_->TestContext3d()->set_have_commit_overlay_planes(true);
- bool use_validator = true;
- Init(use_validator);
- renderer_->set_expect_overlays(true);
-
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
-
- CreateFullscreenCandidateQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(),
- pass.get());
-
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
- CreateFullscreenOpaqueQuad(resource_provider_.get(),
- pass->shared_quad_state_list.back(), pass.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- output_surface_->set_is_displayed_as_overlay_plane(true);
- EXPECT_CALL(*renderer_, DoDrawQuad(_, _)).Times(0);
- EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(2);
- DrawFrame(&pass_list, kDisplaySize);
- EXPECT_EQ(0U, output_surface_->bind_framebuffer_count());
- SwapBuffers();
- Mock::VerifyAndClearExpectations(renderer_.get());
- Mock::VerifyAndClearExpectations(&scheduler_);
-}
-
-TEST_F(GLRendererWithOverlaysTest, ResourcesExportedAndReturnedWithDelay) {
- bool use_validator = true;
- Init(use_validator);
- renderer_->set_expect_overlays(true);
-
- viz::ResourceId resource1 =
- CreateResource(resource_provider_.get(), gfx::Size(32, 32), true);
- viz::ResourceId resource2 =
- CreateResource(resource_provider_.get(), gfx::Size(32, 32), true);
- viz::ResourceId resource3 =
- CreateResource(resource_provider_.get(), gfx::Size(32, 32), true);
-
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- DirectRenderer::DrawingFrame frame1;
- frame1.render_passes_in_draw_order = &pass_list;
- frame1.overlay_list.resize(2);
- frame1.overlay_list.front().use_output_surface_for_resource = true;
- OverlayCandidate& overlay1 = frame1.overlay_list.back();
- overlay1.resource_id = resource1;
- overlay1.plane_z_order = 1;
-
- DirectRenderer::DrawingFrame frame2;
- frame2.render_passes_in_draw_order = &pass_list;
- frame2.overlay_list.resize(2);
- frame2.overlay_list.front().use_output_surface_for_resource = true;
- OverlayCandidate& overlay2 = frame2.overlay_list.back();
- overlay2.resource_id = resource2;
- overlay2.plane_z_order = 1;
-
- DirectRenderer::DrawingFrame frame3;
- frame3.render_passes_in_draw_order = &pass_list;
- frame3.overlay_list.resize(2);
- frame3.overlay_list.front().use_output_surface_for_resource = true;
- OverlayCandidate& overlay3 = frame3.overlay_list.back();
- overlay3.resource_id = resource3;
- overlay3.plane_z_order = 1;
-
- EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(2);
- renderer_->SetCurrentFrame(frame1);
- renderer_->BeginDrawingFrame();
- renderer_->FinishDrawingFrame();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- EXPECT_FALSE(resource_provider_->InUseByConsumer(resource2));
- SwapBuffersWithoutComplete();
- Mock::VerifyAndClearExpectations(&scheduler_);
-
- EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(2);
- renderer_->SetCurrentFrame(frame2);
- renderer_->BeginDrawingFrame();
- renderer_->FinishDrawingFrame();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
- SwapBuffersComplete();
- SwapBuffersWithoutComplete();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
- Mock::VerifyAndClearExpectations(&scheduler_);
-
- EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(2);
- renderer_->SetCurrentFrame(frame3);
- renderer_->BeginDrawingFrame();
- renderer_->FinishDrawingFrame();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource3));
- SwapBuffersComplete();
- SwapBuffersWithoutComplete();
- EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource3));
- Mock::VerifyAndClearExpectations(&scheduler_);
-
- // No overlays, release the resource.
- EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
- DirectRenderer::DrawingFrame frame_no_overlays;
- frame_no_overlays.render_passes_in_draw_order = &pass_list;
- renderer_->set_expect_overlays(false);
- renderer_->SetCurrentFrame(frame_no_overlays);
- renderer_->BeginDrawingFrame();
- renderer_->FinishDrawingFrame();
- EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource3));
- SwapBuffersComplete();
- SwapBuffersWithoutComplete();
- EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
- EXPECT_FALSE(resource_provider_->InUseByConsumer(resource2));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource3));
- Mock::VerifyAndClearExpectations(&scheduler_);
-
- // Use the same buffer twice.
- renderer_->set_expect_overlays(true);
- EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(2);
- renderer_->SetCurrentFrame(frame1);
- renderer_->BeginDrawingFrame();
- renderer_->FinishDrawingFrame();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- SwapBuffersComplete();
- SwapBuffersWithoutComplete();
- Mock::VerifyAndClearExpectations(&scheduler_);
-
- EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(2);
- renderer_->SetCurrentFrame(frame1);
- renderer_->BeginDrawingFrame();
- renderer_->FinishDrawingFrame();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- SwapBuffersComplete();
- SwapBuffersWithoutComplete();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- Mock::VerifyAndClearExpectations(&scheduler_);
-
- EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
- renderer_->set_expect_overlays(false);
- renderer_->SetCurrentFrame(frame_no_overlays);
- renderer_->BeginDrawingFrame();
- renderer_->FinishDrawingFrame();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- SwapBuffersComplete();
- SwapBuffersWithoutComplete();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- Mock::VerifyAndClearExpectations(&scheduler_);
-
- EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(0);
- renderer_->set_expect_overlays(false);
- renderer_->SetCurrentFrame(frame_no_overlays);
- renderer_->BeginDrawingFrame();
- renderer_->FinishDrawingFrame();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- SwapBuffersComplete();
- SwapBuffersWithoutComplete();
- EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
- Mock::VerifyAndClearExpectations(&scheduler_);
-}
-
-TEST_F(GLRendererWithOverlaysTest, ResourcesExportedAndReturnedAfterGpuQuery) {
- bool use_validator = true;
- settings_.release_overlay_resources_after_gpu_query = true;
- Init(use_validator);
- renderer_->set_expect_overlays(true);
-
- viz::ResourceId resource1 =
- CreateResource(resource_provider_.get(), gfx::Size(32, 32), true);
- viz::ResourceId resource2 =
- CreateResource(resource_provider_.get(), gfx::Size(32, 32), true);
- viz::ResourceId resource3 =
- CreateResource(resource_provider_.get(), gfx::Size(32, 32), true);
-
- std::unique_ptr<RenderPass> pass = CreateRenderPass();
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- DirectRenderer::DrawingFrame frame1;
- frame1.render_passes_in_draw_order = &pass_list;
- frame1.overlay_list.resize(2);
- frame1.overlay_list.front().use_output_surface_for_resource = true;
- OverlayCandidate& overlay1 = frame1.overlay_list.back();
- overlay1.resource_id = resource1;
- overlay1.plane_z_order = 1;
-
- DirectRenderer::DrawingFrame frame2;
- frame2.render_passes_in_draw_order = &pass_list;
- frame2.overlay_list.resize(2);
- frame2.overlay_list.front().use_output_surface_for_resource = true;
- OverlayCandidate& overlay2 = frame2.overlay_list.back();
- overlay2.resource_id = resource2;
- overlay2.plane_z_order = 1;
-
- DirectRenderer::DrawingFrame frame3;
- frame3.render_passes_in_draw_order = &pass_list;
- frame3.overlay_list.resize(2);
- frame3.overlay_list.front().use_output_surface_for_resource = true;
- OverlayCandidate& overlay3 = frame3.overlay_list.back();
- overlay3.resource_id = resource3;
- overlay3.plane_z_order = 1;
-
- // First frame, with no swap completion.
- EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(2);
- renderer_->SetCurrentFrame(frame1);
- renderer_->BeginDrawingFrame();
- renderer_->FinishDrawingFrame();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- SwapBuffersWithoutComplete();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- Mock::VerifyAndClearExpectations(&scheduler_);
-
- // Second frame, with no swap completion.
- EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(2);
- renderer_->SetCurrentFrame(frame2);
- renderer_->BeginDrawingFrame();
- renderer_->FinishDrawingFrame();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
- SwapBuffersWithoutComplete();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
- Mock::VerifyAndClearExpectations(&scheduler_);
-
- // Third frame, still with no swap completion (where the resources would
- // otherwise have been released).
- EXPECT_CALL(scheduler_, Schedule(_, _, _, _, _)).Times(2);
- renderer_->SetCurrentFrame(frame3);
- renderer_->BeginDrawingFrame();
- renderer_->FinishDrawingFrame();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource3));
- SwapBuffersWithoutComplete();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource3));
- Mock::VerifyAndClearExpectations(&scheduler_);
-
- // This completion corresponds to the first frame.
- SwapBuffersComplete();
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource1));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource3));
-
- // This completion corresponds to the second frame. The first resource is no
- // longer in use.
- ReturnResourceInUseQuery(resource1);
- SwapBuffersComplete();
- EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource3));
-
- // This completion corresponds to the third frame.
- SwapBuffersComplete();
- EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource2));
- EXPECT_TRUE(resource_provider_->InUseByConsumer(resource3));
-
- ReturnResourceInUseQuery(resource2);
- ReturnResourceInUseQuery(resource3);
- EXPECT_FALSE(resource_provider_->InUseByConsumer(resource1));
- EXPECT_FALSE(resource_provider_->InUseByConsumer(resource2));
- EXPECT_FALSE(resource_provider_->InUseByConsumer(resource3));
-}
-
-class CALayerOverlayRPDQTest : public CALayerOverlayTest {
- protected:
- void SetUp() override {
- CALayerOverlayTest::SetUp();
- pass_list_.push_back(CreateRenderPass());
- pass_ = pass_list_.back().get();
- quad_ = pass_->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- render_pass_id_ = 3;
- }
-
- void ProcessForOverlays() {
- gfx::Rect damage_rect;
- overlay_list_ = BackbufferOverlayList(pass_);
- overlay_processor_->ProcessForOverlays(
- resource_provider_.get(), &pass_list_, render_pass_filters_,
- render_pass_background_filters_, &overlay_list_, &ca_layer_list_,
- nullptr, &damage_rect_, &content_bounds_);
- }
- RenderPassList pass_list_;
- RenderPass* pass_;
- RenderPassDrawQuad* quad_;
- int render_pass_id_;
- FilterOperations filters_;
- FilterOperations background_filters_;
- OverlayProcessor::FilterOperationsMap render_pass_filters_;
- OverlayProcessor::FilterOperationsMap render_pass_background_filters_;
- CALayerOverlayList ca_layer_list_;
- OverlayCandidateList overlay_list_;
-};
-
-TEST_F(CALayerOverlayRPDQTest, RenderPassDrawQuadNoFilters) {
- quad_->SetNew(pass_->shared_quad_state_list.back(), kOverlayRect,
- kOverlayRect, render_pass_id_, 0, gfx::RectF(), gfx::Size(),
- gfx::Vector2dF(1, 1), gfx::PointF(), gfx::RectF());
- ProcessForOverlays();
-
- EXPECT_EQ(1U, ca_layer_list_.size());
-}
-
-TEST_F(CALayerOverlayRPDQTest, RenderPassDrawQuadAllValidFilters) {
- filters_.Append(FilterOperation::CreateGrayscaleFilter(0.1f));
- filters_.Append(FilterOperation::CreateSepiaFilter(0.2f));
- filters_.Append(FilterOperation::CreateSaturateFilter(0.3f));
- filters_.Append(FilterOperation::CreateHueRotateFilter(0.4f));
- filters_.Append(FilterOperation::CreateInvertFilter(0.5f));
- filters_.Append(FilterOperation::CreateBrightnessFilter(0.6f));
- filters_.Append(FilterOperation::CreateContrastFilter(0.7f));
- filters_.Append(FilterOperation::CreateOpacityFilter(0.8f));
- filters_.Append(FilterOperation::CreateBlurFilter(0.9f));
- filters_.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(10, 20),
- 1.0f, SK_ColorGREEN));
- render_pass_filters_[render_pass_id_] = &filters_;
- quad_->SetNew(pass_->shared_quad_state_list.back(), kOverlayRect,
- kOverlayRect, render_pass_id_, 0, gfx::RectF(), gfx::Size(),
- gfx::Vector2dF(1, 1), gfx::PointF(), gfx::RectF());
- ProcessForOverlays();
-
- EXPECT_EQ(1U, ca_layer_list_.size());
-}
-
-TEST_F(CALayerOverlayRPDQTest, RenderPassDrawQuadOpacityFilterScale) {
- filters_.Append(FilterOperation::CreateOpacityFilter(0.8f));
- render_pass_filters_[render_pass_id_] = &filters_;
- quad_->SetNew(pass_->shared_quad_state_list.back(), kOverlayRect,
- kOverlayRect, render_pass_id_, 0, gfx::RectF(), gfx::Size(),
- gfx::Vector2dF(1, 2), gfx::PointF(), gfx::RectF());
- ProcessForOverlays();
- EXPECT_EQ(1U, ca_layer_list_.size());
-}
-
-TEST_F(CALayerOverlayRPDQTest, RenderPassDrawQuadBlurFilterScale) {
- filters_.Append(FilterOperation::CreateBlurFilter(0.8f));
- render_pass_filters_[render_pass_id_] = &filters_;
- quad_->SetNew(pass_->shared_quad_state_list.back(), kOverlayRect,
- kOverlayRect, render_pass_id_, 0, gfx::RectF(), gfx::Size(),
- gfx::Vector2dF(1, 2), gfx::PointF(), gfx::RectF());
- ProcessForOverlays();
- EXPECT_EQ(1U, ca_layer_list_.size());
-}
-
-TEST_F(CALayerOverlayRPDQTest, RenderPassDrawQuadDropShadowFilterScale) {
- filters_.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(10, 20),
- 1.0f, SK_ColorGREEN));
- render_pass_filters_[render_pass_id_] = &filters_;
- quad_->SetNew(pass_->shared_quad_state_list.back(), kOverlayRect,
- kOverlayRect, render_pass_id_, 0, gfx::RectF(), gfx::Size(),
- gfx::Vector2dF(1, 2), gfx::PointF(), gfx::RectF());
- ProcessForOverlays();
- EXPECT_EQ(1U, ca_layer_list_.size());
-}
-
-TEST_F(CALayerOverlayRPDQTest, RenderPassDrawQuadBackgroundFilter) {
- background_filters_.Append(FilterOperation::CreateGrayscaleFilter(0.1f));
- render_pass_background_filters_[render_pass_id_] = &background_filters_;
- quad_->SetNew(pass_->shared_quad_state_list.back(), kOverlayRect,
- kOverlayRect, render_pass_id_, 0, gfx::RectF(), gfx::Size(),
- gfx::Vector2dF(1, 1), gfx::PointF(), gfx::RectF());
- ProcessForOverlays();
- EXPECT_EQ(0U, ca_layer_list_.size());
-}
-
-TEST_F(CALayerOverlayRPDQTest, RenderPassDrawQuadMask) {
- quad_->SetNew(pass_->shared_quad_state_list.back(), kOverlayRect,
- kOverlayRect, render_pass_id_, 2, gfx::RectF(), gfx::Size(),
- gfx::Vector2dF(1, 1), gfx::PointF(), gfx::RectF());
- ProcessForOverlays();
- EXPECT_EQ(1U, ca_layer_list_.size());
-}
-
-TEST_F(CALayerOverlayRPDQTest, RenderPassDrawQuadUnsupportedFilter) {
- filters_.Append(FilterOperation::CreateZoomFilter(0.9f, 1));
- render_pass_filters_[render_pass_id_] = &filters_;
- quad_->SetNew(pass_->shared_quad_state_list.back(), kOverlayRect,
- kOverlayRect, render_pass_id_, 0, gfx::RectF(), gfx::Size(),
- gfx::Vector2dF(1, 1), gfx::PointF(), gfx::RectF());
- ProcessForOverlays();
- EXPECT_EQ(0U, ca_layer_list_.size());
-}
-
-TEST_F(CALayerOverlayRPDQTest, TooManyRenderPassDrawQuads) {
- filters_.Append(FilterOperation::CreateBlurFilter(0.8f));
- int count = 35;
-
- for (int i = 0; i < count; ++i) {
- RenderPassDrawQuad* quad =
- pass_->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- quad->SetNew(pass_->shared_quad_state_list.back(), kOverlayRect,
- kOverlayRect, render_pass_id_, 2, gfx::RectF(), gfx::Size(),
- gfx::Vector2dF(1, 1), gfx::PointF(), gfx::RectF());
- }
-
- ProcessForOverlays();
- EXPECT_EQ(0U, ca_layer_list_.size());
-}
-
-} // namespace
-} // namespace cc
diff --git a/chromium/cc/output/renderer_pixeltest.cc b/chromium/cc/output/renderer_pixeltest.cc
deleted file mode 100644
index 862bc2b6ae3..00000000000
--- a/chromium/cc/output/renderer_pixeltest.cc
+++ /dev/null
@@ -1,3612 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <stddef.h>
-#include <stdint.h>
-#include <memory>
-
-#include "base/memory/aligned_memory.h"
-#include "base/message_loop/message_loop.h"
-#include "cc/base/math_util.h"
-#include "cc/paint/paint_flags.h"
-#include "cc/paint/skia_paint_canvas.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/picture_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
-#include "cc/resources/video_resource_updater.h"
-#include "cc/test/fake_raster_source.h"
-#include "cc/test/fake_recording_source.h"
-#include "cc/test/pixel_test.h"
-#include "components/viz/service/display/gl_renderer.h"
-#include "gpu/command_buffer/client/gles2_interface.h"
-#include "media/base/video_frame.h"
-#include "third_party/skia/include/core/SkColorPriv.h"
-#include "third_party/skia/include/core/SkImageFilter.h"
-#include "third_party/skia/include/core/SkMatrix.h"
-#include "third_party/skia/include/core/SkRefCnt.h"
-#include "third_party/skia/include/core/SkSurface.h"
-#include "third_party/skia/include/effects/SkColorFilterImageFilter.h"
-#include "third_party/skia/include/effects/SkColorMatrixFilter.h"
-#include "ui/gfx/color_transform.h"
-#include "ui/gfx/geometry/rect_conversions.h"
-#include "ui/gfx/test/icc_profiles.h"
-
-using gpu::gles2::GLES2Interface;
-using viz::SharedQuadState;
-
-namespace cc {
-namespace {
-
-#if !defined(OS_ANDROID)
-std::unique_ptr<RenderPass> CreateTestRootRenderPass(int id,
- const gfx::Rect& rect) {
- std::unique_ptr<RenderPass> pass = RenderPass::Create();
- const gfx::Rect output_rect = rect;
- const gfx::Rect damage_rect = rect;
- const gfx::Transform transform_to_root_target;
- pass->SetNew(id, output_rect, damage_rect, transform_to_root_target);
- return pass;
-}
-
-std::unique_ptr<RenderPass> CreateTestRenderPass(
- int id,
- const gfx::Rect& rect,
- const gfx::Transform& transform_to_root_target) {
- std::unique_ptr<RenderPass> pass = RenderPass::Create();
- const gfx::Rect output_rect = rect;
- const gfx::Rect damage_rect = rect;
- pass->SetNew(id, output_rect, damage_rect, transform_to_root_target);
- return pass;
-}
-
-SharedQuadState* CreateTestSharedQuadState(
- gfx::Transform quad_to_target_transform,
- const gfx::Rect& rect,
- RenderPass* render_pass) {
- const gfx::Rect layer_rect = rect;
- const gfx::Rect visible_layer_rect = rect;
- const gfx::Rect clip_rect = rect;
- const bool is_clipped = false;
- const float opacity = 1.0f;
- const SkBlendMode blend_mode = SkBlendMode::kSrcOver;
- int sorting_context_id = 0;
- SharedQuadState* shared_state = render_pass->CreateAndAppendSharedQuadState();
- shared_state->SetAll(quad_to_target_transform, layer_rect, visible_layer_rect,
- clip_rect, is_clipped, opacity, blend_mode,
- sorting_context_id);
- return shared_state;
-}
-
-SharedQuadState* CreateTestSharedQuadStateClipped(
- gfx::Transform quad_to_target_transform,
- const gfx::Rect& rect,
- const gfx::Rect& clip_rect,
- RenderPass* render_pass) {
- const gfx::Rect layer_rect = rect;
- const gfx::Rect visible_layer_rect = clip_rect;
- const bool is_clipped = true;
- const float opacity = 1.0f;
- const SkBlendMode blend_mode = SkBlendMode::kSrcOver;
- int sorting_context_id = 0;
- SharedQuadState* shared_state = render_pass->CreateAndAppendSharedQuadState();
- shared_state->SetAll(quad_to_target_transform, layer_rect, visible_layer_rect,
- clip_rect, is_clipped, opacity, blend_mode,
- sorting_context_id);
- return shared_state;
-}
-
-void CreateTestRenderPassDrawQuad(const SharedQuadState* shared_state,
- const gfx::Rect& rect,
- int pass_id,
- RenderPass* render_pass) {
- RenderPassDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- quad->SetNew(shared_state, rect, rect, pass_id,
- 0, // mask_resource_id
- gfx::RectF(), // mask_uv_rect
- gfx::Size(), // mask_texture_size
- gfx::Vector2dF(), // filters scale
- gfx::PointF(), // filter origin
- gfx::RectF(rect)); // tex_coord_rect
-}
-
-void CreateTestTwoColoredTextureDrawQuad(const gfx::Rect& rect,
- SkColor texel_color,
- SkColor texel_stripe_color,
- SkColor background_color,
- bool premultiplied_alpha,
- const SharedQuadState* shared_state,
- ResourceProvider* resource_provider,
- RenderPass* render_pass) {
- SkPMColor pixel_color = premultiplied_alpha
- ? SkPreMultiplyColor(texel_color)
- : SkPackARGB32NoCheck(SkColorGetA(texel_color),
- SkColorGetR(texel_color),
- SkColorGetG(texel_color),
- SkColorGetB(texel_color));
- SkPMColor pixel_stripe_color =
- premultiplied_alpha
- ? SkPreMultiplyColor(texel_stripe_color)
- : SkPackARGB32NoCheck(SkColorGetA(texel_stripe_color),
- SkColorGetR(texel_stripe_color),
- SkColorGetG(texel_stripe_color),
- SkColorGetB(texel_stripe_color));
- std::vector<uint32_t> pixels(rect.size().GetArea(), pixel_color);
- for (int i = rect.height() / 4; i < (rect.height() * 3 / 4); ++i) {
- for (int k = rect.width() / 4; k < (rect.width() * 3 / 4); ++k) {
- pixels[i * rect.width() + k] = pixel_stripe_color;
- }
- }
- viz::ResourceId resource = resource_provider->CreateResource(
- rect.size(), ResourceProvider::TEXTURE_HINT_IMMUTABLE, viz::RGBA_8888,
- gfx::ColorSpace());
- resource_provider->CopyToResource(
- resource, reinterpret_cast<uint8_t*>(&pixels.front()), rect.size());
-
- bool needs_blending = true;
- float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f};
- const gfx::PointF uv_top_left(0.0f, 0.0f);
- const gfx::PointF uv_bottom_right(1.0f, 1.0f);
- const bool flipped = false;
- const bool nearest_neighbor = false;
- TextureDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
- quad->SetNew(shared_state, rect, rect, needs_blending, resource,
- premultiplied_alpha, uv_top_left, uv_bottom_right,
- background_color, vertex_opacity, flipped, nearest_neighbor,
- false);
-}
-
-void CreateTestTextureDrawQuad(const gfx::Rect& rect,
- SkColor texel_color,
- float vertex_opacity[4],
- SkColor background_color,
- bool premultiplied_alpha,
- const SharedQuadState* shared_state,
- ResourceProvider* resource_provider,
- RenderPass* render_pass) {
- SkPMColor pixel_color = premultiplied_alpha ?
- SkPreMultiplyColor(texel_color) :
- SkPackARGB32NoCheck(SkColorGetA(texel_color),
- SkColorGetR(texel_color),
- SkColorGetG(texel_color),
- SkColorGetB(texel_color));
- size_t num_pixels = static_cast<size_t>(rect.width()) * rect.height();
- std::vector<uint32_t> pixels(num_pixels, pixel_color);
-
- viz::ResourceId resource = resource_provider->CreateResource(
- rect.size(), ResourceProvider::TEXTURE_HINT_IMMUTABLE, viz::RGBA_8888,
- gfx::ColorSpace());
- resource_provider->CopyToResource(
- resource, reinterpret_cast<uint8_t*>(&pixels.front()), rect.size());
-
- bool needs_blending = true;
- const gfx::PointF uv_top_left(0.0f, 0.0f);
- const gfx::PointF uv_bottom_right(1.0f, 1.0f);
- const bool flipped = false;
- const bool nearest_neighbor = false;
- TextureDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
- quad->SetNew(shared_state, rect, rect, needs_blending, resource,
- premultiplied_alpha, uv_top_left, uv_bottom_right,
- background_color, vertex_opacity, flipped, nearest_neighbor,
- false);
-}
-
-void CreateTestTextureDrawQuad(const gfx::Rect& rect,
- SkColor texel_color,
- SkColor background_color,
- bool premultiplied_alpha,
- const SharedQuadState* shared_state,
- ResourceProvider* resource_provider,
- RenderPass* render_pass) {
- float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f};
- CreateTestTextureDrawQuad(rect, texel_color, vertex_opacity, background_color,
- premultiplied_alpha, shared_state,
- resource_provider, render_pass);
-}
-
-void CreateTestYUVVideoDrawQuad_FromVideoFrame(
- const SharedQuadState* shared_state,
- scoped_refptr<media::VideoFrame> video_frame,
- uint8_t alpha_value,
- const gfx::RectF& tex_coord_rect,
- RenderPass* render_pass,
- VideoResourceUpdater* video_resource_updater,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- ResourceProvider* resource_provider) {
- const bool with_alpha = (video_frame->format() == media::PIXEL_FORMAT_YV12A);
- YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::REC_601;
- int video_frame_color_space;
- if (video_frame->metadata()->GetInteger(
- media::VideoFrameMetadata::COLOR_SPACE, &video_frame_color_space) &&
- video_frame_color_space == media::COLOR_SPACE_JPEG) {
- color_space = YUVVideoDrawQuad::JPEG;
- }
-
- gfx::ColorSpace video_color_space = video_frame->ColorSpace();
-
- bool needs_blending = true;
-
- if (with_alpha) {
- memset(video_frame->data(media::VideoFrame::kAPlane), alpha_value,
- video_frame->stride(media::VideoFrame::kAPlane) *
- video_frame->rows(media::VideoFrame::kAPlane));
- }
-
- VideoFrameExternalResources resources =
- video_resource_updater->CreateExternalResourcesFromVideoFrame(
- video_frame);
-
- EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type);
- EXPECT_EQ(media::VideoFrame::NumPlanes(video_frame->format()),
- resources.mailboxes.size());
- EXPECT_EQ(media::VideoFrame::NumPlanes(video_frame->format()),
- resources.release_callbacks.size());
-
- viz::ResourceId y_resource =
- resource_provider->CreateResourceFromTextureMailbox(
- resources.mailboxes[media::VideoFrame::kYPlane],
- SingleReleaseCallbackImpl::Create(
- resources.release_callbacks[media::VideoFrame::kYPlane]));
- viz::ResourceId u_resource =
- resource_provider->CreateResourceFromTextureMailbox(
- resources.mailboxes[media::VideoFrame::kUPlane],
- SingleReleaseCallbackImpl::Create(
- resources.release_callbacks[media::VideoFrame::kUPlane]));
- viz::ResourceId v_resource =
- resource_provider->CreateResourceFromTextureMailbox(
- resources.mailboxes[media::VideoFrame::kVPlane],
- SingleReleaseCallbackImpl::Create(
- resources.release_callbacks[media::VideoFrame::kVPlane]));
- viz::ResourceId a_resource = 0;
- if (with_alpha) {
- a_resource = resource_provider->CreateResourceFromTextureMailbox(
- resources.mailboxes[media::VideoFrame::kAPlane],
- SingleReleaseCallbackImpl::Create(
- resources.release_callbacks[media::VideoFrame::kAPlane]));
- }
-
- const gfx::Size ya_tex_size = video_frame->coded_size();
- const gfx::Size uv_tex_size = media::VideoFrame::PlaneSize(
- video_frame->format(), media::VideoFrame::kUPlane,
- video_frame->coded_size());
- DCHECK(uv_tex_size == media::VideoFrame::PlaneSize(
- video_frame->format(), media::VideoFrame::kVPlane,
- video_frame->coded_size()));
- if (with_alpha) {
- DCHECK(ya_tex_size == media::VideoFrame::PlaneSize(
- video_frame->format(), media::VideoFrame::kAPlane,
- video_frame->coded_size()));
- }
-
- gfx::RectF ya_tex_coord_rect(tex_coord_rect.x() * ya_tex_size.width(),
- tex_coord_rect.y() * ya_tex_size.height(),
- tex_coord_rect.width() * ya_tex_size.width(),
- tex_coord_rect.height() * ya_tex_size.height());
- gfx::RectF uv_tex_coord_rect(tex_coord_rect.x() * uv_tex_size.width(),
- tex_coord_rect.y() * uv_tex_size.height(),
- tex_coord_rect.width() * uv_tex_size.width(),
- tex_coord_rect.height() * uv_tex_size.height());
-
- YUVVideoDrawQuad* yuv_quad =
- render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>();
- uint32_t bits_per_channel = 8;
- if (video_frame->format() == media::PIXEL_FORMAT_YUV420P10 ||
- video_frame->format() == media::PIXEL_FORMAT_YUV422P10 ||
- video_frame->format() == media::PIXEL_FORMAT_YUV444P10) {
- bits_per_channel = 10;
- }
-
- yuv_quad->SetNew(shared_state, rect, visible_rect, needs_blending,
- ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size,
- uv_tex_size, y_resource, u_resource, v_resource, a_resource,
- color_space, video_color_space, 0.0f, 1.0f,
- bits_per_channel);
-}
-
-void CreateTestY16TextureDrawQuad_FromVideoFrame(
- const SharedQuadState* shared_state,
- scoped_refptr<media::VideoFrame> video_frame,
- const gfx::RectF& tex_coord_rect,
- RenderPass* render_pass,
- VideoResourceUpdater* video_resource_updater,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- ResourceProvider* resource_provider) {
- VideoFrameExternalResources resources =
- video_resource_updater->CreateExternalResourcesFromVideoFrame(
- video_frame);
-
- EXPECT_EQ(VideoFrameExternalResources::RGBA_RESOURCE, resources.type);
- EXPECT_EQ(1u, resources.mailboxes.size());
- EXPECT_EQ(1u, resources.release_callbacks.size());
-
- viz::ResourceId y_resource =
- resource_provider->CreateResourceFromTextureMailbox(
- resources.mailboxes[0],
- SingleReleaseCallbackImpl::Create(resources.release_callbacks[0]));
-
- TextureDrawQuad* quad =
- render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
- bool needs_blending = true;
- float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f};
- quad->SetNew(shared_state, rect, rect, needs_blending, y_resource, false,
- tex_coord_rect.origin(), tex_coord_rect.bottom_right(),
- SK_ColorBLACK, vertex_opacity, false, false, false);
-}
-
-// Upshift video frame to 10 bit.
-scoped_refptr<media::VideoFrame> CreateHighbitVideoFrame(
- media::VideoFrame* video_frame) {
- media::VideoPixelFormat format;
- switch (video_frame->format()) {
- case media::PIXEL_FORMAT_I420:
- case media::PIXEL_FORMAT_YV12:
- format = media::PIXEL_FORMAT_YUV420P10;
- break;
- case media::PIXEL_FORMAT_YV16:
- format = media::PIXEL_FORMAT_YUV422P10;
- break;
- case media::PIXEL_FORMAT_YV24:
- format = media::PIXEL_FORMAT_YUV444P10;
- break;
-
- default:
- NOTREACHED();
- return nullptr;
- }
- scoped_refptr<media::VideoFrame> ret = media::VideoFrame::CreateFrame(
- format, video_frame->coded_size(), video_frame->visible_rect(),
- video_frame->natural_size(), video_frame->timestamp());
-
- // Copy all metadata.
- ret->metadata()->MergeMetadataFrom(video_frame->metadata());
-
- for (int plane = media::VideoFrame::kYPlane;
- plane <= media::VideoFrame::kVPlane; ++plane) {
- int width = video_frame->row_bytes(plane);
- const uint8_t* src = video_frame->data(plane);
- uint16_t* dst = reinterpret_cast<uint16_t*>(ret->data(plane));
- for (int row = 0; row < video_frame->rows(plane); row++) {
- for (int x = 0; x < width; x++) {
- // Replicate the top bits into the lower bits, this way
- // 0xFF becomes 0x3FF.
- dst[x] = (src[x] << 2) | (src[x] >> 6);
- }
- src += video_frame->stride(plane);
- dst += ret->stride(plane) / 2;
- }
- }
- return ret;
-}
-
-void CreateTestYUVVideoDrawQuad_Striped(
- const SharedQuadState* shared_state,
- media::VideoPixelFormat format,
- bool is_transparent,
- bool highbit,
- const gfx::RectF& tex_coord_rect,
- RenderPass* render_pass,
- VideoResourceUpdater* video_resource_updater,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- ResourceProvider* resource_provider) {
- scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame(
- format, rect.size(), rect, rect.size(), base::TimeDelta());
-
- // YUV values representing a striped pattern, for validating texture
- // coordinates for sampling.
- uint8_t y_value = 0;
- uint8_t u_value = 0;
- uint8_t v_value = 0;
- for (int i = 0; i < video_frame->rows(media::VideoFrame::kYPlane); ++i) {
- uint8_t* y_row = video_frame->data(media::VideoFrame::kYPlane) +
- video_frame->stride(media::VideoFrame::kYPlane) * i;
- for (int j = 0; j < video_frame->row_bytes(media::VideoFrame::kYPlane);
- ++j) {
- y_row[j] = (y_value += 1);
- }
- }
- for (int i = 0; i < video_frame->rows(media::VideoFrame::kUPlane); ++i) {
- uint8_t* u_row = video_frame->data(media::VideoFrame::kUPlane) +
- video_frame->stride(media::VideoFrame::kUPlane) * i;
- uint8_t* v_row = video_frame->data(media::VideoFrame::kVPlane) +
- video_frame->stride(media::VideoFrame::kVPlane) * i;
- for (int j = 0; j < video_frame->row_bytes(media::VideoFrame::kUPlane);
- ++j) {
- u_row[j] = (u_value += 3);
- v_row[j] = (v_value += 5);
- }
- }
- uint8_t alpha_value = is_transparent ? 0 : 128;
-
- if (highbit)
- video_frame = CreateHighbitVideoFrame(video_frame.get());
-
- CreateTestYUVVideoDrawQuad_FromVideoFrame(
- shared_state, video_frame, alpha_value, tex_coord_rect, render_pass,
- video_resource_updater, rect, visible_rect, resource_provider);
-}
-
-// Creates a video frame of size background_size filled with yuv_background,
-// and then draws a foreground rectangle in a different color on top of
-// that. The foreground rectangle must have coordinates that are divisible
-// by 2 because YUV is a block format.
-void CreateTestYUVVideoDrawQuad_TwoColor(
- const SharedQuadState* shared_state,
- media::VideoPixelFormat format,
- media::ColorSpace color_space,
- bool is_transparent,
- const gfx::RectF& tex_coord_rect,
- const gfx::Size& background_size,
- const gfx::Rect& visible_rect,
- uint8_t y_background,
- uint8_t u_background,
- uint8_t v_background,
- const gfx::Rect& foreground_rect,
- uint8_t y_foreground,
- uint8_t u_foreground,
- uint8_t v_foreground,
- RenderPass* render_pass,
- VideoResourceUpdater* video_resource_updater,
- ResourceProvider* resource_provider) {
- const gfx::Rect rect(background_size);
-
- scoped_refptr<media::VideoFrame> video_frame =
- media::VideoFrame::CreateFrame(format, background_size, foreground_rect,
- foreground_rect.size(), base::TimeDelta());
- video_frame->metadata()->SetInteger(media::VideoFrameMetadata::COLOR_SPACE,
- color_space);
-
- int planes[] = {media::VideoFrame::kYPlane,
- media::VideoFrame::kUPlane,
- media::VideoFrame::kVPlane};
- uint8_t yuv_background[] = {y_background, u_background, v_background};
- uint8_t yuv_foreground[] = {y_foreground, u_foreground, v_foreground};
- int sample_size[] = {1, 2, 2};
-
- for (int i = 0; i < 3; ++i) {
- memset(video_frame->data(planes[i]), yuv_background[i],
- video_frame->stride(planes[i]) * video_frame->rows(planes[i]));
- }
-
- for (int i = 0; i < 3; ++i) {
- // Since yuv encoding uses block encoding, widths have to be divisible
- // by the sample size in order for this function to behave properly.
- DCHECK_EQ(foreground_rect.x() % sample_size[i], 0);
- DCHECK_EQ(foreground_rect.y() % sample_size[i], 0);
- DCHECK_EQ(foreground_rect.width() % sample_size[i], 0);
- DCHECK_EQ(foreground_rect.height() % sample_size[i], 0);
-
- gfx::Rect sample_rect(foreground_rect.x() / sample_size[i],
- foreground_rect.y() / sample_size[i],
- foreground_rect.width() / sample_size[i],
- foreground_rect.height() / sample_size[i]);
- for (int y = sample_rect.y(); y < sample_rect.bottom(); ++y) {
- for (int x = sample_rect.x(); x < sample_rect.right(); ++x) {
- size_t offset = y * video_frame->stride(planes[i]) + x;
- video_frame->data(planes[i])[offset] = yuv_foreground[i];
- }
- }
- }
-
- uint8_t alpha_value = 255;
- CreateTestYUVVideoDrawQuad_FromVideoFrame(
- shared_state, video_frame, alpha_value, tex_coord_rect, render_pass,
- video_resource_updater, rect, visible_rect, resource_provider);
-}
-
-void CreateTestYUVVideoDrawQuad_Solid(
- const SharedQuadState* shared_state,
- media::VideoPixelFormat format,
- media::ColorSpace color_space,
- bool is_transparent,
- const gfx::RectF& tex_coord_rect,
- uint8_t y,
- uint8_t u,
- uint8_t v,
- RenderPass* render_pass,
- VideoResourceUpdater* video_resource_updater,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- ResourceProvider* resource_provider) {
- scoped_refptr<media::VideoFrame> video_frame = media::VideoFrame::CreateFrame(
- format, rect.size(), rect, rect.size(), base::TimeDelta());
- video_frame->metadata()->SetInteger(media::VideoFrameMetadata::COLOR_SPACE,
- color_space);
-
- // YUV values of a solid, constant, color. Useful for testing that color
- // space/color range are being handled properly.
- memset(video_frame->data(media::VideoFrame::kYPlane), y,
- video_frame->stride(media::VideoFrame::kYPlane) *
- video_frame->rows(media::VideoFrame::kYPlane));
- memset(video_frame->data(media::VideoFrame::kUPlane), u,
- video_frame->stride(media::VideoFrame::kUPlane) *
- video_frame->rows(media::VideoFrame::kUPlane));
- memset(video_frame->data(media::VideoFrame::kVPlane), v,
- video_frame->stride(media::VideoFrame::kVPlane) *
- video_frame->rows(media::VideoFrame::kVPlane));
-
- uint8_t alpha_value = is_transparent ? 0 : 128;
- CreateTestYUVVideoDrawQuad_FromVideoFrame(
- shared_state, video_frame, alpha_value, tex_coord_rect, render_pass,
- video_resource_updater, rect, visible_rect, resource_provider);
-}
-
-void CreateTestYUVVideoDrawQuad_NV12(const SharedQuadState* shared_state,
- media::ColorSpace video_frame_color_space,
- const gfx::ColorSpace& video_color_space,
- const gfx::RectF& tex_coord_rect,
- uint8_t y,
- uint8_t u,
- uint8_t v,
- RenderPass* render_pass,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- ResourceProvider* resource_provider) {
- YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::REC_601;
- if (video_frame_color_space == media::COLOR_SPACE_JPEG) {
- color_space = YUVVideoDrawQuad::JPEG;
- }
-
- bool needs_blending = true;
- const gfx::Size ya_tex_size = rect.size();
- const gfx::Size uv_tex_size = media::VideoFrame::PlaneSize(
- media::PIXEL_FORMAT_NV12, media::VideoFrame::kUVPlane, rect.size());
-
- viz::ResourceId y_resource = resource_provider->CreateResource(
- rect.size(), ResourceProvider::TEXTURE_HINT_DEFAULT,
- resource_provider->YuvResourceFormat(8), gfx::ColorSpace());
- viz::ResourceId u_resource = resource_provider->CreateResource(
- uv_tex_size, ResourceProvider::TEXTURE_HINT_DEFAULT, viz::RGBA_8888,
- gfx::ColorSpace());
- viz::ResourceId v_resource = u_resource;
- viz::ResourceId a_resource = 0;
-
- std::vector<uint8_t> y_pixels(ya_tex_size.GetArea(), y);
- resource_provider->CopyToResource(y_resource, y_pixels.data(), ya_tex_size);
-
- // U goes in the R component and V goes in the G component.
- uint32_t rgba_pixel = (u << 24) | (v << 16);
- std::vector<uint32_t> uv_pixels(uv_tex_size.GetArea(), rgba_pixel);
- resource_provider->CopyToResource(
- u_resource, reinterpret_cast<uint8_t*>(uv_pixels.data()), uv_tex_size);
-
- gfx::RectF ya_tex_coord_rect(tex_coord_rect.x() * ya_tex_size.width(),
- tex_coord_rect.y() * ya_tex_size.height(),
- tex_coord_rect.width() * ya_tex_size.width(),
- tex_coord_rect.height() * ya_tex_size.height());
- gfx::RectF uv_tex_coord_rect(tex_coord_rect.x() * uv_tex_size.width(),
- tex_coord_rect.y() * uv_tex_size.height(),
- tex_coord_rect.width() * uv_tex_size.width(),
- tex_coord_rect.height() * uv_tex_size.height());
-
- YUVVideoDrawQuad* yuv_quad =
- render_pass->CreateAndAppendDrawQuad<YUVVideoDrawQuad>();
- yuv_quad->SetNew(shared_state, rect, visible_rect, needs_blending,
- ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size,
- uv_tex_size, y_resource, u_resource, v_resource, a_resource,
- color_space, video_color_space, 0.0f, 1.0f, 8);
-}
-
-void CreateTestY16TextureDrawQuad_TwoColor(
- const SharedQuadState* shared_state,
- const gfx::RectF& tex_coord_rect,
- uint8_t g_foreground,
- uint8_t g_background,
- RenderPass* render_pass,
- VideoResourceUpdater* video_resource_updater,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- const gfx::Rect& foreground_rect,
- ResourceProvider* resource_provider) {
- std::unique_ptr<unsigned char, base::AlignedFreeDeleter> memory(
- static_cast<unsigned char*>(
- base::AlignedAlloc(rect.size().GetArea() * 2,
- media::VideoFrame::kFrameAddressAlignment)));
- scoped_refptr<media::VideoFrame> video_frame =
- media::VideoFrame::WrapExternalData(
- media::PIXEL_FORMAT_Y16, rect.size(), visible_rect,
- visible_rect.size(), memory.get(), rect.size().GetArea() * 2,
- base::TimeDelta());
- DCHECK_EQ(video_frame->rows(0) % 2, 0);
- DCHECK_EQ(video_frame->stride(0) % 2, 0);
-
- for (int j = 0; j < video_frame->rows(0); ++j) {
- uint8_t* row = video_frame->data(0) + j * video_frame->stride(0);
- if (j < foreground_rect.y() || j >= foreground_rect.bottom()) {
- for (int i = 0; i < video_frame->stride(0) / 2; ++i) {
- *row++ = i & 0xFF; // Fill R with anything. It is not rendered.
- *row++ = g_background;
- }
- } else {
- for (int i = 0;
- i < std::min(video_frame->stride(0) / 2, foreground_rect.x()); ++i) {
- *row++ = i & 0xFF;
- *row++ = g_background;
- }
- for (int i = foreground_rect.x();
- i < std::min(video_frame->stride(0) / 2, foreground_rect.right());
- ++i) {
- *row++ = i & 0xFF;
- *row++ = g_foreground;
- }
- for (int i = foreground_rect.right(); i < video_frame->stride(0) / 2;
- ++i) {
- *row++ = i & 0xFF;
- *row++ = g_background;
- }
- }
- }
-
- CreateTestY16TextureDrawQuad_FromVideoFrame(
- shared_state, video_frame, tex_coord_rect, render_pass,
- video_resource_updater, rect, visible_rect, resource_provider);
-}
-
-typedef ::testing::Types<viz::GLRenderer,
- SoftwareRenderer,
- GLRendererWithExpandedViewport,
- SoftwareRendererWithExpandedViewport>
- RendererTypes;
-TYPED_TEST_CASE(RendererPixelTest, RendererTypes);
-
-template <typename RendererType>
-class SoftwareRendererPixelTest : public RendererPixelTest<RendererType> {};
-
-typedef ::testing::Types<SoftwareRenderer, SoftwareRendererWithExpandedViewport>
- SoftwareRendererTypes;
-TYPED_TEST_CASE(SoftwareRendererPixelTest, SoftwareRendererTypes);
-
-template <typename RendererType>
-class FuzzyForSoftwareOnlyPixelComparator : public PixelComparator {
- public:
- explicit FuzzyForSoftwareOnlyPixelComparator(bool discard_alpha)
- : fuzzy_(discard_alpha), exact_(discard_alpha) {}
-
- bool Compare(const SkBitmap& actual_bmp,
- const SkBitmap& expected_bmp) const override;
-
- private:
- FuzzyPixelOffByOneComparator fuzzy_;
- ExactPixelComparator exact_;
-};
-
-template<>
-bool FuzzyForSoftwareOnlyPixelComparator<SoftwareRenderer>::Compare(
- const SkBitmap& actual_bmp,
- const SkBitmap& expected_bmp) const {
- return fuzzy_.Compare(actual_bmp, expected_bmp);
-}
-
-template <>
-bool FuzzyForSoftwareOnlyPixelComparator<
- SoftwareRendererWithExpandedViewport>::Compare(
- const SkBitmap& actual_bmp,
- const SkBitmap& expected_bmp) const {
- return fuzzy_.Compare(actual_bmp, expected_bmp);
-}
-
-template<typename RendererType>
-bool FuzzyForSoftwareOnlyPixelComparator<RendererType>::Compare(
- const SkBitmap& actual_bmp,
- const SkBitmap& expected_bmp) const {
- return exact_.Compare(actual_bmp, expected_bmp);
-}
-
-TYPED_TEST(RendererPixelTest, SimpleGreenRect) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
-
- SolidColorDrawQuad* color_quad =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(shared_state, rect, rect, SK_ColorGREEN, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("green.png")),
- ExactPixelComparator(true)));
-}
-
-TYPED_TEST(RendererPixelTest, SimpleGreenRect_NonRootRenderPass) {
- gfx::Rect rect(this->device_viewport_size_);
- gfx::Rect small_rect(100, 100);
-
- int child_id = 2;
- std::unique_ptr<RenderPass> child_pass =
- CreateTestRenderPass(child_id, small_rect, gfx::Transform());
-
- SharedQuadState* child_shared_state =
- CreateTestSharedQuadState(gfx::Transform(), small_rect, child_pass.get());
-
- SolidColorDrawQuad* color_quad =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(child_shared_state, rect, rect, SK_ColorGREEN, false);
-
- int root_id = 1;
- std::unique_ptr<RenderPass> root_pass =
- CreateTestRenderPass(root_id, rect, gfx::Transform());
-
- SharedQuadState* root_shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, root_pass.get());
-
- CreateTestRenderPassDrawQuad(
- root_shared_state, small_rect, child_id, root_pass.get());
-
- RenderPass* child_pass_ptr = child_pass.get();
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(child_pass));
- pass_list.push_back(std::move(root_pass));
-
- EXPECT_TRUE(this->RunPixelTestWithReadbackTarget(
- &pass_list,
- child_pass_ptr,
- base::FilePath(FILE_PATH_LITERAL("green_small.png")),
- ExactPixelComparator(true)));
-}
-
-TYPED_TEST(RendererPixelTest, PremultipliedTextureWithoutBackground) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
-
- CreateTestTextureDrawQuad(gfx::Rect(this->device_viewport_size_),
- SkColorSetARGB(128, 0, 255, 0), // Texel color.
- SK_ColorTRANSPARENT, // Background color.
- true, // Premultiplied alpha.
- shared_state,
- this->resource_provider_.get(),
- pass.get());
-
- SolidColorDrawQuad* color_quad =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(shared_state, rect, rect, SK_ColorWHITE, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-TYPED_TEST(RendererPixelTest, PremultipliedTextureWithBackground) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* texture_quad_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
- texture_quad_state->opacity = 0.8f;
-
- CreateTestTextureDrawQuad(gfx::Rect(this->device_viewport_size_),
- SkColorSetARGB(204, 120, 255, 120), // Texel color.
- SK_ColorGREEN, // Background color.
- true, // Premultiplied alpha.
- texture_quad_state,
- this->resource_provider_.get(),
- pass.get());
-
- SharedQuadState* color_quad_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
- SolidColorDrawQuad* color_quad =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(color_quad_state, rect, rect, SK_ColorWHITE, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-TEST_F(GLRendererPixelTest, SolidColorBlend) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
- shared_state->opacity = 1 - 16.0f / 255;
- shared_state->blend_mode = SkBlendMode::kDstOut;
-
- SolidColorDrawQuad* color_quad =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(shared_state, rect, rect, SK_ColorRED, false);
-
- SharedQuadState* shared_state_background =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
-
- SkColor background_color = SkColorSetRGB(0xff, 0xff * 14 / 16, 0xff);
- SolidColorDrawQuad* color_quad_background =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad_background->SetNew(shared_state_background, rect, rect,
- background_color, false);
- // Result should be r=16, g=14, b=16.
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list, base::FilePath(FILE_PATH_LITERAL("dark_grey.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-TEST_F(GLRendererPixelTest,
- PremultipliedTextureWithBackgroundAndVertexOpacity) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* texture_quad_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
- texture_quad_state->opacity = 0.8f;
-
- float vertex_opacity[4] = {1.f, 1.f, 0.f, 0.f};
- CreateTestTextureDrawQuad(gfx::Rect(this->device_viewport_size_),
- SkColorSetARGB(204, 120, 255, 120), // Texel color.
- vertex_opacity,
- SK_ColorGREEN, // Background color.
- true, // Premultiplied alpha.
- texture_quad_state, this->resource_provider_.get(),
- pass.get());
-
- SharedQuadState* color_quad_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
- SolidColorDrawQuad* color_quad =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(color_quad_state, rect, rect, SK_ColorWHITE, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("green_alpha_vertex_opacity.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-template <typename TypeParam>
-class IntersectingQuadPixelTest : public RendererPixelTest<TypeParam> {
- protected:
- void SetupQuadStateAndRenderPass() {
- // This sets up a pair of draw quads. They are both rotated
- // relative to the root plane, they are also rotated relative to each other.
- // The intersect in the middle at a non-perpendicular angle so that any
- // errors are hopefully magnified.
- // The quads should intersect correctly, as in the front quad should only
- // be partially in front of the back quad, and partially behind.
-
- viewport_rect_ = gfx::Rect(this->device_viewport_size_);
- quad_rect_ = gfx::Rect(0, 0, this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2.0);
-
- int id = 1;
- render_pass_ = CreateTestRootRenderPass(id, viewport_rect_);
-
- // Create the front quad rotated on the Z and Y axis.
- gfx::Transform trans;
- trans.Translate3d(0, 0, 0.707 * this->device_viewport_size_.width() / 2.0);
- trans.RotateAboutZAxis(45.0);
- trans.RotateAboutYAxis(45.0);
- front_quad_state_ =
- CreateTestSharedQuadState(trans, viewport_rect_, render_pass_.get());
- front_quad_state_->clip_rect = quad_rect_;
- // Make sure they end up in a 3d sorting context.
- front_quad_state_->sorting_context_id = 1;
-
- // Create the back quad, and rotate on just the y axis. This will intersect
- // the first quad partially.
- trans = gfx::Transform();
- trans.Translate3d(0, 0, -0.707 * this->device_viewport_size_.width() / 2.0);
- trans.RotateAboutYAxis(-45.0);
- back_quad_state_ =
- CreateTestSharedQuadState(trans, viewport_rect_, render_pass_.get());
- back_quad_state_->sorting_context_id = 1;
- back_quad_state_->clip_rect = quad_rect_;
- }
- void AppendBackgroundAndRunTest(const PixelComparator& comparator,
- const base::FilePath::CharType* ref_file) {
- SharedQuadState* background_quad_state = CreateTestSharedQuadState(
- gfx::Transform(), viewport_rect_, render_pass_.get());
- SolidColorDrawQuad* background_quad =
- render_pass_->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- background_quad->SetNew(background_quad_state, viewport_rect_,
- viewport_rect_, SK_ColorWHITE, false);
- pass_list_.push_back(std::move(render_pass_));
- EXPECT_TRUE(
- this->RunPixelTest(&pass_list_, base::FilePath(ref_file), comparator));
- }
- template <typename T>
- T* CreateAndAppendDrawQuad() {
- return render_pass_->CreateAndAppendDrawQuad<T>();
- }
-
- std::unique_ptr<RenderPass> render_pass_;
- gfx::Rect viewport_rect_;
- SharedQuadState* front_quad_state_;
- SharedQuadState* back_quad_state_;
- gfx::Rect quad_rect_;
- RenderPassList pass_list_;
-};
-
-template <typename TypeParam>
-class IntersectingQuadGLPixelTest
- : public IntersectingQuadPixelTest<TypeParam> {
- public:
- void SetUp() override {
- IntersectingQuadPixelTest<TypeParam>::SetUp();
- bool use_stream_video_draw_quad = false;
- video_resource_updater_.reset(new VideoResourceUpdater(
- this->output_surface_->context_provider(),
- this->resource_provider_.get(), use_stream_video_draw_quad));
- video_resource_updater2_.reset(new VideoResourceUpdater(
- this->output_surface_->context_provider(),
- this->resource_provider_.get(), use_stream_video_draw_quad));
- }
-
- protected:
- std::unique_ptr<VideoResourceUpdater> video_resource_updater_;
- std::unique_ptr<VideoResourceUpdater> video_resource_updater2_;
-};
-
-template <typename TypeParam>
-class IntersectingQuadSoftwareTest
- : public IntersectingQuadPixelTest<TypeParam> {};
-
-typedef ::testing::Types<SoftwareRenderer, SoftwareRendererWithExpandedViewport>
- SoftwareRendererTypes;
-typedef ::testing::Types<viz::GLRenderer, GLRendererWithExpandedViewport>
- GLRendererTypes;
-
-TYPED_TEST_CASE(IntersectingQuadPixelTest, RendererTypes);
-TYPED_TEST_CASE(IntersectingQuadGLPixelTest, GLRendererTypes);
-TYPED_TEST_CASE(IntersectingQuadSoftwareTest, SoftwareRendererTypes);
-
-TYPED_TEST(IntersectingQuadPixelTest, SolidColorQuads) {
- this->SetupQuadStateAndRenderPass();
-
- SolidColorDrawQuad* quad =
- this->template CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- SolidColorDrawQuad* quad2 =
- this->template CreateAndAppendDrawQuad<SolidColorDrawQuad>();
-
- quad->SetNew(this->front_quad_state_, this->quad_rect_, this->quad_rect_,
- SK_ColorBLUE, false);
- quad2->SetNew(this->back_quad_state_, this->quad_rect_, this->quad_rect_,
- SK_ColorGREEN, false);
- SCOPED_TRACE("IntersectingSolidColorQuads");
- this->AppendBackgroundAndRunTest(
- FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f),
- FILE_PATH_LITERAL("intersecting_blue_green.png"));
-}
-
-template <typename TypeParam>
-SkColor GetColor(const SkColor& color) {
- return color;
-}
-
-template <>
-SkColor GetColor<viz::GLRenderer>(const SkColor& color) {
- return SkColorSetARGB(SkColorGetA(color), SkColorGetB(color),
- SkColorGetG(color), SkColorGetR(color));
-}
-template <>
-SkColor GetColor<GLRendererWithExpandedViewport>(const SkColor& color) {
- return GetColor<viz::GLRenderer>(color);
-}
-
-TYPED_TEST(IntersectingQuadPixelTest, TexturedQuads) {
- this->SetupQuadStateAndRenderPass();
- CreateTestTwoColoredTextureDrawQuad(
- this->quad_rect_, GetColor<TypeParam>(SkColorSetARGB(255, 0, 0, 0)),
- GetColor<TypeParam>(SkColorSetARGB(255, 0, 0, 255)), SK_ColorTRANSPARENT,
- true, this->front_quad_state_, this->resource_provider_.get(),
- this->render_pass_.get());
- CreateTestTwoColoredTextureDrawQuad(
- this->quad_rect_, GetColor<TypeParam>(SkColorSetARGB(255, 0, 255, 0)),
- GetColor<TypeParam>(SkColorSetARGB(255, 0, 0, 0)), SK_ColorTRANSPARENT,
- true, this->back_quad_state_, this->resource_provider_.get(),
- this->render_pass_.get());
-
- SCOPED_TRACE("IntersectingTexturedQuads");
- this->AppendBackgroundAndRunTest(
- FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f),
- FILE_PATH_LITERAL("intersecting_blue_green_squares.png"));
-}
-
-TYPED_TEST(IntersectingQuadSoftwareTest, PictureQuads) {
- bool needs_blending = true;
- this->SetupQuadStateAndRenderPass();
- gfx::Rect outer_rect(this->quad_rect_);
- gfx::Rect inner_rect(this->quad_rect_.x() + (this->quad_rect_.width() / 4),
- this->quad_rect_.y() + (this->quad_rect_.height() / 4),
- this->quad_rect_.width() / 2,
- this->quad_rect_.height() / 2);
-
- PaintFlags black_flags;
- black_flags.setColor(SK_ColorBLACK);
- PaintFlags blue_flags;
- blue_flags.setColor(SK_ColorBLUE);
- PaintFlags green_flags;
- green_flags.setColor(SK_ColorGREEN);
-
- std::unique_ptr<FakeRecordingSource> blue_recording =
- FakeRecordingSource::CreateFilledRecordingSource(this->quad_rect_.size());
- blue_recording->add_draw_rect_with_flags(outer_rect, black_flags);
- blue_recording->add_draw_rect_with_flags(inner_rect, blue_flags);
- blue_recording->Rerecord();
- scoped_refptr<RasterSource> blue_raster_source =
- blue_recording->CreateRasterSource();
-
- PictureDrawQuad* blue_quad =
- this->render_pass_->template CreateAndAppendDrawQuad<PictureDrawQuad>();
-
- blue_quad->SetNew(this->front_quad_state_, this->quad_rect_, this->quad_rect_,
- needs_blending, gfx::RectF(this->quad_rect_),
- this->quad_rect_.size(), false, viz::RGBA_8888,
- this->quad_rect_, 1.f, blue_raster_source);
-
- std::unique_ptr<FakeRecordingSource> green_recording =
- FakeRecordingSource::CreateFilledRecordingSource(this->quad_rect_.size());
- green_recording->add_draw_rect_with_flags(outer_rect, green_flags);
- green_recording->add_draw_rect_with_flags(inner_rect, black_flags);
- green_recording->Rerecord();
- scoped_refptr<RasterSource> green_raster_source =
- green_recording->CreateRasterSource();
-
- PictureDrawQuad* green_quad =
- this->render_pass_->template CreateAndAppendDrawQuad<PictureDrawQuad>();
- green_quad->SetNew(this->back_quad_state_, this->quad_rect_, this->quad_rect_,
- needs_blending, gfx::RectF(this->quad_rect_),
- this->quad_rect_.size(), false, viz::RGBA_8888,
- this->quad_rect_, 1.f, green_raster_source);
- SCOPED_TRACE("IntersectingPictureQuadsPass");
- this->AppendBackgroundAndRunTest(
- FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f),
- FILE_PATH_LITERAL("intersecting_blue_green_squares.png"));
-}
-
-TYPED_TEST(IntersectingQuadPixelTest, RenderPassQuads) {
- this->SetupQuadStateAndRenderPass();
- int child_pass_id1 = 2;
- int child_pass_id2 = 3;
- std::unique_ptr<RenderPass> child_pass1 =
- CreateTestRenderPass(child_pass_id1, this->quad_rect_, gfx::Transform());
- SharedQuadState* child1_quad_state = CreateTestSharedQuadState(
- gfx::Transform(), this->quad_rect_, child_pass1.get());
- std::unique_ptr<RenderPass> child_pass2 =
- CreateTestRenderPass(child_pass_id2, this->quad_rect_, gfx::Transform());
- SharedQuadState* child2_quad_state = CreateTestSharedQuadState(
- gfx::Transform(), this->quad_rect_, child_pass2.get());
-
- CreateTestTwoColoredTextureDrawQuad(
- this->quad_rect_, GetColor<TypeParam>(SkColorSetARGB(255, 0, 0, 0)),
- GetColor<TypeParam>(SkColorSetARGB(255, 0, 0, 255)), SK_ColorTRANSPARENT,
- true, child1_quad_state, this->resource_provider_.get(),
- child_pass1.get());
- CreateTestTwoColoredTextureDrawQuad(
- this->quad_rect_, GetColor<TypeParam>(SkColorSetARGB(255, 0, 255, 0)),
- GetColor<TypeParam>(SkColorSetARGB(255, 0, 0, 0)), SK_ColorTRANSPARENT,
- true, child2_quad_state, this->resource_provider_.get(),
- child_pass2.get());
-
- CreateTestRenderPassDrawQuad(this->front_quad_state_, this->quad_rect_,
- child_pass_id1, this->render_pass_.get());
- CreateTestRenderPassDrawQuad(this->back_quad_state_, this->quad_rect_,
- child_pass_id2, this->render_pass_.get());
-
- this->pass_list_.push_back(std::move(child_pass1));
- this->pass_list_.push_back(std::move(child_pass2));
- SCOPED_TRACE("IntersectingRenderQuadsPass");
- this->AppendBackgroundAndRunTest(
- FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f),
- FILE_PATH_LITERAL("intersecting_blue_green_squares.png"));
-}
-
-TYPED_TEST(IntersectingQuadGLPixelTest, YUVVideoQuads) {
- this->SetupQuadStateAndRenderPass();
- gfx::Rect inner_rect(
- ((this->quad_rect_.x() + (this->quad_rect_.width() / 4)) & ~0xF),
- ((this->quad_rect_.y() + (this->quad_rect_.height() / 4)) & ~0xF),
- (this->quad_rect_.width() / 2) & ~0xF,
- (this->quad_rect_.height() / 2) & ~0xF);
-
- CreateTestYUVVideoDrawQuad_TwoColor(
- this->front_quad_state_, media::PIXEL_FORMAT_YV12,
- media::COLOR_SPACE_JPEG, false, gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f),
- this->quad_rect_.size(), this->quad_rect_, 0, 128, 128, inner_rect, 29,
- 255, 107, this->render_pass_.get(), this->video_resource_updater_.get(),
- this->resource_provider_.get());
-
- CreateTestYUVVideoDrawQuad_TwoColor(
- this->back_quad_state_, media::PIXEL_FORMAT_YV12, media::COLOR_SPACE_JPEG,
- false, gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), this->quad_rect_.size(),
- this->quad_rect_, 149, 43, 21, inner_rect, 0, 128, 128,
- this->render_pass_.get(), this->video_resource_updater2_.get(),
- this->resource_provider_.get());
-
- SCOPED_TRACE("IntersectingVideoQuads");
- this->AppendBackgroundAndRunTest(
- FuzzyPixelOffByOneComparator(false),
- FILE_PATH_LITERAL("intersecting_blue_green_squares_video.png"));
-}
-
-TYPED_TEST(IntersectingQuadGLPixelTest, Y16VideoQuads) {
- this->SetupQuadStateAndRenderPass();
- gfx::Rect inner_rect(
- ((this->quad_rect_.x() + (this->quad_rect_.width() / 4)) & ~0xF),
- ((this->quad_rect_.y() + (this->quad_rect_.height() / 4)) & ~0xF),
- (this->quad_rect_.width() / 2) & ~0xF,
- (this->quad_rect_.height() / 2) & ~0xF);
-
- CreateTestY16TextureDrawQuad_TwoColor(
- this->front_quad_state_, gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), 18, 0,
- this->render_pass_.get(), this->video_resource_updater_.get(),
- this->quad_rect_, this->quad_rect_, inner_rect,
- this->resource_provider_.get());
-
- CreateTestY16TextureDrawQuad_TwoColor(
- this->back_quad_state_, gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), 0, 182,
- this->render_pass_.get(), this->video_resource_updater2_.get(),
- this->quad_rect_, this->quad_rect_, inner_rect,
- this->resource_provider_.get());
-
- SCOPED_TRACE("IntersectingVideoQuads");
- this->AppendBackgroundAndRunTest(
- FuzzyPixelOffByOneComparator(false),
- FILE_PATH_LITERAL("intersecting_light_dark_squares_video.png"));
-}
-
-// TODO(skaslev): The software renderer does not support non-premultplied alpha.
-TEST_F(GLRendererPixelTest, NonPremultipliedTextureWithoutBackground) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
-
- CreateTestTextureDrawQuad(gfx::Rect(this->device_viewport_size_),
- SkColorSetARGB(128, 0, 255, 0), // Texel color.
- SK_ColorTRANSPARENT, // Background color.
- false, // Premultiplied alpha.
- shared_state,
- this->resource_provider_.get(),
- pass.get());
-
- SolidColorDrawQuad* color_quad =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(shared_state, rect, rect, SK_ColorWHITE, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-// TODO(skaslev): The software renderer does not support non-premultplied alpha.
-TEST_F(GLRendererPixelTest, NonPremultipliedTextureWithBackground) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* texture_quad_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
- texture_quad_state->opacity = 0.8f;
-
- CreateTestTextureDrawQuad(gfx::Rect(this->device_viewport_size_),
- SkColorSetARGB(204, 120, 255, 120), // Texel color.
- SK_ColorGREEN, // Background color.
- false, // Premultiplied alpha.
- texture_quad_state,
- this->resource_provider_.get(),
- pass.get());
-
- SharedQuadState* color_quad_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
- SolidColorDrawQuad* color_quad =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(color_quad_state, rect, rect, SK_ColorWHITE, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-class VideoGLRendererPixelTest : public GLRendererPixelTest {
- protected:
- void CreateEdgeBleedPass(media::VideoPixelFormat format,
- media::ColorSpace color_space,
- RenderPassList* pass_list) {
- gfx::Rect rect(200, 200);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- // Scale the video up so that bilinear filtering kicks in to sample more
- // than just nearest neighbor would.
- gfx::Transform scale_by_2;
- scale_by_2.Scale(2.f, 2.f);
- gfx::Rect half_rect(100, 100);
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(scale_by_2, half_rect, pass.get());
-
- gfx::Size background_size(200, 200);
- gfx::Rect green_rect(16, 20, 100, 100);
- gfx::RectF tex_coord_rect(
- static_cast<float>(green_rect.x()) / background_size.width(),
- static_cast<float>(green_rect.y()) / background_size.height(),
- static_cast<float>(green_rect.width()) / background_size.width(),
- static_cast<float>(green_rect.height()) / background_size.height());
-
- // YUV of (149,43,21) should be green (0,255,0) in RGB.
- // Create a video frame that has a non-green background rect, with a
- // green sub-rectangle that should be the only thing displayed in
- // the final image. Bleeding will appear on all four sides of the video
- // if the tex coords are not clamped.
- CreateTestYUVVideoDrawQuad_TwoColor(
- shared_state, format, color_space, false, tex_coord_rect,
- background_size, gfx::Rect(background_size), 128, 128, 128, green_rect,
- 149, 43, 21, pass.get(), video_resource_updater_.get(),
- resource_provider_.get());
- pass_list->push_back(std::move(pass));
- }
-
- void SetUp() override {
- GLRendererPixelTest::SetUp();
- bool use_stream_video_draw_quad = false;
- video_resource_updater_.reset(new VideoResourceUpdater(
- output_surface_->context_provider(), resource_provider_.get(),
- use_stream_video_draw_quad));
- }
-
- std::unique_ptr<VideoResourceUpdater> video_resource_updater_;
-};
-
-class VideoGLRendererPixelHiLoTest
- : public VideoGLRendererPixelTest,
- public ::testing::WithParamInterface<bool> {};
-
-TEST_P(VideoGLRendererPixelHiLoTest, SimpleYUVRect) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
-
- bool highbit = GetParam();
- CreateTestYUVVideoDrawQuad_Striped(
- shared_state, media::PIXEL_FORMAT_YV12, false, highbit,
- gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), pass.get(),
- video_resource_updater_.get(), rect, rect, resource_provider_.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(
- this->RunPixelTest(&pass_list,
- base::FilePath(FILE_PATH_LITERAL("yuv_stripes.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-TEST_P(VideoGLRendererPixelHiLoTest, ClippedYUVRect) {
- gfx::Rect viewport(this->device_viewport_size_);
- gfx::Rect draw_rect(this->device_viewport_size_.width() * 1.5,
- this->device_viewport_size_.height() * 1.5);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, viewport);
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), viewport, pass.get());
-
- bool highbit = GetParam();
- CreateTestYUVVideoDrawQuad_Striped(
- shared_state, media::PIXEL_FORMAT_YV12, false, highbit,
- gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), pass.get(),
- video_resource_updater_.get(), draw_rect, viewport,
- resource_provider_.get());
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list, base::FilePath(FILE_PATH_LITERAL("yuv_stripes_clipped.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-TEST_F(VideoGLRendererPixelHiLoTest, OffsetYUVRect) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
-
- // Intentionally sets frame format to I420 for testing coverage.
- CreateTestYUVVideoDrawQuad_Striped(
- shared_state, media::PIXEL_FORMAT_I420, false, false,
- gfx::RectF(0.125f, 0.25f, 0.75f, 0.5f), pass.get(),
- video_resource_updater_.get(), rect, rect, resource_provider_.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list, base::FilePath(FILE_PATH_LITERAL("yuv_stripes_offset.png")),
- FuzzyPixelComparator(true, 100.0f, 1.0f, 1.0f, 1, 0)));
-}
-
-TEST_F(VideoGLRendererPixelTest, SimpleYUVRectBlack) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
-
- // In MPEG color range YUV values of (15,128,128) should produce black.
- CreateTestYUVVideoDrawQuad_Solid(
- shared_state, media::PIXEL_FORMAT_YV12, media::COLOR_SPACE_UNSPECIFIED,
- false, gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), 15, 128, 128, pass.get(),
- video_resource_updater_.get(), rect, rect, resource_provider_.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- // If we didn't get black out of the YUV values above, then we probably have a
- // color range issue.
- EXPECT_TRUE(this->RunPixelTest(&pass_list,
- base::FilePath(FILE_PATH_LITERAL("black.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-// First argument (test case prefix) is intentionally left empty.
-INSTANTIATE_TEST_CASE_P(, VideoGLRendererPixelHiLoTest, ::testing::Bool());
-
-TEST_F(VideoGLRendererPixelTest, SimpleYUVJRect) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
-
- // YUV of (149,43,21) should be green (0,255,0) in RGB.
- CreateTestYUVVideoDrawQuad_Solid(
- shared_state, media::PIXEL_FORMAT_YV12, media::COLOR_SPACE_JPEG, false,
- gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), 149, 43, 21, pass.get(),
- video_resource_updater_.get(), rect, rect, resource_provider_.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(&pass_list,
- base::FilePath(FILE_PATH_LITERAL("green.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-TEST_F(VideoGLRendererPixelTest, SimpleNV12JRect) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
-
- // YUV of (149,43,21) should be green (0,255,0) in RGB.
- CreateTestYUVVideoDrawQuad_NV12(
- shared_state, media::COLOR_SPACE_JPEG, gfx::ColorSpace::CreateJpeg(),
- gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), 149, 43, 21, pass.get(), rect, rect,
- resource_provider_.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(&pass_list,
- base::FilePath(FILE_PATH_LITERAL("green.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-// Test that a YUV video doesn't bleed outside of its tex coords when the
-// tex coord rect is only a partial subrectangle of the coded contents.
-TEST_F(VideoGLRendererPixelTest, YUVEdgeBleed) {
- RenderPassList pass_list;
- CreateEdgeBleedPass(media::PIXEL_FORMAT_YV12, media::COLOR_SPACE_JPEG,
- &pass_list);
- EXPECT_TRUE(this->RunPixelTest(&pass_list,
- base::FilePath(FILE_PATH_LITERAL("green.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-TEST_F(VideoGLRendererPixelTest, YUVAEdgeBleed) {
- RenderPassList pass_list;
- CreateEdgeBleedPass(media::PIXEL_FORMAT_YV12A, media::COLOR_SPACE_UNSPECIFIED,
- &pass_list);
- EXPECT_TRUE(this->RunPixelTest(&pass_list,
- base::FilePath(FILE_PATH_LITERAL("green.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-TEST_F(VideoGLRendererPixelTest, SimpleYUVJRectGrey) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
-
- // Dark grey in JPEG color range (in MPEG, this is black).
- CreateTestYUVVideoDrawQuad_Solid(
- shared_state, media::PIXEL_FORMAT_YV12, media::COLOR_SPACE_JPEG, false,
- gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), 15, 128, 128, pass.get(),
- video_resource_updater_.get(), rect, rect, resource_provider_.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(
- this->RunPixelTest(&pass_list,
- base::FilePath(FILE_PATH_LITERAL("dark_grey.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-TEST_F(VideoGLRendererPixelHiLoTest, SimpleYUVARect) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
-
- CreateTestYUVVideoDrawQuad_Striped(
- shared_state, media::PIXEL_FORMAT_YV12A, false, false,
- gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), pass.get(),
- video_resource_updater_.get(), rect, rect, resource_provider_.get());
-
- SolidColorDrawQuad* color_quad =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(shared_state, rect, rect, SK_ColorWHITE, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("yuv_stripes_alpha.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-TEST_F(VideoGLRendererPixelTest, FullyTransparentYUVARect) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
-
- CreateTestYUVVideoDrawQuad_Striped(
- shared_state, media::PIXEL_FORMAT_YV12A, true, false,
- gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), pass.get(),
- video_resource_updater_.get(), rect, rect, resource_provider_.get());
-
- SolidColorDrawQuad* color_quad =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(shared_state, rect, rect, SK_ColorBLACK, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("black.png")),
- ExactPixelComparator(true)));
-}
-
-TEST_F(VideoGLRendererPixelTest, TwoColorY16Rect) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
-
- gfx::Rect upper_rect(rect.x(), rect.y(), rect.width(), rect.height() / 2);
- CreateTestY16TextureDrawQuad_TwoColor(
- shared_state, gfx::RectF(0.0f, 0.0f, 1.0f, 1.0f), 68, 123, pass.get(),
- video_resource_updater_.get(), rect, rect, upper_rect,
- resource_provider_.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("blue_yellow_filter_chain.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-TYPED_TEST(RendererPixelTest, FastPassColorFilterAlpha) {
- gfx::Rect viewport_rect(this->device_viewport_size_);
-
- int root_pass_id = 1;
- std::unique_ptr<RenderPass> root_pass =
- CreateTestRootRenderPass(root_pass_id, viewport_rect);
-
- int child_pass_id = 2;
- gfx::Rect pass_rect(this->device_viewport_size_);
- gfx::Transform transform_to_root;
- SkScalar matrix[20];
- float amount = 0.5f;
- matrix[0] = 0.213f + 0.787f * amount;
- matrix[1] = 0.715f - 0.715f * amount;
- matrix[2] = 1.f - (matrix[0] + matrix[1]);
- matrix[3] = matrix[4] = 0;
- matrix[5] = 0.213f - 0.213f * amount;
- matrix[6] = 0.715f + 0.285f * amount;
- matrix[7] = 1.f - (matrix[5] + matrix[6]);
- matrix[8] = matrix[9] = 0;
- matrix[10] = 0.213f - 0.213f * amount;
- matrix[11] = 0.715f - 0.715f * amount;
- matrix[12] = 1.f - (matrix[10] + matrix[11]);
- matrix[13] = matrix[14] = 0;
- matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0;
- matrix[18] = 1;
- FilterOperations filters;
- filters.Append(
- FilterOperation::CreateReferenceFilter(SkColorFilterImageFilter::Make(
- SkColorFilter::MakeMatrixFilterRowMajor255(matrix), nullptr)));
-
- std::unique_ptr<RenderPass> child_pass =
- CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
- child_pass->filters = filters;
-
- gfx::Transform quad_to_target_transform;
- SharedQuadState* shared_state = CreateTestSharedQuadState(
- quad_to_target_transform, viewport_rect, child_pass.get());
- shared_state->opacity = 0.5f;
-
- gfx::Rect blue_rect(0,
- 0,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* blue =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- blue->SetNew(shared_state, blue_rect, blue_rect, SK_ColorBLUE, false);
- gfx::Rect yellow_rect(0,
- this->device_viewport_size_.height() / 2,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* yellow =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- yellow->SetNew(shared_state, yellow_rect, yellow_rect, SK_ColorYELLOW, false);
-
- SharedQuadState* blank_state = CreateTestSharedQuadState(
- quad_to_target_transform, viewport_rect, child_pass.get());
-
- SolidColorDrawQuad* white =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- white->SetNew(
- blank_state, viewport_rect, viewport_rect, SK_ColorWHITE, false);
-
- SharedQuadState* pass_shared_state =
- CreateTestSharedQuadState(gfx::Transform(), pass_rect, root_pass.get());
-
- RenderPassDrawQuad* render_pass_quad =
- root_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- render_pass_quad->SetNew(
- pass_shared_state, pass_rect, pass_rect, child_pass_id, 0, gfx::RectF(),
- gfx::Size(), gfx::Vector2dF(), gfx::PointF(), gfx::RectF(pass_rect));
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(child_pass));
- pass_list.push_back(std::move(root_pass));
-
- // This test has alpha=254 for the software renderer vs. alpha=255 for the gl
- // renderer so use a fuzzy comparator.
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")),
- FuzzyForSoftwareOnlyPixelComparator<TypeParam>(false)));
-}
-
-TYPED_TEST(RendererPixelTest, FastPassSaturateFilter) {
- gfx::Rect viewport_rect(this->device_viewport_size_);
-
- int root_pass_id = 1;
- std::unique_ptr<RenderPass> root_pass =
- CreateTestRootRenderPass(root_pass_id, viewport_rect);
-
- int child_pass_id = 2;
- gfx::Rect pass_rect(this->device_viewport_size_);
- gfx::Transform transform_to_root;
- FilterOperations filters;
- filters.Append(FilterOperation::CreateSaturateFilter(0.5f));
-
- std::unique_ptr<RenderPass> child_pass =
- CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
- child_pass->filters = filters;
-
- gfx::Transform quad_to_target_transform;
- SharedQuadState* shared_state = CreateTestSharedQuadState(
- quad_to_target_transform, viewport_rect, child_pass.get());
- shared_state->opacity = 0.5f;
-
- gfx::Rect blue_rect(0,
- 0,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* blue =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- blue->SetNew(shared_state, blue_rect, blue_rect, SK_ColorBLUE, false);
- gfx::Rect yellow_rect(0,
- this->device_viewport_size_.height() / 2,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* yellow =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- yellow->SetNew(shared_state, yellow_rect, yellow_rect, SK_ColorYELLOW, false);
-
- SharedQuadState* blank_state = CreateTestSharedQuadState(
- quad_to_target_transform, viewport_rect, child_pass.get());
-
- SolidColorDrawQuad* white =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- white->SetNew(
- blank_state, viewport_rect, viewport_rect, SK_ColorWHITE, false);
-
- SharedQuadState* pass_shared_state =
- CreateTestSharedQuadState(gfx::Transform(), pass_rect, root_pass.get());
-
- RenderPassDrawQuad* render_pass_quad =
- root_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- render_pass_quad->SetNew(
- pass_shared_state, pass_rect, pass_rect, child_pass_id, 0, gfx::RectF(),
- gfx::Size(), gfx::Vector2dF(), gfx::PointF(), gfx::RectF(pass_rect));
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(child_pass));
- pass_list.push_back(std::move(root_pass));
-
- // This test blends slightly differently with the software renderer vs. the gl
- // renderer so use a fuzzy comparator.
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list, base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha.png")),
- FuzzyForSoftwareOnlyPixelComparator<TypeParam>(false)));
-}
-
-TYPED_TEST(RendererPixelTest, FastPassFilterChain) {
- gfx::Rect viewport_rect(this->device_viewport_size_);
-
- int root_pass_id = 1;
- std::unique_ptr<RenderPass> root_pass =
- CreateTestRootRenderPass(root_pass_id, viewport_rect);
-
- int child_pass_id = 2;
- gfx::Rect pass_rect(this->device_viewport_size_);
- gfx::Transform transform_to_root;
- FilterOperations filters;
- filters.Append(FilterOperation::CreateGrayscaleFilter(1.f));
- filters.Append(FilterOperation::CreateBrightnessFilter(0.5f));
-
- std::unique_ptr<RenderPass> child_pass =
- CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
- child_pass->filters = filters;
-
- gfx::Transform quad_to_target_transform;
- SharedQuadState* shared_state = CreateTestSharedQuadState(
- quad_to_target_transform, viewport_rect, child_pass.get());
- shared_state->opacity = 0.5f;
-
- gfx::Rect blue_rect(0,
- 0,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* blue =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- blue->SetNew(shared_state, blue_rect, blue_rect, SK_ColorBLUE, false);
- gfx::Rect yellow_rect(0,
- this->device_viewport_size_.height() / 2,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* yellow =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- yellow->SetNew(shared_state, yellow_rect, yellow_rect, SK_ColorYELLOW, false);
-
- SharedQuadState* blank_state = CreateTestSharedQuadState(
- quad_to_target_transform, viewport_rect, child_pass.get());
-
- SolidColorDrawQuad* white =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- white->SetNew(
- blank_state, viewport_rect, viewport_rect, SK_ColorWHITE, false);
-
- SharedQuadState* pass_shared_state =
- CreateTestSharedQuadState(gfx::Transform(), pass_rect, root_pass.get());
-
- RenderPassDrawQuad* render_pass_quad =
- root_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- render_pass_quad->SetNew(
- pass_shared_state, pass_rect, pass_rect, child_pass_id, 0, gfx::RectF(),
- gfx::Size(), gfx::Vector2dF(), gfx::PointF(), gfx::RectF(pass_rect));
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(child_pass));
- pass_list.push_back(std::move(root_pass));
-
- // This test blends slightly differently with the software renderer vs. the gl
- // renderer so use a fuzzy comparator.
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("blue_yellow_filter_chain.png")),
- FuzzyForSoftwareOnlyPixelComparator<TypeParam>(false)));
-}
-
-TYPED_TEST(RendererPixelTest, FastPassColorFilterAlphaTranslation) {
- gfx::Rect viewport_rect(this->device_viewport_size_);
-
- int root_pass_id = 1;
- std::unique_ptr<RenderPass> root_pass =
- CreateTestRootRenderPass(root_pass_id, viewport_rect);
-
- int child_pass_id = 2;
- gfx::Rect pass_rect(this->device_viewport_size_);
- gfx::Transform transform_to_root;
- SkScalar matrix[20];
- float amount = 0.5f;
- matrix[0] = 0.213f + 0.787f * amount;
- matrix[1] = 0.715f - 0.715f * amount;
- matrix[2] = 1.f - (matrix[0] + matrix[1]);
- matrix[3] = 0;
- matrix[4] = 20.f;
- matrix[5] = 0.213f - 0.213f * amount;
- matrix[6] = 0.715f + 0.285f * amount;
- matrix[7] = 1.f - (matrix[5] + matrix[6]);
- matrix[8] = 0;
- matrix[9] = 200.f;
- matrix[10] = 0.213f - 0.213f * amount;
- matrix[11] = 0.715f - 0.715f * amount;
- matrix[12] = 1.f - (matrix[10] + matrix[11]);
- matrix[13] = 0;
- matrix[14] = 1.5f;
- matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0;
- matrix[18] = 1;
- FilterOperations filters;
- filters.Append(
- FilterOperation::CreateReferenceFilter(SkColorFilterImageFilter::Make(
- SkColorFilter::MakeMatrixFilterRowMajor255(matrix), nullptr)));
-
- std::unique_ptr<RenderPass> child_pass =
- CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
- child_pass->filters = filters;
-
- gfx::Transform quad_to_target_transform;
- SharedQuadState* shared_state = CreateTestSharedQuadState(
- quad_to_target_transform, viewport_rect, child_pass.get());
- shared_state->opacity = 0.5f;
-
- gfx::Rect blue_rect(0,
- 0,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* blue =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- blue->SetNew(shared_state, blue_rect, blue_rect, SK_ColorBLUE, false);
- gfx::Rect yellow_rect(0,
- this->device_viewport_size_.height() / 2,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* yellow =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- yellow->SetNew(shared_state, yellow_rect, yellow_rect, SK_ColorYELLOW, false);
-
- SharedQuadState* blank_state = CreateTestSharedQuadState(
- quad_to_target_transform, viewport_rect, child_pass.get());
-
- SolidColorDrawQuad* white =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- white->SetNew(
- blank_state, viewport_rect, viewport_rect, SK_ColorWHITE, false);
-
- SharedQuadState* pass_shared_state =
- CreateTestSharedQuadState(gfx::Transform(), pass_rect, root_pass.get());
-
- RenderPassDrawQuad* render_pass_quad =
- root_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- render_pass_quad->SetNew(
- pass_shared_state, pass_rect, pass_rect, child_pass_id, 0, gfx::RectF(),
- gfx::Size(), gfx::Vector2dF(), gfx::PointF(), gfx::RectF(pass_rect));
-
- RenderPassList pass_list;
-
- pass_list.push_back(std::move(child_pass));
- pass_list.push_back(std::move(root_pass));
-
- // This test has alpha=254 for the software renderer vs. alpha=255 for the gl
- // renderer so use a fuzzy comparator.
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("blue_yellow_alpha_translate.png")),
- FuzzyForSoftwareOnlyPixelComparator<TypeParam>(false)));
-}
-
-TYPED_TEST(RendererPixelTest, EnlargedRenderPassTexture) {
- gfx::Rect viewport_rect(this->device_viewport_size_);
-
- int root_pass_id = 1;
- std::unique_ptr<RenderPass> root_pass =
- CreateTestRootRenderPass(root_pass_id, viewport_rect);
-
- int child_pass_id = 2;
- gfx::Rect pass_rect(this->device_viewport_size_);
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> child_pass =
- CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
-
- gfx::Transform quad_to_target_transform;
- SharedQuadState* shared_state = CreateTestSharedQuadState(
- quad_to_target_transform, viewport_rect, child_pass.get());
-
- gfx::Rect blue_rect(0,
- 0,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* blue =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- blue->SetNew(shared_state, blue_rect, blue_rect, SK_ColorBLUE, false);
- gfx::Rect yellow_rect(0,
- this->device_viewport_size_.height() / 2,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* yellow =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- yellow->SetNew(shared_state, yellow_rect, yellow_rect, SK_ColorYELLOW, false);
-
- SharedQuadState* pass_shared_state =
- CreateTestSharedQuadState(gfx::Transform(), pass_rect, root_pass.get());
- CreateTestRenderPassDrawQuad(
- pass_shared_state, pass_rect, child_pass_id, root_pass.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(child_pass));
- pass_list.push_back(std::move(root_pass));
-
- this->renderer_->SetEnlargePassTextureAmountForTesting(gfx::Size(50, 75));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")),
- ExactPixelComparator(true)));
-}
-
-TYPED_TEST(RendererPixelTest, EnlargedRenderPassTextureWithAntiAliasing) {
- gfx::Rect viewport_rect(this->device_viewport_size_);
-
- int root_pass_id = 1;
- std::unique_ptr<RenderPass> root_pass =
- CreateTestRootRenderPass(root_pass_id, viewport_rect);
-
- int child_pass_id = 2;
- gfx::Rect pass_rect(this->device_viewport_size_);
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> child_pass =
- CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
-
- gfx::Transform quad_to_target_transform;
- SharedQuadState* shared_state = CreateTestSharedQuadState(
- quad_to_target_transform, viewport_rect, child_pass.get());
-
- gfx::Rect blue_rect(0,
- 0,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* blue =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- blue->SetNew(shared_state, blue_rect, blue_rect, SK_ColorBLUE, false);
- gfx::Rect yellow_rect(0,
- this->device_viewport_size_.height() / 2,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* yellow =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- yellow->SetNew(shared_state, yellow_rect, yellow_rect, SK_ColorYELLOW, false);
-
- gfx::Transform aa_transform;
- aa_transform.Translate(0.5, 0.0);
-
- SharedQuadState* pass_shared_state =
- CreateTestSharedQuadState(aa_transform, pass_rect, root_pass.get());
- CreateTestRenderPassDrawQuad(
- pass_shared_state, pass_rect, child_pass_id, root_pass.get());
-
- SharedQuadState* root_shared_state = CreateTestSharedQuadState(
- gfx::Transform(), viewport_rect, root_pass.get());
- SolidColorDrawQuad* background =
- root_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- background->SetNew(root_shared_state,
- gfx::Rect(this->device_viewport_size_),
- gfx::Rect(this->device_viewport_size_),
- SK_ColorWHITE,
- false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(child_pass));
- pass_list.push_back(std::move(root_pass));
-
- this->renderer_->SetEnlargePassTextureAmountForTesting(gfx::Size(50, 75));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("blue_yellow_anti_aliasing.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-// This tests the case where we have a RenderPass with a mask, but the quad
-// for the masked surface does not include the full surface texture.
-TYPED_TEST(RendererPixelTest, RenderPassAndMaskWithPartialQuad) {
- gfx::Rect viewport_rect(this->device_viewport_size_);
-
- int root_pass_id = 1;
- std::unique_ptr<RenderPass> root_pass =
- CreateTestRootRenderPass(root_pass_id, viewport_rect);
- SharedQuadState* root_pass_shared_state = CreateTestSharedQuadState(
- gfx::Transform(), viewport_rect, root_pass.get());
-
- int child_pass_id = 2;
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> child_pass =
- CreateTestRenderPass(child_pass_id, viewport_rect, transform_to_root);
- SharedQuadState* child_pass_shared_state = CreateTestSharedQuadState(
- gfx::Transform(), viewport_rect, child_pass.get());
-
- // The child render pass is just a green box.
- static const SkColor kCSSGreen = 0xff008000;
- SolidColorDrawQuad* green =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- green->SetNew(
- child_pass_shared_state, viewport_rect, viewport_rect, kCSSGreen, false);
-
- // Make a mask.
- gfx::Rect mask_rect = viewport_rect;
- SkBitmap bitmap;
- bitmap.allocPixels(
- SkImageInfo::MakeN32Premul(mask_rect.width(), mask_rect.height()));
- SkiaPaintCanvas canvas(bitmap);
- PaintFlags flags;
- flags.setStyle(PaintFlags::kStroke_Style);
- flags.setStrokeWidth(SkIntToScalar(4));
- flags.setColor(SK_ColorWHITE);
- canvas.clear(SK_ColorTRANSPARENT);
- gfx::Rect rect = mask_rect;
- while (!rect.IsEmpty()) {
- rect.Inset(6, 6, 4, 4);
- canvas.drawRect(
- SkRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()),
- flags);
- rect.Inset(6, 6, 4, 4);
- }
-
- viz::ResourceId mask_resource_id = this->resource_provider_->CreateResource(
- mask_rect.size(), ResourceProvider::TEXTURE_HINT_IMMUTABLE,
- viz::RGBA_8888, gfx::ColorSpace());
-
- this->resource_provider_->CopyToResource(
- mask_resource_id, reinterpret_cast<uint8_t*>(bitmap.getPixels()),
- mask_rect.size());
-
- // This RenderPassDrawQuad does not include the full |viewport_rect| which is
- // the size of the child render pass.
- gfx::Rect sub_rect = gfx::Rect(50, 50, 200, 100);
- EXPECT_NE(sub_rect.x(), child_pass->output_rect.x());
- EXPECT_NE(sub_rect.y(), child_pass->output_rect.y());
- EXPECT_NE(sub_rect.right(), child_pass->output_rect.right());
- EXPECT_NE(sub_rect.bottom(), child_pass->output_rect.bottom());
-
- // Set up a mask on the RenderPassDrawQuad.
- RenderPassDrawQuad* mask_quad =
- root_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- mask_quad->SetNew(
- root_pass_shared_state, sub_rect, sub_rect, child_pass_id,
- mask_resource_id,
- gfx::ScaleRect(gfx::RectF(sub_rect), 2.f / mask_rect.width(),
- 2.f / mask_rect.height()), // mask_uv_rect
- gfx::Size(mask_rect.size()), // mask_texture_size
- gfx::Vector2dF(), // filters scale
- gfx::PointF(), // filter origin
- gfx::RectF(sub_rect)); // tex_coord_rect
-
- // White background behind the masked render pass.
- SolidColorDrawQuad* white =
- root_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- white->SetNew(root_pass_shared_state,
- viewport_rect,
- viewport_rect,
- SK_ColorWHITE,
- false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(child_pass));
- pass_list.push_back(std::move(root_pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("mask_bottom_right.png")),
- ExactPixelComparator(true)));
-}
-
-// This tests the case where we have a RenderPass with a mask, but the quad
-// for the masked surface does not include the full surface texture.
-TYPED_TEST(RendererPixelTest, RenderPassAndMaskWithPartialQuad2) {
- gfx::Rect viewport_rect(this->device_viewport_size_);
-
- int root_pass_id = 1;
- std::unique_ptr<RenderPass> root_pass =
- CreateTestRootRenderPass(root_pass_id, viewport_rect);
- SharedQuadState* root_pass_shared_state = CreateTestSharedQuadState(
- gfx::Transform(), viewport_rect, root_pass.get());
-
- int child_pass_id = 2;
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> child_pass =
- CreateTestRenderPass(child_pass_id, viewport_rect, transform_to_root);
- SharedQuadState* child_pass_shared_state = CreateTestSharedQuadState(
- gfx::Transform(), viewport_rect, child_pass.get());
-
- // The child render pass is just a green box.
- static const SkColor kCSSGreen = 0xff008000;
- SolidColorDrawQuad* green =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- green->SetNew(child_pass_shared_state, viewport_rect, viewport_rect,
- kCSSGreen, false);
-
- // Make a mask.
- gfx::Rect mask_rect = viewport_rect;
- SkBitmap bitmap;
- bitmap.allocPixels(
- SkImageInfo::MakeN32Premul(mask_rect.width(), mask_rect.height()));
- SkiaPaintCanvas canvas(bitmap);
- PaintFlags flags;
- flags.setStyle(PaintFlags::kStroke_Style);
- flags.setStrokeWidth(SkIntToScalar(4));
- flags.setColor(SK_ColorWHITE);
- canvas.clear(SK_ColorTRANSPARENT);
- gfx::Rect rect = mask_rect;
- while (!rect.IsEmpty()) {
- rect.Inset(6, 6, 4, 4);
- canvas.drawRect(
- SkRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()),
- flags);
- rect.Inset(6, 6, 4, 4);
- }
-
- viz::ResourceId mask_resource_id = this->resource_provider_->CreateResource(
- mask_rect.size(), ResourceProvider::TEXTURE_HINT_IMMUTABLE,
- viz::RGBA_8888, gfx::ColorSpace());
-
- this->resource_provider_->CopyToResource(
- mask_resource_id, reinterpret_cast<uint8_t*>(bitmap.getPixels()),
- mask_rect.size());
-
- // This RenderPassDrawQuad does not include the full |viewport_rect| which is
- // the size of the child render pass.
- gfx::Rect sub_rect = gfx::Rect(50, 20, 200, 60);
- EXPECT_NE(sub_rect.x(), child_pass->output_rect.x());
- EXPECT_NE(sub_rect.y(), child_pass->output_rect.y());
- EXPECT_NE(sub_rect.right(), child_pass->output_rect.right());
- EXPECT_NE(sub_rect.bottom(), child_pass->output_rect.bottom());
-
- // Set up a mask on the RenderPassDrawQuad.
- RenderPassDrawQuad* mask_quad =
- root_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- mask_quad->SetNew(
- root_pass_shared_state, sub_rect, sub_rect, child_pass_id,
- mask_resource_id,
- gfx::ScaleRect(gfx::RectF(sub_rect), 2.f / mask_rect.width(),
- 2.f / mask_rect.height()), // mask_uv_rect
- gfx::Size(mask_rect.size()), // mask_texture_size
- gfx::Vector2dF(), // filters scale
- gfx::PointF(), // filter origin
- gfx::RectF(sub_rect)); // tex_coord_rect
-
- // White background behind the masked render pass.
- SolidColorDrawQuad* white =
- root_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- white->SetNew(root_pass_shared_state, viewport_rect, viewport_rect,
- SK_ColorWHITE, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(child_pass));
- pass_list.push_back(std::move(root_pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list, base::FilePath(FILE_PATH_LITERAL("mask_middle.png")),
- ExactPixelComparator(true)));
-}
-
-template <typename RendererType>
-class RendererPixelTestWithBackgroundFilter
- : public RendererPixelTest<RendererType> {
- protected:
- void SetUpRenderPassList() {
- gfx::Rect device_viewport_rect(this->device_viewport_size_);
-
- int root_id = 1;
- std::unique_ptr<RenderPass> root_pass =
- CreateTestRootRenderPass(root_id, device_viewport_rect);
- root_pass->has_transparent_background = false;
-
- gfx::Transform identity_quad_to_target_transform;
-
- int filter_pass_id = 2;
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> filter_pass = CreateTestRenderPass(
- filter_pass_id, filter_pass_layer_rect_, transform_to_root);
- filter_pass->background_filters = this->background_filters_;
-
- // A non-visible quad in the filtering render pass.
- {
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(identity_quad_to_target_transform,
- filter_pass_layer_rect_, filter_pass.get());
- SolidColorDrawQuad* color_quad =
- filter_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(shared_state, filter_pass_layer_rect_,
- filter_pass_layer_rect_, SK_ColorTRANSPARENT, false);
- }
-
- {
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(filter_pass_to_target_transform_,
- filter_pass_layer_rect_, filter_pass.get());
- RenderPassDrawQuad* filter_pass_quad =
- root_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- filter_pass_quad->SetNew(shared_state, filter_pass_layer_rect_,
- filter_pass_layer_rect_, filter_pass_id,
- 0, // mask_resource_id
- gfx::RectF(), // mask_uv_rect
- gfx::Size(), // mask_texture_size
- gfx::Vector2dF(1.0f, 1.0f), // filters_scale
- gfx::PointF(), // filters_origin
- gfx::RectF()); // tex_coord_rect
- }
-
- const int kColumnWidth = device_viewport_rect.width() / 3;
-
- gfx::Rect left_rect = gfx::Rect(0, 0, kColumnWidth, 20);
- for (int i = 0; left_rect.y() < device_viewport_rect.height(); ++i) {
- SharedQuadState* shared_state = CreateTestSharedQuadState(
- identity_quad_to_target_transform, left_rect, root_pass.get());
- SolidColorDrawQuad* color_quad =
- root_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(
- shared_state, left_rect, left_rect, SK_ColorGREEN, false);
- left_rect += gfx::Vector2d(0, left_rect.height() + 1);
- }
-
- gfx::Rect middle_rect = gfx::Rect(kColumnWidth+1, 0, kColumnWidth, 20);
- for (int i = 0; middle_rect.y() < device_viewport_rect.height(); ++i) {
- SharedQuadState* shared_state = CreateTestSharedQuadState(
- identity_quad_to_target_transform, middle_rect, root_pass.get());
- SolidColorDrawQuad* color_quad =
- root_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(
- shared_state, middle_rect, middle_rect, SK_ColorRED, false);
- middle_rect += gfx::Vector2d(0, middle_rect.height() + 1);
- }
-
- gfx::Rect right_rect = gfx::Rect((kColumnWidth+1)*2, 0, kColumnWidth, 20);
- for (int i = 0; right_rect.y() < device_viewport_rect.height(); ++i) {
- SharedQuadState* shared_state = CreateTestSharedQuadState(
- identity_quad_to_target_transform, right_rect, root_pass.get());
- SolidColorDrawQuad* color_quad =
- root_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(
- shared_state, right_rect, right_rect, SK_ColorBLUE, false);
- right_rect += gfx::Vector2d(0, right_rect.height() + 1);
- }
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(identity_quad_to_target_transform,
- device_viewport_rect, root_pass.get());
- SolidColorDrawQuad* background_quad =
- root_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- background_quad->SetNew(shared_state,
- device_viewport_rect,
- device_viewport_rect,
- SK_ColorWHITE,
- false);
-
- pass_list_.push_back(std::move(filter_pass));
- pass_list_.push_back(std::move(root_pass));
- }
-
- RenderPassList pass_list_;
- FilterOperations background_filters_;
- gfx::Transform filter_pass_to_target_transform_;
- gfx::Rect filter_pass_layer_rect_;
-};
-
-typedef ::testing::Types<viz::GLRenderer, SoftwareRenderer>
- BackgroundFilterRendererTypes;
-TYPED_TEST_CASE(RendererPixelTestWithBackgroundFilter,
- BackgroundFilterRendererTypes);
-
-typedef RendererPixelTestWithBackgroundFilter<viz::GLRenderer>
- GLRendererPixelTestWithBackgroundFilter;
-
-// TODO(skaslev): The software renderer does not support filters yet.
-TEST_F(GLRendererPixelTestWithBackgroundFilter, InvertFilter) {
- this->background_filters_.Append(
- FilterOperation::CreateInvertFilter(1.f));
-
- this->filter_pass_layer_rect_ = gfx::Rect(this->device_viewport_size_);
- this->filter_pass_layer_rect_.Inset(12, 14, 16, 18);
-
- this->SetUpRenderPassList();
- EXPECT_TRUE(this->RunPixelTest(
- &this->pass_list_,
- base::FilePath(FILE_PATH_LITERAL("background_filter.png")),
- ExactPixelComparator(true)));
-}
-
-class ExternalStencilPixelTest : public GLRendererPixelTest {
- protected:
- void ClearBackgroundToGreen() {
- GLES2Interface* gl = output_surface_->context_provider()->ContextGL();
- output_surface_->EnsureBackbuffer();
- output_surface_->Reshape(device_viewport_size_, 1, gfx::ColorSpace(), true,
- false);
- gl->ClearColor(0.f, 1.f, 0.f, 1.f);
- gl->Clear(GL_COLOR_BUFFER_BIT);
- }
-
- void PopulateStencilBuffer() {
- // Set two quadrants of the stencil buffer to 1.
- GLES2Interface* gl = output_surface_->context_provider()->ContextGL();
- output_surface_->EnsureBackbuffer();
- output_surface_->Reshape(device_viewport_size_, 1, gfx::ColorSpace(), true,
- false);
- gl->ClearStencil(0);
- gl->Clear(GL_STENCIL_BUFFER_BIT);
- gl->Enable(GL_SCISSOR_TEST);
- gl->ClearStencil(1);
- gl->Scissor(0,
- 0,
- device_viewport_size_.width() / 2,
- device_viewport_size_.height() / 2);
- gl->Clear(GL_STENCIL_BUFFER_BIT);
- gl->Scissor(device_viewport_size_.width() / 2,
- device_viewport_size_.height() / 2,
- device_viewport_size_.width(),
- device_viewport_size_.height());
- gl->Clear(GL_STENCIL_BUFFER_BIT);
- gl->StencilFunc(GL_EQUAL, 1, 1);
- }
-};
-
-TEST_F(ExternalStencilPixelTest, StencilTestEnabled) {
- ClearBackgroundToGreen();
- PopulateStencilBuffer();
- this->EnableExternalStencilTest();
-
- // Draw a blue quad that covers the entire device viewport. It should be
- // clipped to the bottom left and top right corners by the external stencil.
- gfx::Rect rect(this->device_viewport_size_);
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
- SharedQuadState* blue_shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
- SolidColorDrawQuad* blue =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- blue->SetNew(blue_shared_state, rect, rect, SK_ColorBLUE, false);
- pass->has_transparent_background = false;
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
- ExactPixelComparator(true)));
-}
-
-TEST_F(ExternalStencilPixelTest, StencilTestDisabled) {
- PopulateStencilBuffer();
-
- // Draw a green quad that covers the entire device viewport. The stencil
- // buffer should be ignored.
- gfx::Rect rect(this->device_viewport_size_);
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
- SharedQuadState* green_shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
- SolidColorDrawQuad* green =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- green->SetNew(green_shared_state, rect, rect, SK_ColorGREEN, false);
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("green.png")),
- ExactPixelComparator(true)));
-}
-
-TEST_F(ExternalStencilPixelTest, RenderSurfacesIgnoreStencil) {
- // The stencil test should apply only to the final render pass.
- ClearBackgroundToGreen();
- PopulateStencilBuffer();
- this->EnableExternalStencilTest();
-
- gfx::Rect viewport_rect(this->device_viewport_size_);
-
- int root_pass_id = 1;
- std::unique_ptr<RenderPass> root_pass =
- CreateTestRootRenderPass(root_pass_id, viewport_rect);
- root_pass->has_transparent_background = false;
-
- int child_pass_id = 2;
- gfx::Rect pass_rect(this->device_viewport_size_);
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> child_pass =
- CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
-
- gfx::Transform quad_to_target_transform;
- SharedQuadState* shared_state = CreateTestSharedQuadState(
- quad_to_target_transform, viewport_rect, child_pass.get());
-
- gfx::Rect blue_rect(0,
- 0,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height());
- SolidColorDrawQuad* blue =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- blue->SetNew(shared_state, blue_rect, blue_rect, SK_ColorBLUE, false);
-
- SharedQuadState* pass_shared_state =
- CreateTestSharedQuadState(gfx::Transform(), pass_rect, root_pass.get());
- CreateTestRenderPassDrawQuad(
- pass_shared_state, pass_rect, child_pass_id, root_pass.get());
- RenderPassList pass_list;
- pass_list.push_back(std::move(child_pass));
- pass_list.push_back(std::move(root_pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
- ExactPixelComparator(true)));
-}
-
-// Software renderer does not support anti-aliased edges.
-TEST_F(GLRendererPixelTest, AntiAliasing) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- gfx::Transform red_quad_to_target_transform;
- red_quad_to_target_transform.Rotate(10);
- SharedQuadState* red_shared_state =
- CreateTestSharedQuadState(red_quad_to_target_transform, rect, pass.get());
-
- SolidColorDrawQuad* red = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- red->SetNew(red_shared_state, rect, rect, SK_ColorRED, false);
-
- gfx::Transform yellow_quad_to_target_transform;
- yellow_quad_to_target_transform.Rotate(5);
- SharedQuadState* yellow_shared_state = CreateTestSharedQuadState(
- yellow_quad_to_target_transform, rect, pass.get());
-
- SolidColorDrawQuad* yellow =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- yellow->SetNew(yellow_shared_state, rect, rect, SK_ColorYELLOW, false);
-
- gfx::Transform blue_quad_to_target_transform;
- SharedQuadState* blue_shared_state = CreateTestSharedQuadState(
- blue_quad_to_target_transform, rect, pass.get());
-
- SolidColorDrawQuad* blue =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- blue->SetNew(blue_shared_state, rect, rect, SK_ColorBLUE, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("anti_aliasing.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-// This test tests that anti-aliasing works for axis aligned quads.
-// Anti-aliasing is only supported in the gl renderer.
-TEST_F(GLRendererPixelTest, AxisAligned) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> pass =
- CreateTestRenderPass(id, rect, transform_to_root);
-
- gfx::Transform red_quad_to_target_transform;
- red_quad_to_target_transform.Translate(50, 50);
- red_quad_to_target_transform.Scale(0.5f + 1.0f / (rect.width() * 2.0f),
- 0.5f + 1.0f / (rect.height() * 2.0f));
- SharedQuadState* red_shared_state =
- CreateTestSharedQuadState(red_quad_to_target_transform, rect, pass.get());
-
- SolidColorDrawQuad* red = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- red->SetNew(red_shared_state, rect, rect, SK_ColorRED, false);
-
- gfx::Transform yellow_quad_to_target_transform;
- yellow_quad_to_target_transform.Translate(25.5f, 25.5f);
- yellow_quad_to_target_transform.Scale(0.5f, 0.5f);
- SharedQuadState* yellow_shared_state = CreateTestSharedQuadState(
- yellow_quad_to_target_transform, rect, pass.get());
-
- SolidColorDrawQuad* yellow =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- yellow->SetNew(yellow_shared_state, rect, rect, SK_ColorYELLOW, false);
-
- gfx::Transform blue_quad_to_target_transform;
- SharedQuadState* blue_shared_state = CreateTestSharedQuadState(
- blue_quad_to_target_transform, rect, pass.get());
-
- SolidColorDrawQuad* blue =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- blue->SetNew(blue_shared_state, rect, rect, SK_ColorBLUE, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("axis_aligned.png")),
- ExactPixelComparator(true)));
-}
-
-// This test tests that forcing anti-aliasing off works as expected.
-// Anti-aliasing is only supported in the gl renderer.
-TEST_F(GLRendererPixelTest, ForceAntiAliasingOff) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> pass =
- CreateTestRenderPass(id, rect, transform_to_root);
-
- gfx::Transform hole_quad_to_target_transform;
- hole_quad_to_target_transform.Translate(50, 50);
- hole_quad_to_target_transform.Scale(0.5f + 1.0f / (rect.width() * 2.0f),
- 0.5f + 1.0f / (rect.height() * 2.0f));
- SharedQuadState* hole_shared_state = CreateTestSharedQuadState(
- hole_quad_to_target_transform, rect, pass.get());
-
- SolidColorDrawQuad* hole =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- hole->SetAll(hole_shared_state, rect, rect, false, SK_ColorTRANSPARENT, true);
-
- gfx::Transform green_quad_to_target_transform;
- SharedQuadState* green_shared_state = CreateTestSharedQuadState(
- green_quad_to_target_transform, rect, pass.get());
-
- SolidColorDrawQuad* green =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- green->SetNew(green_shared_state, rect, rect, SK_ColorGREEN, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("force_anti_aliasing_off.png")),
- ExactPixelComparator(false)));
-}
-
-TEST_F(GLRendererPixelTest, AntiAliasingPerspective) {
- gfx::Rect rect(this->device_viewport_size_);
-
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(1, rect);
-
- gfx::Rect red_rect(0, 0, 180, 500);
- gfx::Transform red_quad_to_target_transform(
- 1.0f, 2.4520f, 10.6206f, 19.0f, 0.0f, 0.3528f, 5.9737f, 9.5f, 0.0f,
- -0.2250f, -0.9744f, 0.0f, 0.0f, 0.0225f, 0.0974f, 1.0f);
- SharedQuadState* red_shared_state = CreateTestSharedQuadState(
- red_quad_to_target_transform, red_rect, pass.get());
- SolidColorDrawQuad* red = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- red->SetNew(red_shared_state, red_rect, red_rect, SK_ColorRED, false);
-
- gfx::Rect green_rect(19, 7, 180, 10);
- SharedQuadState* green_shared_state =
- CreateTestSharedQuadState(gfx::Transform(), green_rect, pass.get());
- SolidColorDrawQuad* green =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- green->SetNew(
- green_shared_state, green_rect, green_rect, SK_ColorGREEN, false);
-
- SharedQuadState* blue_shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
- SolidColorDrawQuad* blue =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- blue->SetNew(blue_shared_state, rect, rect, SK_ColorBLUE, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("anti_aliasing_perspective.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-TYPED_TEST(SoftwareRendererPixelTest, PictureDrawQuadIdentityScale) {
- gfx::Rect viewport(this->device_viewport_size_);
- // TODO(enne): the renderer should figure this out on its own.
- viz::ResourceFormat texture_format = viz::RGBA_8888;
- bool nearest_neighbor = false;
-
- int id = 1;
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> pass =
- CreateTestRenderPass(id, viewport, transform_to_root);
-
- // One clipped blue quad in the lower right corner. Outside the clip
- // is red, which should not appear.
- gfx::Rect blue_rect(gfx::Size(100, 100));
- gfx::Rect blue_clip_rect(gfx::Point(50, 50), gfx::Size(50, 50));
-
- std::unique_ptr<FakeRecordingSource> blue_recording =
- FakeRecordingSource::CreateFilledRecordingSource(blue_rect.size());
- PaintFlags red_flags;
- red_flags.setColor(SK_ColorRED);
- blue_recording->add_draw_rect_with_flags(blue_rect, red_flags);
- PaintFlags blue_flags;
- blue_flags.setColor(SK_ColorBLUE);
- blue_recording->add_draw_rect_with_flags(blue_clip_rect, blue_flags);
- blue_recording->Rerecord();
-
- scoped_refptr<RasterSource> blue_raster_source =
- blue_recording->CreateRasterSource();
-
- gfx::Vector2d offset(viewport.bottom_right() - blue_rect.bottom_right());
- bool needs_blending = true;
- gfx::Transform blue_quad_to_target_transform;
- blue_quad_to_target_transform.Translate(offset.x(), offset.y());
- gfx::Rect blue_target_clip_rect = MathUtil::MapEnclosingClippedRect(
- blue_quad_to_target_transform, blue_clip_rect);
- SharedQuadState* blue_shared_state =
- CreateTestSharedQuadStateClipped(blue_quad_to_target_transform, blue_rect,
- blue_target_clip_rect, pass.get());
-
- PictureDrawQuad* blue_quad = pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
-
- blue_quad->SetNew(blue_shared_state,
- viewport, // Intentionally bigger than clip.
- viewport, needs_blending, gfx::RectF(viewport),
- viewport.size(), nearest_neighbor, texture_format, viewport,
- 1.f, std::move(blue_raster_source));
-
- // One viewport-filling green quad.
- std::unique_ptr<FakeRecordingSource> green_recording =
- FakeRecordingSource::CreateFilledRecordingSource(viewport.size());
- PaintFlags green_flags;
- green_flags.setColor(SK_ColorGREEN);
- green_recording->add_draw_rect_with_flags(viewport, green_flags);
- green_recording->Rerecord();
- scoped_refptr<RasterSource> green_raster_source =
- green_recording->CreateRasterSource();
-
- gfx::Transform green_quad_to_target_transform;
- SharedQuadState* green_shared_state = CreateTestSharedQuadState(
- green_quad_to_target_transform, viewport, pass.get());
-
- PictureDrawQuad* green_quad =
- pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
- green_quad->SetNew(green_shared_state, viewport, viewport, needs_blending,
- gfx::RectF(0.f, 0.f, 1.f, 1.f), viewport.size(),
- nearest_neighbor, texture_format, viewport, 1.f,
- std::move(green_raster_source));
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("green_with_blue_corner.png")),
- ExactPixelComparator(true)));
-}
-
-// Not WithSkiaGPUBackend since that path currently requires tiles for opacity.
-TYPED_TEST(SoftwareRendererPixelTest, PictureDrawQuadOpacity) {
- gfx::Rect viewport(this->device_viewport_size_);
- bool needs_blending = true;
- viz::ResourceFormat texture_format = viz::RGBA_8888;
- bool nearest_neighbor = false;
-
- int id = 1;
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> pass =
- CreateTestRenderPass(id, viewport, transform_to_root);
-
- // One viewport-filling 0.5-opacity green quad.
- std::unique_ptr<FakeRecordingSource> green_recording =
- FakeRecordingSource::CreateFilledRecordingSource(viewport.size());
- PaintFlags green_flags;
- green_flags.setColor(SK_ColorGREEN);
- green_recording->add_draw_rect_with_flags(viewport, green_flags);
- green_recording->Rerecord();
- scoped_refptr<RasterSource> green_raster_source =
- green_recording->CreateRasterSource();
-
- gfx::Transform green_quad_to_target_transform;
- SharedQuadState* green_shared_state = CreateTestSharedQuadState(
- green_quad_to_target_transform, viewport, pass.get());
- green_shared_state->opacity = 0.5f;
-
- PictureDrawQuad* green_quad =
- pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
- green_quad->SetNew(green_shared_state, viewport, viewport, needs_blending,
- gfx::RectF(0, 0, 1, 1), viewport.size(), nearest_neighbor,
- texture_format, viewport, 1.f, green_raster_source.get());
-
- // One viewport-filling white quad.
- std::unique_ptr<FakeRecordingSource> white_recording =
- FakeRecordingSource::CreateFilledRecordingSource(viewport.size());
- PaintFlags white_flags;
- white_flags.setColor(SK_ColorWHITE);
- white_recording->add_draw_rect_with_flags(viewport, white_flags);
- white_recording->Rerecord();
- scoped_refptr<RasterSource> white_raster_source =
- white_recording->CreateRasterSource();
-
- gfx::Transform white_quad_to_target_transform;
- SharedQuadState* white_shared_state = CreateTestSharedQuadState(
- white_quad_to_target_transform, viewport, pass.get());
-
- PictureDrawQuad* white_quad =
- pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
- white_quad->SetNew(white_shared_state, viewport, viewport, needs_blending,
- gfx::RectF(0, 0, 1, 1), viewport.size(), nearest_neighbor,
- texture_format, viewport, 1.f,
- std::move(white_raster_source));
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("green_alpha.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-template<typename TypeParam> bool IsSoftwareRenderer() {
- return false;
-}
-
-template<>
-bool IsSoftwareRenderer<SoftwareRenderer>() {
- return true;
-}
-
-template<>
-bool IsSoftwareRenderer<SoftwareRendererWithExpandedViewport>() {
- return true;
-}
-
-void draw_point_color(SkCanvas* canvas, SkScalar x, SkScalar y, SkColor color) {
- SkPaint paint;
- paint.setColor(color);
- canvas->drawPoint(x, y, paint);
-}
-
-// If we disable image filtering, then a 2x2 bitmap should appear as four
-// huge sharp squares.
-TYPED_TEST(SoftwareRendererPixelTest, PictureDrawQuadDisableImageFiltering) {
- // We only care about this in software mode since bilinear filtering is
- // cheap in hardware.
- if (!IsSoftwareRenderer<TypeParam>())
- return;
-
- gfx::Rect viewport(this->device_viewport_size_);
- viz::ResourceFormat texture_format = viz::RGBA_8888;
- bool needs_blending = true;
- bool nearest_neighbor = false;
-
- int id = 1;
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> pass =
- CreateTestRenderPass(id, viewport, transform_to_root);
-
- sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(2, 2);
- ASSERT_NE(surface, nullptr);
- SkCanvas* canvas = surface->getCanvas();
- draw_point_color(canvas, 0, 0, SK_ColorGREEN);
- draw_point_color(canvas, 0, 1, SK_ColorBLUE);
- draw_point_color(canvas, 1, 0, SK_ColorBLUE);
- draw_point_color(canvas, 1, 1, SK_ColorGREEN);
-
- std::unique_ptr<FakeRecordingSource> recording =
- FakeRecordingSource::CreateFilledRecordingSource(viewport.size());
- PaintFlags flags;
- flags.setFilterQuality(kLow_SkFilterQuality);
- recording->add_draw_image_with_flags(surface->makeImageSnapshot(),
- gfx::Point(), flags);
- recording->Rerecord();
- scoped_refptr<RasterSource> raster_source = recording->CreateRasterSource();
-
- gfx::Transform quad_to_target_transform;
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(quad_to_target_transform, viewport, pass.get());
-
- PictureDrawQuad* quad = pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
- quad->SetNew(shared_state, viewport, viewport, needs_blending,
- gfx::RectF(0, 0, 2, 2), viewport.size(), nearest_neighbor,
- texture_format, viewport, 1.f, std::move(raster_source));
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- this->disable_picture_quad_image_filtering_ = true;
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
- ExactPixelComparator(true)));
-}
-
-// This disables filtering by setting |nearest_neighbor| on the PictureDrawQuad.
-TYPED_TEST(SoftwareRendererPixelTest, PictureDrawQuadNearestNeighbor) {
- gfx::Rect viewport(this->device_viewport_size_);
- viz::ResourceFormat texture_format = viz::RGBA_8888;
- bool needs_blending = true;
- bool nearest_neighbor = true;
-
- int id = 1;
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> pass =
- CreateTestRenderPass(id, viewport, transform_to_root);
-
- sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(2, 2);
- ASSERT_NE(surface, nullptr);
- SkCanvas* canvas = surface->getCanvas();
- draw_point_color(canvas, 0, 0, SK_ColorGREEN);
- draw_point_color(canvas, 0, 1, SK_ColorBLUE);
- draw_point_color(canvas, 1, 0, SK_ColorBLUE);
- draw_point_color(canvas, 1, 1, SK_ColorGREEN);
-
- std::unique_ptr<FakeRecordingSource> recording =
- FakeRecordingSource::CreateFilledRecordingSource(viewport.size());
- PaintFlags flags;
- flags.setFilterQuality(kLow_SkFilterQuality);
- recording->add_draw_image_with_flags(surface->makeImageSnapshot(),
- gfx::Point(), flags);
- recording->Rerecord();
- scoped_refptr<RasterSource> raster_source = recording->CreateRasterSource();
-
- gfx::Transform quad_to_target_transform;
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(quad_to_target_transform, viewport, pass.get());
-
- PictureDrawQuad* quad = pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
- quad->SetNew(shared_state, viewport, viewport, needs_blending,
- gfx::RectF(0, 0, 2, 2), viewport.size(), nearest_neighbor,
- texture_format, viewport, 1.f, std::move(raster_source));
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
- ExactPixelComparator(true)));
-}
-
-// This disables filtering by setting |nearest_neighbor| on the TileDrawQuad.
-TYPED_TEST(RendererPixelTest, TileDrawQuadNearestNeighbor) {
- gfx::Rect viewport(this->device_viewport_size_);
- bool swizzle_contents = true;
- bool needs_blending = true;
- bool nearest_neighbor = true;
-
- SkBitmap bitmap;
- bitmap.allocN32Pixels(2, 2);
- SkCanvas canvas(bitmap);
- draw_point_color(&canvas, 0, 0, SK_ColorGREEN);
- draw_point_color(&canvas, 0, 1, SK_ColorBLUE);
- draw_point_color(&canvas, 1, 0, SK_ColorBLUE);
- draw_point_color(&canvas, 1, 1, SK_ColorGREEN);
-
- gfx::Size tile_size(2, 2);
- viz::ResourceId resource = this->resource_provider_->CreateResource(
- tile_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, viz::RGBA_8888,
- gfx::ColorSpace());
-
- this->resource_provider_->CopyToResource(
- resource, static_cast<uint8_t*>(bitmap.getPixels()), tile_size);
-
- int id = 1;
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> pass =
- CreateTestRenderPass(id, viewport, transform_to_root);
-
- gfx::Transform quad_to_target_transform;
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(quad_to_target_transform, viewport, pass.get());
-
- TileDrawQuad* quad = pass->CreateAndAppendDrawQuad<TileDrawQuad>();
- quad->SetNew(shared_state, viewport, viewport, needs_blending, resource,
- gfx::RectF(gfx::Rect(tile_size)), tile_size, swizzle_contents,
- nearest_neighbor);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
- ExactPixelComparator(true)));
-}
-
-// This disables filtering by setting |nearest_neighbor| to true on the
-// TextureDrawQuad.
-TYPED_TEST(SoftwareRendererPixelTest, TextureDrawQuadNearestNeighbor) {
- gfx::Rect viewport(this->device_viewport_size_);
- bool needs_blending = true;
- bool nearest_neighbor = true;
-
- SkBitmap bitmap;
- bitmap.allocN32Pixels(2, 2);
- SkCanvas canvas(bitmap);
- draw_point_color(&canvas, 0, 0, SK_ColorGREEN);
- draw_point_color(&canvas, 0, 1, SK_ColorBLUE);
- draw_point_color(&canvas, 1, 0, SK_ColorBLUE);
- draw_point_color(&canvas, 1, 1, SK_ColorGREEN);
-
- gfx::Size tile_size(2, 2);
- viz::ResourceId resource = this->resource_provider_->CreateResource(
- tile_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, viz::RGBA_8888,
- gfx::ColorSpace());
-
- this->resource_provider_->CopyToResource(
- resource, static_cast<uint8_t*>(bitmap.getPixels()), tile_size);
-
- int id = 1;
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> pass =
- CreateTestRenderPass(id, viewport, transform_to_root);
-
- gfx::Transform quad_to_target_transform;
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(quad_to_target_transform, viewport, pass.get());
-
- float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f};
- TextureDrawQuad* quad = pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
- quad->SetNew(shared_state, viewport, viewport, needs_blending, resource,
- false, gfx::PointF(0, 0), gfx::PointF(1, 1), SK_ColorBLACK,
- vertex_opacity, false, nearest_neighbor, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
- FuzzyPixelComparator(false, 2.f, 0.f, 256.f, 256, 0.f)));
-}
-
-// This ensures filtering is enabled by setting |nearest_neighbor| to false on
-// the TextureDrawQuad.
-TYPED_TEST(SoftwareRendererPixelTest, TextureDrawQuadLinear) {
- gfx::Rect viewport(this->device_viewport_size_);
- bool needs_blending = true;
- bool nearest_neighbor = false;
-
- SkBitmap bitmap;
- bitmap.allocN32Pixels(2, 2);
- {
- SkCanvas canvas(bitmap);
- draw_point_color(&canvas, 0, 0, SK_ColorGREEN);
- draw_point_color(&canvas, 0, 1, SK_ColorBLUE);
- draw_point_color(&canvas, 1, 0, SK_ColorBLUE);
- draw_point_color(&canvas, 1, 1, SK_ColorGREEN);
- }
-
- gfx::Size tile_size(2, 2);
- viz::ResourceId resource = this->resource_provider_->CreateResource(
- tile_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, viz::RGBA_8888,
- gfx::ColorSpace());
-
- this->resource_provider_->CopyToResource(
- resource, static_cast<uint8_t*>(bitmap.getPixels()), tile_size);
-
- int id = 1;
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> pass =
- CreateTestRenderPass(id, viewport, transform_to_root);
-
- gfx::Transform quad_to_target_transform;
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(quad_to_target_transform, viewport, pass.get());
-
- float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f};
- TextureDrawQuad* quad = pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
- quad->SetNew(shared_state, viewport, viewport, needs_blending, resource,
- false, gfx::PointF(0, 0), gfx::PointF(1, 1), SK_ColorBLACK,
- vertex_opacity, false, nearest_neighbor, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- // Allow for a small amount of error as the blending alogrithm used by Skia is
- // affected by the offset in the expanded rect.
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers_linear.png")),
- FuzzyPixelComparator(false, 100.f, 0.f, 16.f, 16.f, 0.f)));
-}
-
-TYPED_TEST(SoftwareRendererPixelTest, PictureDrawQuadNonIdentityScale) {
- gfx::Rect viewport(this->device_viewport_size_);
- // TODO(enne): the renderer should figure this out on its own.
- viz::ResourceFormat texture_format = viz::RGBA_8888;
- bool needs_blending = true;
- bool nearest_neighbor = false;
-
- int id = 1;
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> pass =
- CreateTestRenderPass(id, viewport, transform_to_root);
-
- // As scaling up the blue checkerboards will cause sampling on the GPU,
- // a few extra "cleanup rects" need to be added to clobber the blending
- // to make the output image more clean. This will also test subrects
- // of the layer.
- gfx::Transform green_quad_to_target_transform;
- gfx::Rect green_rect1(gfx::Point(80, 0), gfx::Size(20, 100));
- gfx::Rect green_rect2(gfx::Point(0, 80), gfx::Size(100, 20));
-
- std::unique_ptr<FakeRecordingSource> green_recording =
- FakeRecordingSource::CreateFilledRecordingSource(viewport.size());
-
- PaintFlags red_flags;
- red_flags.setColor(SK_ColorRED);
- green_recording->add_draw_rect_with_flags(viewport, red_flags);
- PaintFlags green_flags;
- green_flags.setColor(SK_ColorGREEN);
- green_recording->add_draw_rect_with_flags(green_rect1, green_flags);
- green_recording->add_draw_rect_with_flags(green_rect2, green_flags);
- green_recording->Rerecord();
- scoped_refptr<RasterSource> green_raster_source =
- green_recording->CreateRasterSource();
-
- SharedQuadState* top_right_green_shared_quad_state =
- CreateTestSharedQuadState(green_quad_to_target_transform, viewport,
- pass.get());
-
- PictureDrawQuad* green_quad1 =
- pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
- green_quad1->SetNew(top_right_green_shared_quad_state, green_rect1,
- green_rect1, needs_blending,
- gfx::RectF(gfx::SizeF(green_rect1.size())),
- green_rect1.size(), nearest_neighbor, texture_format,
- green_rect1, 1.f, green_raster_source);
-
- PictureDrawQuad* green_quad2 =
- pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
- green_quad2->SetNew(top_right_green_shared_quad_state, green_rect2,
- green_rect2, needs_blending,
- gfx::RectF(gfx::SizeF(green_rect2.size())),
- green_rect2.size(), nearest_neighbor, texture_format,
- green_rect2, 1.f, std::move(green_raster_source));
-
- // Add a green clipped checkerboard in the bottom right to help test
- // interleaving picture quad content and solid color content.
- gfx::Rect bottom_right_rect(
- gfx::Point(viewport.width() / 2, viewport.height() / 2),
- gfx::Size(viewport.width() / 2, viewport.height() / 2));
- SharedQuadState* bottom_right_green_shared_state =
- CreateTestSharedQuadStateClipped(green_quad_to_target_transform, viewport,
- bottom_right_rect, pass.get());
- SolidColorDrawQuad* bottom_right_color_quad =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- bottom_right_color_quad->SetNew(bottom_right_green_shared_state,
- viewport,
- viewport,
- SK_ColorGREEN,
- false);
-
- // Add two blue checkerboards taking up the bottom left and top right,
- // but use content scales as content rects to make this happen.
- // The content is at a 4x content scale.
- gfx::Rect layer_rect(gfx::Size(20, 30));
- float contents_scale = 4.f;
- // Two rects that touch at their corners, arbitrarily placed in the layer.
- gfx::RectF blue_layer_rect1(gfx::PointF(5.5f, 9.0f), gfx::SizeF(2.5f, 2.5f));
- gfx::RectF blue_layer_rect2(gfx::PointF(8.0f, 6.5f), gfx::SizeF(2.5f, 2.5f));
- gfx::RectF union_layer_rect = blue_layer_rect1;
- union_layer_rect.Union(blue_layer_rect2);
-
- // Because scaling up will cause sampling outside the rects, add one extra
- // pixel of buffer at the final content scale.
- float inset = -1.f / contents_scale;
- blue_layer_rect1.Inset(inset, inset, inset, inset);
- blue_layer_rect2.Inset(inset, inset, inset, inset);
-
- std::unique_ptr<FakeRecordingSource> recording =
- FakeRecordingSource::CreateFilledRecordingSource(layer_rect.size());
-
- Region outside(layer_rect);
- outside.Subtract(gfx::ToEnclosingRect(union_layer_rect));
- for (Region::Iterator iter(outside); iter.has_rect(); iter.next()) {
- recording->add_draw_rect_with_flags(iter.rect(), red_flags);
- }
-
- PaintFlags blue_flags;
- blue_flags.setColor(SK_ColorBLUE);
- recording->add_draw_rectf_with_flags(blue_layer_rect1, blue_flags);
- recording->add_draw_rectf_with_flags(blue_layer_rect2, blue_flags);
- recording->Rerecord();
- scoped_refptr<RasterSource> raster_source = recording->CreateRasterSource();
-
- gfx::Rect content_union_rect(
- gfx::ToEnclosingRect(gfx::ScaleRect(union_layer_rect, contents_scale)));
-
- // At a scale of 4x the rectangles with a width of 2.5 will take up 10 pixels,
- // so scale an additional 10x to make them 100x100.
- gfx::Transform quad_to_target_transform;
- quad_to_target_transform.Scale(10.0, 10.0);
- gfx::Rect quad_content_rect(gfx::Size(20, 20));
- SharedQuadState* blue_shared_state = CreateTestSharedQuadState(
- quad_to_target_transform, quad_content_rect, pass.get());
-
- PictureDrawQuad* blue_quad = pass->CreateAndAppendDrawQuad<PictureDrawQuad>();
- blue_quad->SetNew(blue_shared_state, quad_content_rect, quad_content_rect,
- needs_blending, gfx::RectF(quad_content_rect),
- content_union_rect.size(), nearest_neighbor, texture_format,
- content_union_rect, contents_scale,
- std::move(raster_source));
-
- // Fill left half of viewport with green.
- gfx::Transform half_green_quad_to_target_transform;
- gfx::Rect half_green_rect(gfx::Size(viewport.width() / 2, viewport.height()));
- SharedQuadState* half_green_shared_state = CreateTestSharedQuadState(
- half_green_quad_to_target_transform, half_green_rect, pass.get());
- SolidColorDrawQuad* half_color_quad =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- half_color_quad->SetNew(half_green_shared_state,
- half_green_rect,
- half_green_rect,
- SK_ColorGREEN,
- false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("four_blue_green_checkers.png")),
- ExactPixelComparator(true)));
-}
-
-typedef RendererPixelTest<GLRendererWithFlippedSurface>
- GLRendererPixelTestWithFlippedOutputSurface;
-
-TEST_F(GLRendererPixelTestWithFlippedOutputSurface, ExplicitFlipTest) {
- // This draws a blue rect above a yellow rect with an inverted output surface.
- gfx::Rect viewport_rect(this->device_viewport_size_);
-
- int root_pass_id = 1;
- std::unique_ptr<RenderPass> root_pass =
- CreateTestRootRenderPass(root_pass_id, viewport_rect);
-
- int child_pass_id = 2;
- gfx::Rect pass_rect(this->device_viewport_size_);
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> child_pass =
- CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
-
- gfx::Transform quad_to_target_transform;
- SharedQuadState* shared_state = CreateTestSharedQuadState(
- quad_to_target_transform, viewport_rect, child_pass.get());
-
- gfx::Rect blue_rect(0,
- 0,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* blue =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- blue->SetNew(shared_state, blue_rect, blue_rect, SK_ColorBLUE, false);
- gfx::Rect yellow_rect(0,
- this->device_viewport_size_.height() / 2,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* yellow =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- yellow->SetNew(shared_state, yellow_rect, yellow_rect, SK_ColorYELLOW, false);
-
- SharedQuadState* pass_shared_state =
- CreateTestSharedQuadState(gfx::Transform(), pass_rect, root_pass.get());
- CreateTestRenderPassDrawQuad(
- pass_shared_state, pass_rect, child_pass_id, root_pass.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(child_pass));
- pass_list.push_back(std::move(root_pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list,
- base::FilePath(FILE_PATH_LITERAL("blue_yellow_flipped.png")),
- ExactPixelComparator(true)));
-}
-
-TEST_F(GLRendererPixelTestWithFlippedOutputSurface, CheckChildPassUnflipped) {
- // This draws a blue rect above a yellow rect with an inverted output surface.
- gfx::Rect viewport_rect(this->device_viewport_size_);
-
- int root_pass_id = 1;
- std::unique_ptr<RenderPass> root_pass =
- CreateTestRootRenderPass(root_pass_id, viewport_rect);
-
- int child_pass_id = 2;
- gfx::Rect pass_rect(this->device_viewport_size_);
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> child_pass =
- CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
-
- gfx::Transform quad_to_target_transform;
- SharedQuadState* shared_state = CreateTestSharedQuadState(
- quad_to_target_transform, viewport_rect, child_pass.get());
-
- gfx::Rect blue_rect(0,
- 0,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* blue =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- blue->SetNew(shared_state, blue_rect, blue_rect, SK_ColorBLUE, false);
- gfx::Rect yellow_rect(0,
- this->device_viewport_size_.height() / 2,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height() / 2);
- SolidColorDrawQuad* yellow =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- yellow->SetNew(shared_state, yellow_rect, yellow_rect, SK_ColorYELLOW, false);
-
- SharedQuadState* pass_shared_state =
- CreateTestSharedQuadState(gfx::Transform(), pass_rect, root_pass.get());
- CreateTestRenderPassDrawQuad(
- pass_shared_state, pass_rect, child_pass_id, root_pass.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(child_pass));
- pass_list.push_back(std::move(root_pass));
-
- // Check that the child pass remains unflipped.
- EXPECT_TRUE(this->RunPixelTestWithReadbackTarget(
- &pass_list, pass_list.front().get(),
- base::FilePath(FILE_PATH_LITERAL("blue_yellow.png")),
- ExactPixelComparator(true)));
-}
-
-TEST_F(GLRendererPixelTest, CheckReadbackSubset) {
- gfx::Rect viewport_rect(this->device_viewport_size_);
-
- int root_pass_id = 1;
- std::unique_ptr<RenderPass> root_pass =
- CreateTestRootRenderPass(root_pass_id, viewport_rect);
-
- int child_pass_id = 2;
- gfx::Rect pass_rect(this->device_viewport_size_);
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> child_pass =
- CreateTestRenderPass(child_pass_id, pass_rect, transform_to_root);
-
- gfx::Transform quad_to_target_transform;
- SharedQuadState* shared_state = CreateTestSharedQuadState(
- quad_to_target_transform, viewport_rect, child_pass.get());
-
- // Draw a green quad full-size with a blue quad in the lower-right corner.
- gfx::Rect blue_rect(this->device_viewport_size_.width() * 3 / 4,
- this->device_viewport_size_.height() * 3 / 4,
- this->device_viewport_size_.width() * 3 / 4,
- this->device_viewport_size_.height() * 3 / 4);
- SolidColorDrawQuad* blue =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- blue->SetNew(shared_state, blue_rect, blue_rect, SK_ColorBLUE, false);
- gfx::Rect green_rect(0,
- 0,
- this->device_viewport_size_.width(),
- this->device_viewport_size_.height());
- SolidColorDrawQuad* green =
- child_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- green->SetNew(shared_state, green_rect, green_rect, SK_ColorGREEN, false);
-
- SharedQuadState* pass_shared_state =
- CreateTestSharedQuadState(gfx::Transform(), pass_rect, root_pass.get());
- CreateTestRenderPassDrawQuad(
- pass_shared_state, pass_rect, child_pass_id, root_pass.get());
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(child_pass));
- pass_list.push_back(std::move(root_pass));
-
- // Check that the child pass remains unflipped.
- gfx::Rect capture_rect(this->device_viewport_size_.width() / 2,
- this->device_viewport_size_.height() / 2,
- this->device_viewport_size_.width() / 2,
- this->device_viewport_size_.height() / 2);
- EXPECT_TRUE(this->RunPixelTestWithReadbackTargetAndArea(
- &pass_list, pass_list.front().get(),
- base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png")),
- ExactPixelComparator(true), &capture_rect));
-}
-
-TEST_F(GLRendererPixelTest, TextureQuadBatching) {
- // This test verifies that multiple texture quads using the same resource
- // get drawn correctly. It implicitly is trying to test that the
- // viz::GLRenderer does the right thing with its draw quad cache.
-
- gfx::Rect rect(this->device_viewport_size_);
- bool needs_blending = false;
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
-
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
-
- // Make a mask.
- gfx::Rect mask_rect = rect;
- SkBitmap bitmap;
- bitmap.allocPixels(
- SkImageInfo::MakeN32Premul(mask_rect.width(), mask_rect.height()));
- SkCanvas canvas(bitmap);
- SkPaint paint;
- paint.setStyle(SkPaint::kStroke_Style);
- paint.setStrokeWidth(SkIntToScalar(4));
- paint.setColor(SK_ColorGREEN);
- canvas.clear(SK_ColorWHITE);
- gfx::Rect inset_rect = rect;
- while (!inset_rect.IsEmpty()) {
- inset_rect.Inset(6, 6, 4, 4);
- canvas.drawRect(SkRect::MakeXYWH(inset_rect.x(), inset_rect.y(),
- inset_rect.width(), inset_rect.height()),
- paint);
- inset_rect.Inset(6, 6, 4, 4);
- }
-
- viz::ResourceId resource = this->resource_provider_->CreateResource(
- mask_rect.size(), ResourceProvider::TEXTURE_HINT_IMMUTABLE,
- viz::RGBA_8888, gfx::ColorSpace());
-
- this->resource_provider_->CopyToResource(
- resource, reinterpret_cast<uint8_t*>(bitmap.getPixels()),
- mask_rect.size());
-
- // Arbitrary dividing lengths to divide up the resource into 16 quads.
- int widths[] = {
- 0, 60, 50, 40,
- };
- int heights[] = {
- 0, 10, 80, 50,
- };
- size_t num_quads = 4;
- for (size_t i = 0; i < num_quads; ++i) {
- int x_start = widths[i];
- int x_end = i == num_quads - 1 ? rect.width() : widths[i + 1];
- DCHECK_LE(x_end, rect.width());
- for (size_t j = 0; j < num_quads; ++j) {
- int y_start = heights[j];
- int y_end = j == num_quads - 1 ? rect.height() : heights[j + 1];
- DCHECK_LE(y_end, rect.height());
-
- float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f};
- gfx::Rect layer_rect(x_start, y_start, x_end - x_start, y_end - y_start);
- gfx::RectF uv_rect = gfx::ScaleRect(
- gfx::RectF(layer_rect), 1.f / rect.width(), 1.f / rect.height());
-
- TextureDrawQuad* texture_quad =
- pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
- texture_quad->SetNew(shared_state, layer_rect, layer_rect, needs_blending,
- resource, true, uv_rect.origin(),
- uv_rect.bottom_right(), SK_ColorWHITE,
- vertex_opacity, false, false, false);
- }
- }
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(
- &pass_list, base::FilePath(FILE_PATH_LITERAL("spiral.png")),
- FuzzyPixelOffByOneComparator(true)));
-}
-
-class GLRendererPixelTestWithOverdrawFeedback : public GLRendererPixelTest {
- protected:
- void SetUp() override {
- renderer_settings_.show_overdraw_feedback = true;
- GLRendererPixelTest::SetUp();
- }
-};
-
-TEST_F(GLRendererPixelTestWithOverdrawFeedback, TranslucentRectangles) {
- gfx::Rect rect(this->device_viewport_size_);
-
- int id = 1;
- gfx::Transform transform_to_root;
- std::unique_ptr<RenderPass> pass =
- CreateTestRenderPass(id, rect, transform_to_root);
-
- gfx::Transform dark_gray_quad_to_target_transform;
- dark_gray_quad_to_target_transform.Translate(50, 50);
- dark_gray_quad_to_target_transform.Scale(
- 0.5f + 1.0f / (rect.width() * 2.0f),
- 0.5f + 1.0f / (rect.height() * 2.0f));
- SharedQuadState* dark_gray_shared_state = CreateTestSharedQuadState(
- dark_gray_quad_to_target_transform, rect, pass.get());
-
- SolidColorDrawQuad* dark_gray =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- dark_gray->SetNew(dark_gray_shared_state, rect, rect, 0x10444444, false);
-
- gfx::Transform light_gray_quad_to_target_transform;
- light_gray_quad_to_target_transform.Translate(25.5f, 25.5f);
- light_gray_quad_to_target_transform.Scale(0.5f, 0.5f);
- SharedQuadState* light_gray_shared_state = CreateTestSharedQuadState(
- light_gray_quad_to_target_transform, rect, pass.get());
-
- SolidColorDrawQuad* light_gray =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- light_gray->SetNew(light_gray_shared_state, rect, rect, 0x10CCCCCC, false);
-
- gfx::Transform bg_quad_to_target_transform;
- SharedQuadState* bg_shared_state =
- CreateTestSharedQuadState(bg_quad_to_target_transform, rect, pass.get());
-
- SolidColorDrawQuad* bg = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- bg->SetNew(bg_shared_state, rect, rect, SK_ColorBLACK, false);
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- EXPECT_TRUE(this->RunPixelTest(&pass_list, base::FilePath(FILE_PATH_LITERAL(
- "translucent_rectangles.png")),
- ExactPixelComparator(true)));
-}
-
-typedef std::tr1::tuple<gfx::ColorSpace, gfx::ColorSpace> ColorSpacePair;
-
-class ColorTransformPixelTest
- : public GLRendererPixelTest,
- public testing::WithParamInterface<ColorSpacePair> {
- public:
- ColorTransformPixelTest() {
- renderer_settings_.enable_color_correct_rendering = true;
- // Note that this size of 17 is not random -- it is chosen to match the
- // size of LUTs that are created. If we did not match the LUT size exactly,
- // then the error for LUT based transforms is much larger.
- device_viewport_size_ = gfx::Size(17, 4);
- src_color_space_ = std::tr1::get<0>(GetParam());
- dst_color_space_ = std::tr1::get<1>(GetParam());
- if (!src_color_space_.IsValid()) {
- src_color_space_ =
- gfx::ICCProfileForTestingNoAnalyticTrFn().GetColorSpace();
- }
- if (!dst_color_space_.IsValid()) {
- dst_color_space_ =
- gfx::ICCProfileForTestingNoAnalyticTrFn().GetColorSpace();
- }
- }
- gfx::ColorSpace src_color_space_;
- gfx::ColorSpace dst_color_space_;
-};
-
-TEST_P(ColorTransformPixelTest, Basic) {
- gfx::Rect rect(this->device_viewport_size_);
- std::vector<uint8_t> input_colors(4 * rect.width() * rect.height(), 0);
- std::vector<SkColor> expected_output_colors(rect.width() * rect.height());
-
- renderer_->DisableColorChecksForTesting();
-
- // Set the input data to be:
- // Row 0: Gradient of red from 0 to 255
- // Row 1: Gradient of green from 0 to 255
- // Row 2: Gradient of blue from 0 to 255
- // Row 3: Gradient of grey from 0 to 255
- for (int x = 0; x < rect.width(); ++x) {
- int v = (x * 255) / (rect.width() - 1);
- for (int y = 0; y < rect.height(); ++y) {
- for (int c = 0; c < 3; ++c) {
- if (y == c || y == rect.height() - 1) {
- input_colors[c + 4 * (x + rect.width() * y)] = v;
- }
- }
- input_colors[3 + 4 * (x + rect.width() * y)] = 255;
- }
- }
-
- std::unique_ptr<gfx::ColorTransform> transform =
- gfx::ColorTransform::NewColorTransform(
- src_color_space_, dst_color_space_,
- gfx::ColorTransform::Intent::INTENT_PERCEPTUAL);
-
- for (size_t i = 0; i < expected_output_colors.size(); ++i) {
- gfx::ColorTransform::TriStim color;
- color.set_x(input_colors[4 * i + 0] / 255.f);
- color.set_y(input_colors[4 * i + 1] / 255.f);
- color.set_z(input_colors[4 * i + 2] / 255.f);
- transform->Transform(&color, 1);
- color.set_x(std::min(std::max(0.f, color.x()), 1.f));
- color.set_y(std::min(std::max(0.f, color.y()), 1.f));
- color.set_z(std::min(std::max(0.f, color.z()), 1.f));
- expected_output_colors[i] =
- SkColorSetARGBInline(255, static_cast<size_t>(255.f * color.x() + 0.5f),
- static_cast<size_t>(255.f * color.y() + 0.5f),
- static_cast<size_t>(255.f * color.z() + 0.5f));
- }
-
- int id = 1;
- std::unique_ptr<RenderPass> pass = CreateTestRootRenderPass(id, rect);
- pass->color_space = dst_color_space_;
-
- {
- SharedQuadState* shared_state =
- CreateTestSharedQuadState(gfx::Transform(), rect, pass.get());
-
- viz::ResourceId resource = resource_provider_->CreateResource(
- rect.size(), ResourceProvider::TEXTURE_HINT_IMMUTABLE, viz::RGBA_8888,
- src_color_space_);
- resource_provider_->CopyToResource(resource, input_colors.data(),
- rect.size());
-
- bool needs_blending = true;
- const gfx::PointF uv_top_left(0.0f, 0.0f);
- const gfx::PointF uv_bottom_right(1.0f, 1.0f);
- const bool flipped = false;
- const bool nearest_neighbor = false;
- const bool premultiplied_alpha = false;
- TextureDrawQuad* quad = pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
-
- float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f};
- quad->SetNew(shared_state, rect, rect, needs_blending, resource,
- premultiplied_alpha, uv_top_left, uv_bottom_right,
- SK_ColorBLACK, vertex_opacity, flipped, nearest_neighbor,
- false);
-
- SolidColorDrawQuad* color_quad =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(shared_state, rect, rect, SK_ColorWHITE, false);
- }
-
- RenderPassList pass_list;
- pass_list.push_back(std::move(pass));
-
- // Allow a difference of 2 bytes in comparison for shader-based transforms,
- // and 4 bytes for LUT-based transforms (determined empirically).
- FuzzyPixelComparator comparator(false, 100.f, 0.f, 2.f, 2, 0);
- if (!transform->CanGetShaderSource())
- comparator = FuzzyPixelComparator(false, 100.f, 0.f, 6.f, 6, 0);
- EXPECT_TRUE(RunPixelTest(&pass_list, &expected_output_colors, comparator));
-}
-
-typedef gfx::ColorSpace::PrimaryID PrimaryID;
-typedef gfx::ColorSpace::TransferID TransferID;
-typedef gfx::ColorSpace::MatrixID MatrixID;
-typedef gfx::ColorSpace::RangeID RangeID;
-
-gfx::ColorSpace src_color_spaces[] = {
- // This will be replaced by an ICC-based space (which can't be initialized
- // here).
- gfx::ColorSpace(),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::BT709),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::GAMMA22),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::GAMMA24),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::GAMMA28),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::SMPTE170M),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::SMPTE240M),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::LINEAR),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::LOG),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::LOG_SQRT),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_4),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::BT1361_ECG),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::BT2020_10),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::BT2020_12),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::SMPTEST2084),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::SMPTEST428_1),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::ARIB_STD_B67),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1_HDR),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::LINEAR_HDR),
- gfx::ColorSpace(PrimaryID::BT709,
- TransferID::BT2020_10,
- MatrixID::BT2020_CL,
- RangeID::FULL),
-};
-
-gfx::ColorSpace dst_color_spaces[] = {
- // This will be replaced by an ICC-based space (which can't be initialized
- // here).
- gfx::ColorSpace(),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::BT709),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::GAMMA22),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::GAMMA24),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::GAMMA28),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::SMPTE170M),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::SMPTE240M),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::LINEAR),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::LOG),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::LOG_SQRT),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_4),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::BT1361_ECG),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::BT2020_10),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::BT2020_12),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::SMPTEST2084),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::ARIB_STD_B67),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::IEC61966_2_1_HDR),
- gfx::ColorSpace(PrimaryID::BT709, TransferID::LINEAR_HDR),
-};
-
-gfx::ColorSpace intermediate_color_spaces[] = {
- gfx::ColorSpace(PrimaryID::XYZ_D50, TransferID::LINEAR),
- gfx::ColorSpace(PrimaryID::XYZ_D50, TransferID::IEC61966_2_1_HDR),
-};
-
-INSTANTIATE_TEST_CASE_P(
- FromColorSpace,
- ColorTransformPixelTest,
- testing::Combine(testing::ValuesIn(src_color_spaces),
- testing::ValuesIn(intermediate_color_spaces)));
-
-INSTANTIATE_TEST_CASE_P(
- ToColorSpace,
- ColorTransformPixelTest,
- testing::Combine(testing::ValuesIn(intermediate_color_spaces),
- testing::ValuesIn(dst_color_spaces)));
-
-#endif // !defined(OS_ANDROID)
-
-} // namespace
-} // namespace cc
diff --git a/chromium/cc/output/software_output_device.cc b/chromium/cc/output/software_output_device.cc
deleted file mode 100644
index 04a426a12ea..00000000000
--- a/chromium/cc/output/software_output_device.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/software_output_device.h"
-
-#include "base/logging.h"
-#include "third_party/skia/include/core/SkCanvas.h"
-#include "ui/gfx/vsync_provider.h"
-
-namespace cc {
-
-SoftwareOutputDevice::SoftwareOutputDevice() = default;
-SoftwareOutputDevice::~SoftwareOutputDevice() = default;
-
-void SoftwareOutputDevice::Resize(const gfx::Size& viewport_pixel_size,
- float scale_factor) {
- if (viewport_pixel_size_ == viewport_pixel_size)
- return;
-
- SkImageInfo info = SkImageInfo::MakeN32(viewport_pixel_size.width(),
- viewport_pixel_size.height(),
- kOpaque_SkAlphaType);
- viewport_pixel_size_ = viewport_pixel_size;
- surface_ = SkSurface::MakeRaster(info);
-}
-
-SkCanvas* SoftwareOutputDevice::BeginPaint(const gfx::Rect& damage_rect) {
- damage_rect_ = damage_rect;
- return surface_ ? surface_->getCanvas() : nullptr;
-}
-
-void SoftwareOutputDevice::EndPaint() {}
-
-gfx::VSyncProvider* SoftwareOutputDevice::GetVSyncProvider() {
- return vsync_provider_.get();
-}
-
-} // namespace cc
diff --git a/chromium/cc/output/software_output_device.h b/chromium/cc/output/software_output_device.h
deleted file mode 100644
index 322e17cab76..00000000000
--- a/chromium/cc/output/software_output_device.h
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_SOFTWARE_OUTPUT_DEVICE_H_
-#define CC_OUTPUT_SOFTWARE_OUTPUT_DEVICE_H_
-
-#include <memory>
-
-#include "base/macros.h"
-#include "cc/cc_export.h"
-#include "third_party/skia/include/core/SkSurface.h"
-#include "ui/gfx/geometry/rect.h"
-#include "ui/gfx/geometry/size.h"
-#include "ui/gfx/geometry/vector2d.h"
-
-class SkCanvas;
-
-namespace gfx {
-class VSyncProvider;
-}
-
-namespace cc {
-
-// This is a "tear-off" class providing software drawing support to
-// OutputSurface, such as to a platform-provided window framebuffer.
-class CC_EXPORT SoftwareOutputDevice {
- public:
- SoftwareOutputDevice();
- virtual ~SoftwareOutputDevice();
-
- // Discards any pre-existing backing buffers and allocates memory for a
- // software device of |size|. This must be called before the
- // |SoftwareOutputDevice| can be used in other ways.
- virtual void Resize(const gfx::Size& pixel_size, float scale_factor);
-
- // Called on BeginDrawingFrame. The compositor will draw into the returned
- // SkCanvas. The |SoftwareOutputDevice| implementation needs to provide a
- // valid SkCanvas of at least size |damage_rect|. This class retains ownership
- // of the SkCanvas.
- virtual SkCanvas* BeginPaint(const gfx::Rect& damage_rect);
-
- // Called on FinishDrawingFrame. The compositor will no longer mutate the the
- // SkCanvas instance returned by |BeginPaint| and should discard any reference
- // that it holds to it.
- virtual void EndPaint();
-
- // Discard the backing buffer in the surface provided by this instance.
- virtual void DiscardBackbuffer() {}
-
- // Ensures that there is a backing buffer available on this instance.
- virtual void EnsureBackbuffer() {}
-
- // VSyncProvider used to update the timer used to schedule draws with the
- // hardware vsync. Return NULL if a provider doesn't exist.
- virtual gfx::VSyncProvider* GetVSyncProvider();
-
- protected:
- gfx::Size viewport_pixel_size_;
- gfx::Rect damage_rect_;
- sk_sp<SkSurface> surface_;
- std::unique_ptr<gfx::VSyncProvider> vsync_provider_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDevice);
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_SOFTWARE_OUTPUT_DEVICE_H_
diff --git a/chromium/cc/output/software_renderer.cc b/chromium/cc/output/software_renderer.cc
deleted file mode 100644
index 37ccbf1d6f6..00000000000
--- a/chromium/cc/output/software_renderer.cc
+++ /dev/null
@@ -1,732 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/software_renderer.h"
-
-#include "base/memory/ptr_util.h"
-#include "base/trace_event/trace_event.h"
-#include "cc/base/math_util.h"
-#include "cc/base/render_surface_filters.h"
-#include "cc/output/output_surface.h"
-#include "cc/output/output_surface_frame.h"
-#include "cc/output/software_output_device.h"
-#include "cc/quads/debug_border_draw_quad.h"
-#include "cc/quads/picture_draw_quad.h"
-#include "cc/quads/render_pass_draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
-#include "cc/quads/tile_draw_quad.h"
-#include "cc/resources/scoped_resource.h"
-#include "components/viz/common/display/renderer_settings.h"
-#include "components/viz/common/quads/copy_output_request.h"
-#include "skia/ext/opacity_filter_canvas.h"
-#include "third_party/skia/include/core/SkCanvas.h"
-#include "third_party/skia/include/core/SkColor.h"
-#include "third_party/skia/include/core/SkImageFilter.h"
-#include "third_party/skia/include/core/SkMatrix.h"
-#include "third_party/skia/include/core/SkPath.h"
-#include "third_party/skia/include/core/SkPoint.h"
-#include "third_party/skia/include/core/SkShader.h"
-#include "third_party/skia/include/effects/SkLayerRasterizer.h"
-#include "ui/gfx/geometry/axis_transform2d.h"
-#include "ui/gfx/geometry/rect_conversions.h"
-#include "ui/gfx/skia_util.h"
-#include "ui/gfx/transform.h"
-
-namespace cc {
-namespace {
-
-static inline bool IsScalarNearlyInteger(SkScalar scalar) {
- return SkScalarNearlyZero(scalar - SkScalarRoundToScalar(scalar));
-}
-
-bool IsScaleAndIntegerTranslate(const SkMatrix& matrix) {
- return IsScalarNearlyInteger(matrix[SkMatrix::kMTransX]) &&
- IsScalarNearlyInteger(matrix[SkMatrix::kMTransY]) &&
- SkScalarNearlyZero(matrix[SkMatrix::kMSkewX]) &&
- SkScalarNearlyZero(matrix[SkMatrix::kMSkewY]) &&
- SkScalarNearlyZero(matrix[SkMatrix::kMPersp0]) &&
- SkScalarNearlyZero(matrix[SkMatrix::kMPersp1]) &&
- SkScalarNearlyZero(matrix[SkMatrix::kMPersp2] - 1.0f);
-}
-
-} // anonymous namespace
-
-SoftwareRenderer::SoftwareRenderer(const viz::RendererSettings* settings,
- OutputSurface* output_surface,
- DisplayResourceProvider* resource_provider)
- : DirectRenderer(settings, output_surface, resource_provider),
- output_device_(output_surface->software_device()) {}
-
-SoftwareRenderer::~SoftwareRenderer() {}
-
-bool SoftwareRenderer::CanPartialSwap() {
- return true;
-}
-
-viz::ResourceFormat SoftwareRenderer::BackbufferFormat() const {
- return resource_provider_->best_texture_format();
-}
-
-void SoftwareRenderer::BeginDrawingFrame() {
- TRACE_EVENT0("cc", "SoftwareRenderer::BeginDrawingFrame");
- root_canvas_ = output_device_->BeginPaint(current_frame()->root_damage_rect);
-}
-
-void SoftwareRenderer::FinishDrawingFrame() {
- TRACE_EVENT0("cc", "SoftwareRenderer::FinishDrawingFrame");
- current_framebuffer_lock_ = nullptr;
- current_framebuffer_canvas_.reset();
- current_canvas_ = nullptr;
- root_canvas_ = nullptr;
-
- output_device_->EndPaint();
-}
-
-void SoftwareRenderer::SwapBuffers(std::vector<ui::LatencyInfo> latency_info) {
- DCHECK(visible_);
- TRACE_EVENT0("cc", "SoftwareRenderer::SwapBuffers");
- OutputSurfaceFrame output_frame;
- output_frame.latency_info = std::move(latency_info);
- output_surface_->SwapBuffers(std::move(output_frame));
-}
-
-bool SoftwareRenderer::FlippedFramebuffer() const {
- return false;
-}
-
-void SoftwareRenderer::EnsureScissorTestEnabled() {
- is_scissor_enabled_ = true;
-}
-
-void SoftwareRenderer::EnsureScissorTestDisabled() {
- is_scissor_enabled_ = false;
-}
-
-void SoftwareRenderer::BindFramebufferToOutputSurface() {
- DCHECK(!output_surface_->HasExternalStencilTest());
- current_framebuffer_lock_ = nullptr;
- current_framebuffer_canvas_.reset();
- current_canvas_ = root_canvas_;
-}
-
-bool SoftwareRenderer::BindFramebufferToTexture(
- const ScopedResource* texture) {
- DCHECK(texture->id());
-
- // Explicitly release lock, otherwise we can crash when try to lock
- // same texture again.
- current_framebuffer_lock_ = nullptr;
- current_framebuffer_lock_ =
- std::make_unique<ResourceProvider::ScopedWriteLockSoftware>(
- resource_provider_, texture->id());
- current_framebuffer_canvas_ =
- std::make_unique<SkCanvas>(current_framebuffer_lock_->sk_bitmap());
- current_canvas_ = current_framebuffer_canvas_.get();
- return true;
-}
-
-void SoftwareRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) {
- is_scissor_enabled_ = true;
- scissor_rect_ = scissor_rect;
-}
-
-void SoftwareRenderer::SetClipRect(const gfx::Rect& rect) {
- if (!current_canvas_)
- return;
- // Skia applies the current matrix to clip rects so we reset it temporary.
- SkMatrix current_matrix = current_canvas_->getTotalMatrix();
- current_canvas_->resetMatrix();
- // SetClipRect is assumed to be applied temporarily, on an
- // otherwise-unclipped canvas.
- DCHECK_EQ(current_canvas_->getDeviceClipBounds().width(),
- current_canvas_->imageInfo().width());
- DCHECK_EQ(current_canvas_->getDeviceClipBounds().height(),
- current_canvas_->imageInfo().height());
- current_canvas_->clipRect(gfx::RectToSkRect(rect));
- current_canvas_->setMatrix(current_matrix);
-}
-
-void SoftwareRenderer::ClearCanvas(SkColor color) {
- if (!current_canvas_)
- return;
-
- if (is_scissor_enabled_) {
- // The same paint used by SkCanvas::clear, but applied to the scissor rect.
- SkPaint clear_paint;
- clear_paint.setColor(color);
- clear_paint.setBlendMode(SkBlendMode::kSrc);
- current_canvas_->drawRect(gfx::RectToSkRect(scissor_rect_), clear_paint);
- } else {
- current_canvas_->clear(color);
- }
-}
-
-void SoftwareRenderer::ClearFramebuffer() {
- if (current_frame()->current_render_pass->has_transparent_background) {
- ClearCanvas(SkColorSetARGB(0, 0, 0, 0));
- } else {
-#ifndef NDEBUG
- // On DEBUG builds, opaque render passes are cleared to blue
- // to easily see regions that were not drawn on the screen.
- ClearCanvas(SkColorSetARGB(255, 0, 0, 255));
-#endif
- }
-}
-
-void SoftwareRenderer::PrepareSurfaceForPass(
- SurfaceInitializationMode initialization_mode,
- const gfx::Rect& render_pass_scissor) {
- switch (initialization_mode) {
- case SURFACE_INITIALIZATION_MODE_PRESERVE:
- EnsureScissorTestDisabled();
- return;
- case SURFACE_INITIALIZATION_MODE_FULL_SURFACE_CLEAR:
- EnsureScissorTestDisabled();
- ClearFramebuffer();
- break;
- case SURFACE_INITIALIZATION_MODE_SCISSORED_CLEAR:
- SetScissorTestRect(render_pass_scissor);
- ClearFramebuffer();
- break;
- }
-}
-
-bool SoftwareRenderer::IsSoftwareResource(viz::ResourceId resource_id) const {
- switch (resource_provider_->GetResourceType(resource_id)) {
- case ResourceProvider::RESOURCE_TYPE_GPU_MEMORY_BUFFER:
- case ResourceProvider::RESOURCE_TYPE_GL_TEXTURE:
- return false;
- case ResourceProvider::RESOURCE_TYPE_BITMAP:
- return true;
- }
-
- LOG(FATAL) << "Invalid resource type.";
- return false;
-}
-
-void SoftwareRenderer::DoDrawQuad(const DrawQuad* quad,
- const gfx::QuadF* draw_region) {
- if (!current_canvas_)
- return;
-
- TRACE_EVENT0("cc", "SoftwareRenderer::DoDrawQuad");
- bool do_save = draw_region || is_scissor_enabled_;
- SkAutoCanvasRestore canvas_restore(current_canvas_, do_save);
- if (is_scissor_enabled_) {
- SetClipRect(scissor_rect_);
- }
-
- gfx::Transform quad_rect_matrix;
- QuadRectTransform(&quad_rect_matrix,
- quad->shared_quad_state->quad_to_target_transform,
- gfx::RectF(quad->rect));
- gfx::Transform contents_device_transform =
- current_frame()->window_matrix * current_frame()->projection_matrix *
- quad_rect_matrix;
- contents_device_transform.FlattenTo2d();
- SkMatrix sk_device_matrix;
- gfx::TransformToFlattenedSkMatrix(contents_device_transform,
- &sk_device_matrix);
- current_canvas_->setMatrix(sk_device_matrix);
-
- current_paint_.reset();
- if (settings_->force_antialiasing ||
- !IsScaleAndIntegerTranslate(sk_device_matrix)) {
- // TODO(danakj): Until we can enable AA only on exterior edges of the
- // layer, disable AA if any interior edges are present. crbug.com/248175
- bool all_four_edges_are_exterior = quad->IsTopEdge() &&
- quad->IsLeftEdge() &&
- quad->IsBottomEdge() &&
- quad->IsRightEdge();
- if (settings_->allow_antialiasing &&
- (settings_->force_antialiasing || all_four_edges_are_exterior))
- current_paint_.setAntiAlias(true);
- current_paint_.setFilterQuality(kLow_SkFilterQuality);
- }
-
- if (quad->ShouldDrawWithBlending() ||
- quad->shared_quad_state->blend_mode != SkBlendMode::kSrcOver) {
- current_paint_.setAlpha(quad->shared_quad_state->opacity * 255);
- current_paint_.setBlendMode(quad->shared_quad_state->blend_mode);
- } else {
- current_paint_.setBlendMode(SkBlendMode::kSrc);
- }
-
- if (draw_region) {
- gfx::QuadF local_draw_region(*draw_region);
- SkPath draw_region_clip_path;
- local_draw_region -=
- gfx::Vector2dF(quad->visible_rect.x(), quad->visible_rect.y());
- local_draw_region.Scale(1.0f / quad->visible_rect.width(),
- 1.0f / quad->visible_rect.height());
- local_draw_region -= gfx::Vector2dF(0.5f, 0.5f);
-
- SkPoint clip_points[4];
- QuadFToSkPoints(local_draw_region, clip_points);
- draw_region_clip_path.addPoly(clip_points, 4, true);
-
- current_canvas_->clipPath(draw_region_clip_path);
- }
-
- switch (quad->material) {
- case DrawQuad::DEBUG_BORDER:
- DrawDebugBorderQuad(DebugBorderDrawQuad::MaterialCast(quad));
- break;
- case DrawQuad::PICTURE_CONTENT:
- DrawPictureQuad(PictureDrawQuad::MaterialCast(quad));
- break;
- case DrawQuad::RENDER_PASS:
- DrawRenderPassQuad(RenderPassDrawQuad::MaterialCast(quad));
- break;
- case DrawQuad::SOLID_COLOR:
- DrawSolidColorQuad(SolidColorDrawQuad::MaterialCast(quad));
- break;
- case DrawQuad::TEXTURE_CONTENT:
- DrawTextureQuad(TextureDrawQuad::MaterialCast(quad));
- break;
- case DrawQuad::TILED_CONTENT:
- DrawTileQuad(TileDrawQuad::MaterialCast(quad));
- break;
- case DrawQuad::SURFACE_CONTENT:
- // Surface content should be fully resolved to other quad types before
- // reaching a direct renderer.
- NOTREACHED();
- break;
- case DrawQuad::INVALID:
- case DrawQuad::YUV_VIDEO_CONTENT:
- case DrawQuad::STREAM_VIDEO_CONTENT:
- DrawUnsupportedQuad(quad);
- NOTREACHED();
- break;
- }
-
- current_canvas_->resetMatrix();
-}
-
-void SoftwareRenderer::DrawDebugBorderQuad(const DebugBorderDrawQuad* quad) {
- // We need to apply the matrix manually to have pixel-sized stroke width.
- SkPoint vertices[4];
- gfx::RectFToSkRect(QuadVertexRect()).toQuad(vertices);
- SkPoint transformed_vertices[4];
- current_canvas_->getTotalMatrix().mapPoints(transformed_vertices,
- vertices,
- 4);
- current_canvas_->resetMatrix();
-
- current_paint_.setColor(quad->color);
- current_paint_.setAlpha(quad->shared_quad_state->opacity *
- SkColorGetA(quad->color));
- current_paint_.setStyle(SkPaint::kStroke_Style);
- current_paint_.setStrokeWidth(quad->width);
- current_canvas_->drawPoints(SkCanvas::kPolygon_PointMode,
- 4, transformed_vertices, current_paint_);
-}
-
-void SoftwareRenderer::DrawPictureQuad(const PictureDrawQuad* quad) {
- SkMatrix content_matrix;
- content_matrix.setRectToRect(
- gfx::RectFToSkRect(quad->tex_coord_rect),
- gfx::RectFToSkRect(QuadVertexRect()),
- SkMatrix::kFill_ScaleToFit);
- current_canvas_->concat(content_matrix);
-
- const bool needs_transparency =
- SkScalarRoundToInt(quad->shared_quad_state->opacity * 255) < 255;
- const bool disable_image_filtering =
- disable_picture_quad_image_filtering_ || quad->nearest_neighbor;
-
- TRACE_EVENT0("cc", "SoftwareRenderer::DrawPictureQuad");
-
- // TODO(ccameron): Determine a color space strategy for software rendering.
- gfx::ColorSpace canvas_color_space;
- if (settings_->enable_color_correct_rendering)
- canvas_color_space = gfx::ColorSpace::CreateSRGB();
-
- RasterSource::PlaybackSettings playback_settings;
- playback_settings.playback_to_shared_canvas = true;
- if (needs_transparency || disable_image_filtering) {
- // TODO(aelias): This isn't correct in all cases. We should detect these
- // cases and fall back to a persistent bitmap backing
- // (http://crbug.com/280374).
- // TODO(vmpstr): Fold this canvas into playback and have raster source
- // accept a set of settings on playback that will determine which canvas to
- // apply. (http://crbug.com/594679)
- skia::OpacityFilterCanvas filtered_canvas(current_canvas_,
- quad->shared_quad_state->opacity,
- disable_image_filtering);
- quad->raster_source->PlaybackToCanvas(
- &filtered_canvas, canvas_color_space, quad->content_rect,
- quad->content_rect,
- gfx::AxisTransform2d(quad->contents_scale, gfx::Vector2dF()),
- playback_settings);
- } else {
- quad->raster_source->PlaybackToCanvas(
- current_canvas_, canvas_color_space, quad->content_rect,
- quad->content_rect,
- gfx::AxisTransform2d(quad->contents_scale, gfx::Vector2dF()),
- playback_settings);
- }
-}
-
-void SoftwareRenderer::DrawSolidColorQuad(const SolidColorDrawQuad* quad) {
- gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional(
- QuadVertexRect(), gfx::RectF(quad->rect), gfx::RectF(quad->visible_rect));
- current_paint_.setColor(quad->color);
- current_paint_.setAlpha(quad->shared_quad_state->opacity *
- SkColorGetA(quad->color));
- current_canvas_->drawRect(gfx::RectFToSkRect(visible_quad_vertex_rect),
- current_paint_);
-}
-
-void SoftwareRenderer::DrawTextureQuad(const TextureDrawQuad* quad) {
- if (!IsSoftwareResource(quad->resource_id())) {
- DrawUnsupportedQuad(quad);
- return;
- }
-
- // TODO(skaslev): Add support for non-premultiplied alpha.
- DisplayResourceProvider::ScopedReadLockSkImage lock(resource_provider_,
- quad->resource_id());
- if (!lock.valid())
- return;
- const SkImage* image = lock.sk_image();
- gfx::RectF uv_rect = gfx::ScaleRect(
- gfx::BoundingRect(quad->uv_top_left, quad->uv_bottom_right),
- image->width(), image->height());
- gfx::RectF visible_uv_rect = MathUtil::ScaleRectProportional(
- uv_rect, gfx::RectF(quad->rect), gfx::RectF(quad->visible_rect));
- SkRect sk_uv_rect = gfx::RectFToSkRect(visible_uv_rect);
- gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional(
- QuadVertexRect(), gfx::RectF(quad->rect), gfx::RectF(quad->visible_rect));
- SkRect quad_rect = gfx::RectFToSkRect(visible_quad_vertex_rect);
-
- if (quad->y_flipped)
- current_canvas_->scale(1, -1);
-
- bool blend_background =
- quad->background_color != SK_ColorTRANSPARENT && !image->isOpaque();
- bool needs_layer = blend_background && (current_paint_.getAlpha() != 0xFF);
- if (needs_layer) {
- current_canvas_->saveLayerAlpha(&quad_rect, current_paint_.getAlpha());
- current_paint_.setAlpha(0xFF);
- }
- if (blend_background) {
- SkPaint background_paint;
- background_paint.setColor(quad->background_color);
- current_canvas_->drawRect(quad_rect, background_paint);
- }
- current_paint_.setFilterQuality(
- quad->nearest_neighbor ? kNone_SkFilterQuality : kLow_SkFilterQuality);
- current_canvas_->drawImageRect(image, sk_uv_rect, quad_rect, &current_paint_);
- if (needs_layer)
- current_canvas_->restore();
-}
-
-void SoftwareRenderer::DrawTileQuad(const TileDrawQuad* quad) {
- // |resource_provider_| can be NULL in resourceless software draws, which
- // should never produce tile quads in the first place.
- DCHECK(resource_provider_);
- DCHECK(IsSoftwareResource(quad->resource_id()));
-
- DisplayResourceProvider::ScopedReadLockSkImage lock(resource_provider_,
- quad->resource_id());
- if (!lock.valid())
- return;
-
- gfx::RectF visible_tex_coord_rect = MathUtil::ScaleRectProportional(
- quad->tex_coord_rect, gfx::RectF(quad->rect),
- gfx::RectF(quad->visible_rect));
- gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional(
- QuadVertexRect(), gfx::RectF(quad->rect), gfx::RectF(quad->visible_rect));
-
- SkRect uv_rect = gfx::RectFToSkRect(visible_tex_coord_rect);
- current_paint_.setFilterQuality(
- quad->nearest_neighbor ? kNone_SkFilterQuality : kLow_SkFilterQuality);
- current_canvas_->drawImageRect(lock.sk_image(), uv_rect,
- gfx::RectFToSkRect(visible_quad_vertex_rect),
- &current_paint_);
-}
-
-void SoftwareRenderer::DrawRenderPassQuad(const RenderPassDrawQuad* quad) {
- ScopedResource* content_texture =
- render_pass_textures_[quad->render_pass_id].get();
- DCHECK(content_texture);
- DCHECK(content_texture->id());
- DCHECK(IsSoftwareResource(content_texture->id()));
-
- DisplayResourceProvider::ScopedReadLockSoftware lock(resource_provider_,
- content_texture->id());
- if (!lock.valid())
- return;
-
- SkRect dest_rect = gfx::RectFToSkRect(QuadVertexRect());
- SkRect dest_visible_rect = gfx::RectFToSkRect(
- MathUtil::ScaleRectProportional(QuadVertexRect(), gfx::RectF(quad->rect),
- gfx::RectF(quad->visible_rect)));
- SkRect content_rect = RectFToSkRect(quad->tex_coord_rect);
-
- const SkBitmap* content = lock.sk_bitmap();
-
- sk_sp<SkImage> filter_image;
- const FilterOperations* filters = FiltersForPass(quad->render_pass_id);
- if (filters) {
- DCHECK(!filters->IsEmpty());
- sk_sp<SkImageFilter> image_filter = RenderSurfaceFilters::BuildImageFilter(
- *filters, gfx::SizeF(content_texture->size()));
- if (image_filter) {
- SkIRect result_rect;
- // TODO(ajuma): Apply the filter in the same pass as the content where
- // possible (e.g. when there's no origin offset). See crbug.com/308201.
- filter_image =
- ApplyImageFilter(image_filter.get(), quad, *content, &result_rect);
- if (result_rect.isEmpty()) {
- return;
- }
- if (filter_image) {
- gfx::RectF rect = gfx::SkRectToRectF(SkRect::Make(result_rect));
- dest_rect = dest_visible_rect =
- gfx::RectFToSkRect(MathUtil::ScaleRectProportional(
- QuadVertexRect(), gfx::RectF(quad->rect), rect));
- content_rect =
- SkRect::MakeWH(result_rect.width(), result_rect.height());
- }
- }
- }
-
- SkMatrix content_mat;
- content_mat.setRectToRect(content_rect, dest_rect,
- SkMatrix::kFill_ScaleToFit);
-
- sk_sp<SkShader> shader;
- if (!filter_image) {
- shader =
- SkShader::MakeBitmapShader(*content, SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode, &content_mat);
- } else {
- shader = filter_image->makeShader(SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode, &content_mat);
- }
-
- std::unique_ptr<DisplayResourceProvider::ScopedReadLockSoftware> mask_lock;
- if (quad->mask_resource_id()) {
- mask_lock =
- std::unique_ptr<DisplayResourceProvider::ScopedReadLockSoftware>(
- new DisplayResourceProvider::ScopedReadLockSoftware(
- resource_provider_, quad->mask_resource_id()));
-
- if (!mask_lock->valid())
- return;
-
- const SkBitmap* mask = mask_lock->sk_bitmap();
-
- // Scale normalized uv rect into absolute texel coordinates.
- SkRect mask_rect = gfx::RectFToSkRect(
- gfx::ScaleRect(quad->mask_uv_rect, quad->mask_texture_size.width(),
- quad->mask_texture_size.height()));
-
- SkMatrix mask_mat;
- mask_mat.setRectToRect(mask_rect, dest_rect, SkMatrix::kFill_ScaleToFit);
-
- SkPaint mask_paint;
- mask_paint.setShader(
- SkShader::MakeBitmapShader(*mask, SkShader::kClamp_TileMode,
- SkShader::kClamp_TileMode, &mask_mat));
-
- SkLayerRasterizer::Builder builder;
- builder.addLayer(mask_paint);
-
- current_paint_.setRasterizer(builder.detach());
- }
-
- // If we have a background filter shader, render its results first.
- sk_sp<SkShader> background_filter_shader =
- GetBackgroundFilterShader(quad, SkShader::kClamp_TileMode);
- if (background_filter_shader) {
- SkPaint paint;
- paint.setShader(std::move(background_filter_shader));
- paint.setRasterizer(current_paint_.refRasterizer());
- current_canvas_->drawRect(dest_visible_rect, paint);
- }
- current_paint_.setShader(std::move(shader));
- current_canvas_->drawRect(dest_visible_rect, current_paint_);
-}
-
-void SoftwareRenderer::DrawUnsupportedQuad(const DrawQuad* quad) {
-#ifdef NDEBUG
- current_paint_.setColor(SK_ColorWHITE);
-#else
- current_paint_.setColor(SK_ColorMAGENTA);
-#endif
- current_paint_.setAlpha(quad->shared_quad_state->opacity * 255);
- current_canvas_->drawRect(gfx::RectFToSkRect(QuadVertexRect()),
- current_paint_);
-}
-
-void SoftwareRenderer::CopyCurrentRenderPassToBitmap(
- std::unique_ptr<viz::CopyOutputRequest> request) {
- gfx::Rect copy_rect = current_frame()->current_render_pass->output_rect;
- if (request->has_area())
- copy_rect.Intersect(request->area());
- gfx::Rect window_copy_rect = MoveFromDrawToWindowSpace(copy_rect);
-
- std::unique_ptr<SkBitmap> bitmap(new SkBitmap);
- bitmap->allocPixels(SkImageInfo::MakeN32Premul(window_copy_rect.width(),
- window_copy_rect.height()));
- if (!current_canvas_->readPixels(*bitmap, window_copy_rect.x(),
- window_copy_rect.y()))
- bitmap->reset();
-
- request->SendBitmapResult(std::move(bitmap));
-}
-
-void SoftwareRenderer::SetEnableDCLayers(bool enable) {
- NOTIMPLEMENTED();
-}
-
-void SoftwareRenderer::DidChangeVisibility() {
- if (visible_)
- output_surface_->EnsureBackbuffer();
- else
- output_surface_->DiscardBackbuffer();
-}
-
-bool SoftwareRenderer::ShouldApplyBackgroundFilters(
- const RenderPassDrawQuad* quad,
- const FilterOperations* background_filters) const {
- if (!background_filters)
- return false;
- DCHECK(!background_filters->IsEmpty());
-
- // TODO(hendrikw): Look into allowing background filters to see pixels from
- // other render targets. See crbug.com/314867.
-
- return true;
-}
-
-// If non-null, auto_bounds will be filled with the automatically-computed
-// destination bounds. If null, the output will be the same size as the
-// input bitmap.
-sk_sp<SkImage> SoftwareRenderer::ApplyImageFilter(
- SkImageFilter* filter,
- const RenderPassDrawQuad* quad,
- const SkBitmap& to_filter,
- SkIRect* auto_bounds) const {
- if (!filter)
- return nullptr;
-
- SkMatrix local_matrix;
- local_matrix.setTranslate(quad->filters_origin.x(), quad->filters_origin.y());
- local_matrix.postScale(quad->filters_scale.x(), quad->filters_scale.y());
- SkIRect dst_rect;
- if (auto_bounds) {
- dst_rect =
- filter->filterBounds(gfx::RectToSkIRect(quad->rect), local_matrix,
- SkImageFilter::kForward_MapDirection);
- *auto_bounds = dst_rect;
- } else {
- dst_rect = to_filter.bounds();
- }
-
- SkImageInfo dst_info =
- SkImageInfo::MakeN32Premul(dst_rect.width(), dst_rect.height());
- sk_sp<SkSurface> surface = SkSurface::MakeRaster(dst_info);
-
- if (!surface) {
- return nullptr;
- }
-
- SkPaint paint;
- // Treat subnormal float values as zero for performance.
- ScopedSubnormalFloatDisabler disabler;
- paint.setImageFilter(filter->makeWithLocalMatrix(local_matrix));
- surface->getCanvas()->translate(-dst_rect.x(), -dst_rect.y());
- surface->getCanvas()->drawBitmap(to_filter, quad->rect.x(), quad->rect.y(),
- &paint);
-
- return surface->makeImageSnapshot();
-}
-
-SkBitmap SoftwareRenderer::GetBackdropBitmap(
- const gfx::Rect& bounding_rect) const {
- SkBitmap bitmap;
- bitmap.allocPixels(SkImageInfo::MakeN32Premul(bounding_rect.width(),
- bounding_rect.height()));
- if (!current_canvas_->readPixels(bitmap, bounding_rect.x(),
- bounding_rect.y()))
- bitmap.reset();
- return bitmap;
-}
-
-gfx::Rect SoftwareRenderer::GetBackdropBoundingBoxForRenderPassQuad(
- const RenderPassDrawQuad* quad,
- const gfx::Transform& contents_device_transform,
- const FilterOperations* background_filters,
- gfx::Rect* unclipped_rect) const {
- DCHECK(ShouldApplyBackgroundFilters(quad, background_filters));
- gfx::Rect backdrop_rect = gfx::ToEnclosingRect(
- MathUtil::MapClippedRect(contents_device_transform, QuadVertexRect()));
-
- SkMatrix matrix;
- matrix.setScale(quad->filters_scale.x(), quad->filters_scale.y());
- backdrop_rect = background_filters->MapRectReverse(backdrop_rect, matrix);
-
- *unclipped_rect = backdrop_rect;
- backdrop_rect.Intersect(MoveFromDrawToWindowSpace(
- current_frame()->current_render_pass->output_rect));
-
- return backdrop_rect;
-}
-
-sk_sp<SkShader> SoftwareRenderer::GetBackgroundFilterShader(
- const RenderPassDrawQuad* quad,
- SkShader::TileMode content_tile_mode) const {
- const FilterOperations* background_filters =
- BackgroundFiltersForPass(quad->render_pass_id);
- if (!ShouldApplyBackgroundFilters(quad, background_filters))
- return nullptr;
-
- gfx::Transform quad_rect_matrix;
- QuadRectTransform(&quad_rect_matrix,
- quad->shared_quad_state->quad_to_target_transform,
- gfx::RectF(quad->rect));
- gfx::Transform contents_device_transform =
- current_frame()->window_matrix * current_frame()->projection_matrix *
- quad_rect_matrix;
- contents_device_transform.FlattenTo2d();
-
- gfx::Rect unclipped_rect;
- gfx::Rect backdrop_rect = GetBackdropBoundingBoxForRenderPassQuad(
- quad, contents_device_transform, background_filters, &unclipped_rect);
-
- // Figure out the transformations to move it back to pixel space.
- gfx::Transform contents_device_transform_inverse;
- if (!contents_device_transform.GetInverse(&contents_device_transform_inverse))
- return nullptr;
-
- SkMatrix filter_backdrop_transform =
- contents_device_transform_inverse.matrix();
- filter_backdrop_transform.preTranslate(backdrop_rect.x(), backdrop_rect.y());
-
- // Draw what's behind, and apply the filter to it.
- SkBitmap backdrop_bitmap = GetBackdropBitmap(backdrop_rect);
-
- gfx::Vector2dF clipping_offset =
- (unclipped_rect.top_right() - backdrop_rect.top_right()) +
- (backdrop_rect.bottom_left() - unclipped_rect.bottom_left());
- sk_sp<SkImageFilter> filter = RenderSurfaceFilters::BuildImageFilter(
- *background_filters,
- gfx::SizeF(backdrop_bitmap.width(), backdrop_bitmap.height()),
- clipping_offset);
- sk_sp<SkImage> filter_backdrop_image =
- ApplyImageFilter(filter.get(), quad, backdrop_bitmap, nullptr);
-
- if (!filter_backdrop_image)
- return nullptr;
-
- return filter_backdrop_image->makeShader(content_tile_mode, content_tile_mode,
- &filter_backdrop_transform);
-}
-
-} // namespace cc
diff --git a/chromium/cc/output/software_renderer.h b/chromium/cc/output/software_renderer.h
deleted file mode 100644
index d377da03096..00000000000
--- a/chromium/cc/output/software_renderer.h
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_SOFTWARE_RENDERER_H_
-#define CC_OUTPUT_SOFTWARE_RENDERER_H_
-
-#include "base/macros.h"
-#include "cc/cc_export.h"
-#include "cc/output/direct_renderer.h"
-#include "ui/latency/latency_info.h"
-
-namespace cc {
-class DebugBorderDrawQuad;
-class OutputSurface;
-class PictureDrawQuad;
-class RenderPassDrawQuad;
-class DisplayResourceProvider;
-class SoftwareOutputDevice;
-class SolidColorDrawQuad;
-class TextureDrawQuad;
-class TileDrawQuad;
-
-class CC_EXPORT SoftwareRenderer : public DirectRenderer {
- public:
- SoftwareRenderer(const viz::RendererSettings* settings,
- OutputSurface* output_surface,
- DisplayResourceProvider* resource_provider);
-
- ~SoftwareRenderer() override;
-
- void SwapBuffers(std::vector<ui::LatencyInfo> latency_info) override;
-
- void SetDisablePictureQuadImageFiltering(bool disable) {
- disable_picture_quad_image_filtering_ = disable;
- }
-
- protected:
- bool CanPartialSwap() override;
- viz::ResourceFormat BackbufferFormat() const override;
- void BindFramebufferToOutputSurface() override;
- bool BindFramebufferToTexture(const ScopedResource* texture) override;
- void SetScissorTestRect(const gfx::Rect& scissor_rect) override;
- void PrepareSurfaceForPass(SurfaceInitializationMode initialization_mode,
- const gfx::Rect& render_pass_scissor) override;
- void DoDrawQuad(const DrawQuad* quad, const gfx::QuadF* draw_region) override;
- void BeginDrawingFrame() override;
- void FinishDrawingFrame() override;
- bool FlippedFramebuffer() const override;
- void EnsureScissorTestEnabled() override;
- void EnsureScissorTestDisabled() override;
- void CopyCurrentRenderPassToBitmap(
- std::unique_ptr<viz::CopyOutputRequest> request) override;
- void SetEnableDCLayers(bool enable) override;
- void DidChangeVisibility() override;
-
- private:
- void ClearCanvas(SkColor color);
- void ClearFramebuffer();
- void SetClipRect(const gfx::Rect& rect);
- bool IsSoftwareResource(viz::ResourceId resource_id) const;
-
- void DrawDebugBorderQuad(const DebugBorderDrawQuad* quad);
- void DrawPictureQuad(const PictureDrawQuad* quad);
- void DrawRenderPassQuad(const RenderPassDrawQuad* quad);
- void DrawSolidColorQuad(const SolidColorDrawQuad* quad);
- void DrawTextureQuad(const TextureDrawQuad* quad);
- void DrawTileQuad(const TileDrawQuad* quad);
- void DrawUnsupportedQuad(const DrawQuad* quad);
- bool ShouldApplyBackgroundFilters(
- const RenderPassDrawQuad* quad,
- const FilterOperations* background_filters) const;
- sk_sp<SkImage> ApplyImageFilter(SkImageFilter* filter,
- const RenderPassDrawQuad* quad,
- const SkBitmap& to_filter,
- SkIRect* auto_bounds) const;
- gfx::Rect GetBackdropBoundingBoxForRenderPassQuad(
- const RenderPassDrawQuad* quad,
- const gfx::Transform& contents_device_transform,
- const FilterOperations* background_filters,
- gfx::Rect* unclipped_rect) const;
- SkBitmap GetBackdropBitmap(const gfx::Rect& bounding_rect) const;
- sk_sp<SkShader> GetBackgroundFilterShader(
- const RenderPassDrawQuad* quad,
- SkShader::TileMode content_tile_mode) const;
-
- bool disable_picture_quad_image_filtering_ = false;
-
- bool is_scissor_enabled_ = false;
- gfx::Rect scissor_rect_;
-
- SoftwareOutputDevice* output_device_;
- SkCanvas* root_canvas_ = nullptr;
- SkCanvas* current_canvas_ = nullptr;
- SkPaint current_paint_;
- std::unique_ptr<ResourceProvider::ScopedWriteLockSoftware>
- current_framebuffer_lock_;
- std::unique_ptr<SkCanvas> current_framebuffer_canvas_;
-
- DISALLOW_COPY_AND_ASSIGN(SoftwareRenderer);
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_SOFTWARE_RENDERER_H_
diff --git a/chromium/cc/output/software_renderer_unittest.cc b/chromium/cc/output/software_renderer_unittest.cc
deleted file mode 100644
index 066b1869707..00000000000
--- a/chromium/cc/output/software_renderer_unittest.cc
+++ /dev/null
@@ -1,456 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/software_renderer.h"
-
-#include <stdint.h>
-
-#include "base/bind.h"
-#include "base/memory/ptr_util.h"
-#include "base/run_loop.h"
-#include "cc/output/compositor_frame_metadata.h"
-#include "cc/output/software_output_device.h"
-#include "cc/quads/render_pass.h"
-#include "cc/quads/render_pass_draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/tile_draw_quad.h"
-#include "cc/test/animation_test_common.h"
-#include "cc/test/fake_output_surface.h"
-#include "cc/test/fake_output_surface_client.h"
-#include "cc/test/fake_resource_provider.h"
-#include "cc/test/geometry_test_utils.h"
-#include "cc/test/render_pass_test_utils.h"
-#include "cc/test/test_shared_bitmap_manager.h"
-#include "components/viz/common/quads/copy_output_request.h"
-#include "components/viz/common/quads/copy_output_result.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/skia/include/core/SkCanvas.h"
-#include "third_party/skia/include/utils/SkNWayCanvas.h"
-#include "ui/gfx/skia_util.h"
-
-namespace cc {
-namespace {
-
-class SoftwareRendererTest : public testing::Test {
- public:
- void InitializeRenderer(
- std::unique_ptr<SoftwareOutputDevice> software_output_device) {
- output_surface_ =
- FakeOutputSurface::CreateSoftware(std::move(software_output_device));
- output_surface_->BindToClient(&output_surface_client_);
-
- shared_bitmap_manager_.reset(new TestSharedBitmapManager());
- resource_provider_ = FakeResourceProvider::Create<DisplayResourceProvider>(
- nullptr, shared_bitmap_manager_.get());
- renderer_ = std::make_unique<SoftwareRenderer>(
- &settings_, output_surface_.get(), resource_provider());
- renderer_->Initialize();
- renderer_->SetVisible(true);
- }
-
- DisplayResourceProvider* resource_provider() const {
- return resource_provider_.get();
- }
-
- SoftwareRenderer* renderer() const { return renderer_.get(); }
-
- std::unique_ptr<SkBitmap> DrawAndCopyOutput(RenderPassList* list,
- float device_scale_factor,
- gfx::Size viewport_size) {
- std::unique_ptr<SkBitmap> bitmap_result;
- base::RunLoop loop;
-
- list->back()->copy_requests.push_back(
- viz::CopyOutputRequest::CreateBitmapRequest(base::BindOnce(
- &SoftwareRendererTest::SaveBitmapResult,
- base::Unretained(&bitmap_result), loop.QuitClosure())));
-
- renderer()->DrawFrame(list, device_scale_factor, viewport_size);
- loop.Run();
- return bitmap_result;
- }
-
- static void SaveBitmapResult(std::unique_ptr<SkBitmap>* bitmap_result,
- const base::Closure& quit_closure,
- std::unique_ptr<viz::CopyOutputResult> result) {
- DCHECK(result->HasBitmap());
- *bitmap_result = result->TakeBitmap();
- quit_closure.Run();
- }
-
- protected:
- viz::RendererSettings settings_;
- FakeOutputSurfaceClient output_surface_client_;
- std::unique_ptr<FakeOutputSurface> output_surface_;
- std::unique_ptr<viz::SharedBitmapManager> shared_bitmap_manager_;
- std::unique_ptr<DisplayResourceProvider> resource_provider_;
- std::unique_ptr<SoftwareRenderer> renderer_;
-};
-
-TEST_F(SoftwareRendererTest, SolidColorQuad) {
- gfx::Size outer_size(100, 100);
- gfx::Size inner_size(98, 98);
- gfx::Rect outer_rect(outer_size);
- gfx::Rect inner_rect(gfx::Point(1, 1), inner_size);
- gfx::Rect visible_rect(gfx::Point(1, 2), gfx::Size(98, 97));
-
- InitializeRenderer(base::WrapUnique(new SoftwareOutputDevice));
-
- int root_render_pass_id = 1;
- std::unique_ptr<RenderPass> root_render_pass = RenderPass::Create();
- root_render_pass->SetNew(root_render_pass_id, outer_rect, outer_rect,
- gfx::Transform());
- viz::SharedQuadState* shared_quad_state =
- root_render_pass->CreateAndAppendSharedQuadState();
- shared_quad_state->SetAll(gfx::Transform(), outer_rect, outer_rect,
- outer_rect, false, 1.0, SkBlendMode::kSrcOver, 0);
- SolidColorDrawQuad* inner_quad =
- root_render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- inner_quad->SetNew(
- shared_quad_state, inner_rect, inner_rect, SK_ColorCYAN, false);
- inner_quad->visible_rect = visible_rect;
- SolidColorDrawQuad* outer_quad =
- root_render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- outer_quad->SetNew(
- shared_quad_state, outer_rect, outer_rect, SK_ColorYELLOW, false);
-
- RenderPassList list;
- list.push_back(std::move(root_render_pass));
-
- float device_scale_factor = 1.f;
- std::unique_ptr<SkBitmap> output =
- DrawAndCopyOutput(&list, device_scale_factor, outer_size);
- EXPECT_EQ(outer_rect.width(), output->info().width());
- EXPECT_EQ(outer_rect.height(), output->info().height());
-
- EXPECT_EQ(SK_ColorYELLOW, output->getColor(0, 0));
- EXPECT_EQ(SK_ColorYELLOW,
- output->getColor(outer_size.width() - 1, outer_size.height() - 1));
- EXPECT_EQ(SK_ColorYELLOW, output->getColor(1, 1));
- EXPECT_EQ(SK_ColorCYAN, output->getColor(1, 2));
- EXPECT_EQ(SK_ColorCYAN,
- output->getColor(inner_size.width() - 1, inner_size.height() - 1));
-}
-
-TEST_F(SoftwareRendererTest, TileQuad) {
- gfx::Size outer_size(100, 100);
- gfx::Size inner_size(98, 98);
- gfx::Rect outer_rect(outer_size);
- gfx::Rect inner_rect(gfx::Point(1, 1), inner_size);
- bool needs_blending = false;
- InitializeRenderer(base::WrapUnique(new SoftwareOutputDevice));
-
- viz::ResourceId resource_yellow = resource_provider()->CreateResource(
- outer_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, viz::RGBA_8888,
- gfx::ColorSpace());
- viz::ResourceId resource_cyan = resource_provider()->CreateResource(
- inner_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, viz::RGBA_8888,
- gfx::ColorSpace());
-
- SkBitmap yellow_tile;
- yellow_tile.allocN32Pixels(outer_size.width(), outer_size.height());
- yellow_tile.eraseColor(SK_ColorYELLOW);
-
- SkBitmap cyan_tile;
- cyan_tile.allocN32Pixels(inner_size.width(), inner_size.height());
- cyan_tile.eraseColor(SK_ColorCYAN);
-
- resource_provider()->CopyToResource(
- resource_yellow, static_cast<uint8_t*>(yellow_tile.getPixels()),
- outer_size);
- resource_provider()->CopyToResource(
- resource_cyan, static_cast<uint8_t*>(cyan_tile.getPixels()), inner_size);
-
- gfx::Rect root_rect = outer_rect;
-
- int root_render_pass_id = 1;
- std::unique_ptr<RenderPass> root_render_pass = RenderPass::Create();
- root_render_pass->SetNew(root_render_pass_id, root_rect, root_rect,
- gfx::Transform());
- viz::SharedQuadState* shared_quad_state =
- root_render_pass->CreateAndAppendSharedQuadState();
- shared_quad_state->SetAll(gfx::Transform(), outer_rect, outer_rect,
- outer_rect, false, 1.0, SkBlendMode::kSrcOver, 0);
- TileDrawQuad* inner_quad =
- root_render_pass->CreateAndAppendDrawQuad<TileDrawQuad>();
- inner_quad->SetNew(shared_quad_state, inner_rect, inner_rect, needs_blending,
- resource_cyan, gfx::RectF(gfx::SizeF(inner_size)),
- inner_size, false, false);
- TileDrawQuad* outer_quad =
- root_render_pass->CreateAndAppendDrawQuad<TileDrawQuad>();
- outer_quad->SetNew(shared_quad_state, outer_rect, outer_rect, needs_blending,
- resource_yellow, gfx::RectF(gfx::SizeF(outer_size)),
- outer_size, false, false);
-
- RenderPassList list;
- list.push_back(std::move(root_render_pass));
-
- float device_scale_factor = 1.f;
- std::unique_ptr<SkBitmap> output =
- DrawAndCopyOutput(&list, device_scale_factor, outer_size);
- EXPECT_EQ(outer_rect.width(), output->info().width());
- EXPECT_EQ(outer_rect.height(), output->info().height());
-
- EXPECT_EQ(SK_ColorYELLOW, output->getColor(0, 0));
- EXPECT_EQ(SK_ColorYELLOW,
- output->getColor(outer_size.width() - 1, outer_size.height() - 1));
- EXPECT_EQ(SK_ColorCYAN, output->getColor(1, 1));
- EXPECT_EQ(SK_ColorCYAN,
- output->getColor(inner_size.width() - 1, inner_size.height() - 1));
-}
-
-TEST_F(SoftwareRendererTest, TileQuadVisibleRect) {
- gfx::Size tile_size(100, 100);
- gfx::Rect tile_rect(tile_size);
- gfx::Rect visible_rect = tile_rect;
- bool needs_blending = false;
- visible_rect.Inset(1, 2, 3, 4);
- InitializeRenderer(base::WrapUnique(new SoftwareOutputDevice));
-
- viz::ResourceId resource_cyan = resource_provider()->CreateResource(
- tile_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, viz::RGBA_8888,
- gfx::ColorSpace());
-
- SkBitmap cyan_tile; // The lowest five rows are yellow.
- cyan_tile.allocN32Pixels(tile_size.width(), tile_size.height());
- cyan_tile.eraseColor(SK_ColorCYAN);
- cyan_tile.eraseArea(
- SkIRect::MakeLTRB(
- 0, visible_rect.bottom() - 1, tile_rect.width(), tile_rect.bottom()),
- SK_ColorYELLOW);
-
- resource_provider()->CopyToResource(
- resource_cyan, static_cast<uint8_t*>(cyan_tile.getPixels()), tile_size);
-
- gfx::Rect root_rect(tile_size);
-
- int root_render_pass_id = 1;
- std::unique_ptr<RenderPass> root_render_pass = RenderPass::Create();
- root_render_pass->SetNew(root_render_pass_id, root_rect, root_rect,
- gfx::Transform());
- viz::SharedQuadState* shared_quad_state =
- root_render_pass->CreateAndAppendSharedQuadState();
- shared_quad_state->SetAll(gfx::Transform(), tile_rect, tile_rect, tile_rect,
- false, 1.0, SkBlendMode::kSrcOver, 0);
- TileDrawQuad* quad =
- root_render_pass->CreateAndAppendDrawQuad<TileDrawQuad>();
- quad->SetNew(shared_quad_state, tile_rect, tile_rect, needs_blending,
- resource_cyan, gfx::RectF(gfx::SizeF(tile_size)), tile_size,
- false, false);
- quad->visible_rect = visible_rect;
-
- RenderPassList list;
- list.push_back(std::move(root_render_pass));
-
- float device_scale_factor = 1.f;
- std::unique_ptr<SkBitmap> output =
- DrawAndCopyOutput(&list, device_scale_factor, tile_size);
- EXPECT_EQ(tile_rect.width(), output->info().width());
- EXPECT_EQ(tile_rect.height(), output->info().height());
-
- // Check portion of tile not in visible rect isn't drawn.
- const unsigned int kTransparent = SK_ColorTRANSPARENT;
- EXPECT_EQ(kTransparent, output->getColor(0, 0));
- EXPECT_EQ(kTransparent,
- output->getColor(tile_rect.width() - 1, tile_rect.height() - 1));
- EXPECT_EQ(kTransparent,
- output->getColor(visible_rect.x() - 1, visible_rect.y() - 1));
- EXPECT_EQ(kTransparent,
- output->getColor(visible_rect.right(), visible_rect.bottom()));
- // Ensure visible part is drawn correctly.
- EXPECT_EQ(SK_ColorCYAN, output->getColor(visible_rect.x(), visible_rect.y()));
- EXPECT_EQ(
- SK_ColorCYAN,
- output->getColor(visible_rect.right() - 2, visible_rect.bottom() - 2));
- // Ensure last visible line is correct.
- EXPECT_EQ(
- SK_ColorYELLOW,
- output->getColor(visible_rect.right() - 1, visible_rect.bottom() - 1));
-}
-
-TEST_F(SoftwareRendererTest, ShouldClearRootRenderPass) {
- float device_scale_factor = 1.f;
- gfx::Size viewport_size(100, 100);
-
- settings_.should_clear_root_render_pass = false;
- InitializeRenderer(base::WrapUnique(new SoftwareOutputDevice));
-
- RenderPassList list;
-
- // Draw a fullscreen green quad in a first frame.
- int root_clear_pass_id = 1;
- RenderPass* root_clear_pass =
- AddRenderPass(&list, root_clear_pass_id, gfx::Rect(viewport_size),
- gfx::Transform(), FilterOperations());
- AddQuad(root_clear_pass, gfx::Rect(viewport_size), SK_ColorGREEN);
-
- renderer()->DecideRenderPassAllocationsForFrame(list);
-
- std::unique_ptr<SkBitmap> output =
- DrawAndCopyOutput(&list, device_scale_factor, viewport_size);
- EXPECT_EQ(viewport_size.width(), output->info().width());
- EXPECT_EQ(viewport_size.height(), output->info().height());
-
- EXPECT_EQ(SK_ColorGREEN, output->getColor(0, 0));
- EXPECT_EQ(SK_ColorGREEN, output->getColor(viewport_size.width() - 1,
- viewport_size.height() - 1));
-
- list.clear();
-
- // Draw a smaller magenta rect without filling the viewport in a separate
- // frame.
- gfx::Rect smaller_rect(20, 20, 60, 60);
-
- int root_smaller_pass_id = 2;
- RenderPass* root_smaller_pass =
- AddRenderPass(&list, root_smaller_pass_id, gfx::Rect(viewport_size),
- gfx::Transform(), FilterOperations());
- AddQuad(root_smaller_pass, smaller_rect, SK_ColorMAGENTA);
-
- renderer()->DecideRenderPassAllocationsForFrame(list);
-
- output = DrawAndCopyOutput(&list, device_scale_factor, viewport_size);
- EXPECT_EQ(viewport_size.width(), output->info().width());
- EXPECT_EQ(viewport_size.height(), output->info().height());
-
- // If we didn't clear, the borders should still be green.
- EXPECT_EQ(SK_ColorGREEN, output->getColor(0, 0));
- EXPECT_EQ(SK_ColorGREEN, output->getColor(viewport_size.width() - 1,
- viewport_size.height() - 1));
-
- EXPECT_EQ(SK_ColorMAGENTA,
- output->getColor(smaller_rect.x(), smaller_rect.y()));
- EXPECT_EQ(
- SK_ColorMAGENTA,
- output->getColor(smaller_rect.right() - 1, smaller_rect.bottom() - 1));
-}
-
-TEST_F(SoftwareRendererTest, RenderPassVisibleRect) {
- float device_scale_factor = 1.f;
- gfx::Size viewport_size(100, 100);
- InitializeRenderer(base::WrapUnique(new SoftwareOutputDevice));
-
- RenderPassList list;
-
- // Pass drawn as inner quad is magenta.
- gfx::Rect smaller_rect(20, 20, 60, 60);
- int smaller_pass_id = 2;
- RenderPass* smaller_pass =
- AddRenderPass(&list, smaller_pass_id, smaller_rect, gfx::Transform(),
- FilterOperations());
- AddQuad(smaller_pass, smaller_rect, SK_ColorMAGENTA);
-
- // Root pass is green.
- int root_clear_pass_id = 1;
- RenderPass* root_clear_pass =
- AddRenderPass(&list, root_clear_pass_id, gfx::Rect(viewport_size),
- gfx::Transform(), FilterOperations());
- AddRenderPassQuad(root_clear_pass, smaller_pass);
- AddQuad(root_clear_pass, gfx::Rect(viewport_size), SK_ColorGREEN);
-
- // Interior pass quad has smaller visible rect.
- gfx::Rect interior_visible_rect(30, 30, 40, 40);
- root_clear_pass->quad_list.front()->visible_rect = interior_visible_rect;
-
- renderer()->DecideRenderPassAllocationsForFrame(list);
-
- std::unique_ptr<SkBitmap> output =
- DrawAndCopyOutput(&list, device_scale_factor, viewport_size);
- EXPECT_EQ(viewport_size.width(), output->info().width());
- EXPECT_EQ(viewport_size.height(), output->info().height());
-
- EXPECT_EQ(SK_ColorGREEN, output->getColor(0, 0));
- EXPECT_EQ(SK_ColorGREEN, output->getColor(viewport_size.width() - 1,
- viewport_size.height() - 1));
-
- // Part outside visible rect should remain green.
- EXPECT_EQ(SK_ColorGREEN,
- output->getColor(smaller_rect.x(), smaller_rect.y()));
- EXPECT_EQ(
- SK_ColorGREEN,
- output->getColor(smaller_rect.right() - 1, smaller_rect.bottom() - 1));
-
- EXPECT_EQ(
- SK_ColorMAGENTA,
- output->getColor(interior_visible_rect.x(), interior_visible_rect.y()));
- EXPECT_EQ(SK_ColorMAGENTA,
- output->getColor(interior_visible_rect.right() - 1,
- interior_visible_rect.bottom() - 1));
-}
-
-class ClipTrackingCanvas : public SkNWayCanvas {
- public:
- ClipTrackingCanvas(int width, int height) : SkNWayCanvas(width, height) {}
- void onClipRect(const SkRect& rect,
- SkClipOp op,
- ClipEdgeStyle style) override {
- last_clip_rect_ = rect;
- SkNWayCanvas::onClipRect(rect, op, style);
- }
-
- SkRect last_clip_rect() const { return last_clip_rect_; }
-
- private:
- SkRect last_clip_rect_;
-};
-
-class PartialSwapSoftwareOutputDevice : public SoftwareOutputDevice {
- public:
- // SoftwareOutputDevice overrides.
- SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override {
- damage_rect_at_start_ = damage_rect;
- canvas_.reset(new ClipTrackingCanvas(viewport_pixel_size_.width(),
- viewport_pixel_size_.height()));
- canvas_->addCanvas(SoftwareOutputDevice::BeginPaint(damage_rect));
- return canvas_.get();
- }
-
- void EndPaint() override {
- clip_rect_at_end_ = gfx::SkRectToRectF(canvas_->last_clip_rect());
- SoftwareOutputDevice::EndPaint();
- }
-
- gfx::Rect damage_rect_at_start() const { return damage_rect_at_start_; }
- gfx::RectF clip_rect_at_end() const { return clip_rect_at_end_; }
-
- private:
- std::unique_ptr<ClipTrackingCanvas> canvas_;
- gfx::Rect damage_rect_at_start_;
- gfx::RectF clip_rect_at_end_;
-};
-
-TEST_F(SoftwareRendererTest, PartialSwap) {
- float device_scale_factor = 1.f;
- gfx::Size viewport_size(100, 100);
-
- settings_.partial_swap_enabled = true;
-
- auto device_owned = std::make_unique<PartialSwapSoftwareOutputDevice>();
- auto* device = device_owned.get();
- InitializeRenderer(std::move(device_owned));
-
- RenderPassList list;
-
- int root_pass_id = 1;
- RenderPass* root_pass =
- AddRenderPass(&list, root_pass_id, gfx::Rect(viewport_size),
- gfx::Transform(), FilterOperations());
- AddQuad(root_pass, gfx::Rect(viewport_size), SK_ColorGREEN);
-
- // Partial frame, we should pass this rect to the SoftwareOutputDevice.
- // partial swap is enabled.
- root_pass->damage_rect = gfx::Rect(2, 2, 3, 3);
-
- renderer()->DecideRenderPassAllocationsForFrame(list);
- renderer()->DrawFrame(&list, device_scale_factor, viewport_size);
-
- // The damage rect should be reported to the SoftwareOutputDevice.
- EXPECT_EQ(gfx::Rect(2, 2, 3, 3), device->damage_rect_at_start());
- // The SkCanvas should be clipped to the damage rect.
- EXPECT_EQ(gfx::RectF(2, 2, 3, 3), device->clip_rect_at_end());
-}
-
-} // namespace
-} // namespace cc
diff --git a/chromium/cc/output/texture_mailbox_deleter.cc b/chromium/cc/output/texture_mailbox_deleter.cc
deleted file mode 100644
index 3aa308c5573..00000000000
--- a/chromium/cc/output/texture_mailbox_deleter.cc
+++ /dev/null
@@ -1,100 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/texture_mailbox_deleter.h"
-
-#include <stddef.h>
-
-#include "base/bind.h"
-#include "base/location.h"
-#include "base/memory/weak_ptr.h"
-#include "base/single_thread_task_runner.h"
-#include "components/viz/common/gpu/context_provider.h"
-#include "components/viz/common/quads/single_release_callback.h"
-#include "gpu/command_buffer/client/gles2_interface.h"
-#include "gpu/command_buffer/common/sync_token.h"
-
-namespace cc {
-
-static void DeleteTextureOnImplThread(
- const scoped_refptr<viz::ContextProvider>& context_provider,
- unsigned texture_id,
- const gpu::SyncToken& sync_token,
- bool is_lost) {
- if (sync_token.HasData()) {
- context_provider->ContextGL()->WaitSyncTokenCHROMIUM(
- sync_token.GetConstData());
- }
- context_provider->ContextGL()->DeleteTextures(1, &texture_id);
-}
-
-static void PostTaskFromMainToImplThread(
- scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
- viz::ReleaseCallback run_impl_callback,
- const gpu::SyncToken& sync_token,
- bool is_lost) {
- // This posts the task to RunDeleteTextureOnImplThread().
- impl_task_runner->PostTask(
- FROM_HERE, base::BindOnce(run_impl_callback, sync_token, is_lost));
-}
-
-TextureMailboxDeleter::TextureMailboxDeleter(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner)
- : impl_task_runner_(std::move(task_runner)), weak_ptr_factory_(this) {}
-
-TextureMailboxDeleter::~TextureMailboxDeleter() {
- for (size_t i = 0; i < impl_callbacks_.size(); ++i)
- impl_callbacks_.at(i)->Run(gpu::SyncToken(), true);
-}
-
-std::unique_ptr<viz::SingleReleaseCallback>
-TextureMailboxDeleter::GetReleaseCallback(
- scoped_refptr<viz::ContextProvider> context_provider,
- unsigned texture_id) {
- // This callback owns the |context_provider|. It must be destroyed on the impl
- // thread. Upon destruction of this class, the callback must immediately be
- // destroyed.
- std::unique_ptr<viz::SingleReleaseCallback> impl_callback =
- viz::SingleReleaseCallback::Create(base::Bind(
- &DeleteTextureOnImplThread, std::move(context_provider), texture_id));
-
- impl_callbacks_.push_back(std::move(impl_callback));
-
- // The raw pointer to the impl-side callback is valid as long as this
- // class is alive. So we guard it with a WeakPtr.
- viz::ReleaseCallback run_impl_callback(
- base::Bind(&TextureMailboxDeleter::RunDeleteTextureOnImplThread,
- weak_ptr_factory_.GetWeakPtr(), impl_callbacks_.back().get()));
-
- // Provide a callback for the main thread that posts back to the impl
- // thread.
- std::unique_ptr<viz::SingleReleaseCallback> main_callback;
- if (impl_task_runner_) {
- main_callback = viz::SingleReleaseCallback::Create(base::Bind(
- &PostTaskFromMainToImplThread, impl_task_runner_, run_impl_callback));
- } else {
- main_callback = viz::SingleReleaseCallback::Create(run_impl_callback);
- }
-
- return main_callback;
-}
-
-void TextureMailboxDeleter::RunDeleteTextureOnImplThread(
- viz::SingleReleaseCallback* impl_callback,
- const gpu::SyncToken& sync_token,
- bool is_lost) {
- for (size_t i = 0; i < impl_callbacks_.size(); ++i) {
- if (impl_callbacks_[i].get() == impl_callback) {
- // Run the callback, then destroy it here on the impl thread.
- impl_callbacks_[i]->Run(sync_token, is_lost);
- impl_callbacks_.erase(impl_callbacks_.begin() + i);
- return;
- }
- }
-
- NOTREACHED() << "The Callback returned by GetDeleteCallback() was called "
- << "more than once.";
-}
-
-} // namespace cc
diff --git a/chromium/cc/output/texture_mailbox_deleter.h b/chromium/cc/output/texture_mailbox_deleter.h
deleted file mode 100644
index 8d6a8901037..00000000000
--- a/chromium/cc/output/texture_mailbox_deleter.h
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_TEXTURE_MAILBOX_DELETER_H_
-#define CC_OUTPUT_TEXTURE_MAILBOX_DELETER_H_
-
-#include <memory>
-#include <vector>
-
-#include "base/memory/weak_ptr.h"
-#include "cc/cc_export.h"
-
-namespace base {
-class SingleThreadTaskRunner;
-}
-
-namespace gpu {
-struct SyncToken;
-}
-
-namespace viz {
-class ContextProvider;
-class SingleReleaseCallback;
-}
-
-namespace cc {
-
-class CC_EXPORT TextureMailboxDeleter {
- public:
- // task_runner corresponds with the thread the delete task should be posted
- // to. If null, the delete will happen on the calling thread.
- explicit TextureMailboxDeleter(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner);
- ~TextureMailboxDeleter();
-
- // Returns a Callback that can be used as the viz::ReleaseCallback for a
- // TextureMailbox attached to the |texture_id|. The viz::ReleaseCallback can
- // be passed to other threads and will destroy the texture, once it is
- // run, on the impl thread. If the TextureMailboxDeleter is destroyed
- // due to the compositor shutting down, then the viz::ReleaseCallback will
- // become a no-op and the texture will be deleted immediately on the
- // impl thread, along with dropping the reference to the viz::ContextProvider.
- std::unique_ptr<viz::SingleReleaseCallback> GetReleaseCallback(
- scoped_refptr<viz::ContextProvider> context_provider,
- unsigned texture_id);
-
- private:
- // Runs the |impl_callback| to delete the texture and removes the callback
- // from the |impl_callbacks_| list.
- void RunDeleteTextureOnImplThread(viz::SingleReleaseCallback* impl_callback,
- const gpu::SyncToken& sync_token,
- bool is_lost);
-
- scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_;
- std::vector<std::unique_ptr<viz::SingleReleaseCallback>> impl_callbacks_;
- base::WeakPtrFactory<TextureMailboxDeleter> weak_ptr_factory_;
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_TEXTURE_MAILBOX_DELETER_H_
diff --git a/chromium/cc/output/texture_mailbox_deleter_unittest.cc b/chromium/cc/output/texture_mailbox_deleter_unittest.cc
deleted file mode 100644
index d9850edbd6f..00000000000
--- a/chromium/cc/output/texture_mailbox_deleter_unittest.cc
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/texture_mailbox_deleter.h"
-
-#include "base/single_thread_task_runner.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "cc/test/test_context_provider.h"
-#include "cc/test/test_web_graphics_context_3d.h"
-#include "components/viz/common/quads/single_release_callback.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace cc {
-namespace {
-
-TEST(TextureMailboxDeleterTest, Destroy) {
- std::unique_ptr<TextureMailboxDeleter> deleter(
- new TextureMailboxDeleter(base::ThreadTaskRunnerHandle::Get()));
-
- scoped_refptr<TestContextProvider> context_provider =
- TestContextProvider::Create();
- context_provider->BindToCurrentThread();
-
- GLuint texture_id = 0u;
- context_provider->ContextGL()->GenTextures(1, &texture_id);
-
- EXPECT_TRUE(context_provider->HasOneRef());
- EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures());
-
- std::unique_ptr<viz::SingleReleaseCallback> cb =
- deleter->GetReleaseCallback(context_provider, texture_id);
- EXPECT_FALSE(context_provider->HasOneRef());
- EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures());
-
- // When the deleter is destroyed, it immediately drops its ref on the
- // viz::ContextProvider, and deletes the texture.
- deleter = nullptr;
- EXPECT_TRUE(context_provider->HasOneRef());
- EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures());
-
- // Run the scoped release callback before destroying it, but it won't do
- // anything.
- cb->Run(gpu::SyncToken(), false);
-}
-
-TEST(TextureMailboxDeleterTest, NullTaskRunner) {
- std::unique_ptr<TextureMailboxDeleter> deleter(
- new TextureMailboxDeleter(nullptr));
-
- scoped_refptr<TestContextProvider> context_provider =
- TestContextProvider::Create();
- context_provider->BindToCurrentThread();
-
- GLuint texture_id = 0u;
- context_provider->ContextGL()->GenTextures(1, &texture_id);
-
- EXPECT_TRUE(context_provider->HasOneRef());
- EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures());
-
- std::unique_ptr<viz::SingleReleaseCallback> cb =
- deleter->GetReleaseCallback(context_provider, texture_id);
- EXPECT_FALSE(context_provider->HasOneRef());
- EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures());
-
- cb->Run(gpu::SyncToken(), false);
-
- // With no task runner the callback will immediately drops its ref on the
- // viz::ContextProvider and delete the texture.
- EXPECT_TRUE(context_provider->HasOneRef());
- EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures());
-}
-
-} // namespace
-} // namespace cc
diff --git a/chromium/cc/output/vulkan_renderer.cc b/chromium/cc/output/vulkan_renderer.cc
deleted file mode 100644
index 78afcb5f5a0..00000000000
--- a/chromium/cc/output/vulkan_renderer.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright (c) 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/output/vulkan_renderer.h"
-#include "cc/output/output_surface_frame.h"
-
-namespace cc {
-
-VulkanRenderer::~VulkanRenderer() {}
-
-void VulkanRenderer::SwapBuffers(std::vector<ui::LatencyInfo> latency_info) {
- OutputSurfaceFrame output_frame;
- output_frame.latency_info = std::move(latency_info);
- output_surface_->SwapBuffers(std::move(output_frame));
-}
-
-VulkanRenderer::VulkanRenderer(const RendererSettings* settings,
- OutputSurface* output_surface,
- ResourceProvider* resource_provider,
- TextureMailboxDeleter* texture_mailbox_deleter,
- int highp_threshold_min)
- : DirectRenderer(settings, output_surface, resource_provider) {}
-
-void VulkanRenderer::DidChangeVisibility() {
- NOTIMPLEMENTED();
-}
-
-void VulkanRenderer::BindFramebufferToOutputSurface(DrawingFrame* frame) {
- NOTIMPLEMENTED();
-}
-
-bool VulkanRenderer::BindFramebufferToTexture(DrawingFrame* frame,
- const ScopedResource* resource) {
- NOTIMPLEMENTED();
- return false;
-}
-
-void VulkanRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) {
- NOTIMPLEMENTED();
-}
-
-void VulkanRenderer::PrepareSurfaceForPass(
- DrawingFrame* frame,
- SurfaceInitializationMode initialization_mode,
- const gfx::Rect& render_pass_scissor) {
- NOTIMPLEMENTED();
-}
-
-void VulkanRenderer::DoDrawQuad(DrawingFrame* frame,
- const DrawQuad* quad,
- const gfx::QuadF* clip_region) {
- NOTIMPLEMENTED();
-}
-
-void VulkanRenderer::BeginDrawingFrame(DrawingFrame* frame) {
- NOTIMPLEMENTED();
-}
-
-void VulkanRenderer::FinishDrawingFrame(DrawingFrame* frame) {
- NOTIMPLEMENTED();
-}
-
-void VulkanRenderer::FinishDrawingQuadList() {
- NOTIMPLEMENTED();
-}
-
-bool VulkanRenderer::FlippedFramebuffer(const DrawingFrame* frame) const {
- NOTIMPLEMENTED();
- return false;
-}
-
-void VulkanRenderer::EnsureScissorTestEnabled() {
- NOTIMPLEMENTED();
-}
-
-void VulkanRenderer::EnsureScissorTestDisabled() {
- NOTIMPLEMENTED();
-}
-
-void VulkanRenderer::CopyCurrentRenderPassToBitmap(
- DrawingFrame* frame,
- std::unique_ptr<viz::CopyOutputRequest> request) {
- NOTIMPLEMENTED();
-}
-
-bool VulkanRenderer::CanPartialSwap() {
- NOTIMPLEMENTED();
- return false;
-}
-
-} // namespace cc
diff --git a/chromium/cc/output/vulkan_renderer.h b/chromium/cc/output/vulkan_renderer.h
deleted file mode 100644
index 66b78319c67..00000000000
--- a/chromium/cc/output/vulkan_renderer.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright (c) 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_OUTPUT_VULKAN_RENDERER_H_
-#define CC_OUTPUT_VULKAN_RENDERER_H_
-
-#include "cc/base/cc_export.h"
-#include "cc/output/direct_renderer.h"
-#include "ui/latency/latency_info.h"
-
-namespace cc {
-
-class TextureMailboxDeleter;
-
-class CC_EXPORT VulkanRenderer : public DirectRenderer {
- public:
- VulkanRenderer(const RendererSettings* settings,
- OutputSurface* output_surface,
- ResourceProvider* resource_provider,
- TextureMailboxDeleter* texture_mailbox_deleter,
- int highp_threshold_min);
- ~VulkanRenderer() override;
-
- // Implementation of public DirectRenderer functions.
- void SwapBuffers(std::vector<ui::LatencyInfo> latency_info) override;
-
- protected:
- // Implementations of protected Renderer functions.
- void DidChangeVisibility() override;
-
- // Implementations of protected DirectRenderer functions.
- void BindFramebufferToOutputSurface(DrawingFrame* frame) override;
- bool BindFramebufferToTexture(DrawingFrame* frame,
- const ScopedResource* resource) override;
- void SetScissorTestRect(const gfx::Rect& scissor_rect) override;
- void PrepareSurfaceForPass(DrawingFrame* frame,
- SurfaceInitializationMode initialization_mode,
- const gfx::Rect& render_pass_scissor) override;
- void DoDrawQuad(DrawingFrame* frame,
- const DrawQuad* quad,
- const gfx::QuadF* clip_region) override;
- void BeginDrawingFrame(DrawingFrame* frame) override;
- void FinishDrawingFrame(DrawingFrame* frame) override;
- void FinishDrawingQuadList() override;
- bool FlippedFramebuffer(const DrawingFrame* frame) const override;
- void EnsureScissorTestEnabled() override;
- void EnsureScissorTestDisabled() override;
- void CopyCurrentRenderPassToBitmap(
- DrawingFrame* frame,
- std::unique_ptr<viz::CopyOutputRequest> request) override;
- bool CanPartialSwap() override;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(VulkanRenderer);
-};
-
-} // namespace cc
-
-#endif // CC_OUTPUT_VULKAN_RENDERER_H_
diff --git a/chromium/cc/paint/BUILD.gn b/chromium/cc/paint/BUILD.gn
index a3ef3d029c8..037891d448e 100644
--- a/chromium/cc/paint/BUILD.gn
+++ b/chromium/cc/paint/BUILD.gn
@@ -16,6 +16,7 @@ cc_component("paint") {
"display_item_list.h",
"draw_image.cc",
"draw_image.h",
+ "image_animation_count.h",
"image_id.h",
"image_provider.cc",
"image_provider.h",
@@ -44,6 +45,8 @@ cc_component("paint") {
"paint_shader.h",
"record_paint_canvas.cc",
"record_paint_canvas.h",
+ "scoped_image_flags.cc",
+ "scoped_image_flags.h",
"skia_paint_canvas.cc",
"skia_paint_canvas.h",
"skia_paint_image_generator.cc",
diff --git a/chromium/cc/paint/discardable_image_map.cc b/chromium/cc/paint/discardable_image_map.cc
index 430c5cf6651..05dbe8b2911 100644
--- a/chromium/cc/paint/discardable_image_map.cc
+++ b/chromium/cc/paint/discardable_image_map.cc
@@ -27,6 +27,8 @@ SkRect MapRect(const SkMatrix& matrix, const SkRect& src) {
return dst;
}
+// This canvas is used only for tracking transform/clip/filter state from the
+// non-drawing ops.
class PaintTrackingCanvas final : public SkNoDrawCanvas {
public:
PaintTrackingCanvas(int width, int height) : SkNoDrawCanvas(width, height) {}
@@ -75,51 +77,13 @@ class PaintTrackingCanvas final : public SkNoDrawCanvas {
class DiscardableImageGenerator {
public:
- DiscardableImageGenerator(int width, int height) : canvas_(width, height) {}
- ~DiscardableImageGenerator() = default;
-
- void GatherDiscardableImages(const PaintOpBuffer* buffer) {
- if (!buffer->HasDiscardableImages())
- return;
-
- PlaybackParams params(nullptr, canvas_.getTotalMatrix());
- canvas_.save();
- // TODO(khushalsagar): Optimize out save/restore blocks if there are no
- // images in the draw ops between them.
- for (auto* op : PaintOpBuffer::Iterator(buffer)) {
- if (op->IsDrawOp()) {
- SkRect op_rect;
- if (op->IsPaintOpWithFlags() && PaintOp::GetBounds(op, &op_rect)) {
- AddImageFromFlags(op_rect,
- static_cast<const PaintOpWithFlags*>(op)->flags);
- }
-
- PaintOpType op_type = static_cast<PaintOpType>(op->type);
- if (op_type == PaintOpType::DrawImage) {
- auto* image_op = static_cast<DrawImageOp*>(op);
- auto* sk_image = image_op->image.GetSkImage().get();
- AddImage(image_op->image,
- SkRect::MakeIWH(sk_image->width(), sk_image->height()),
- SkRect::MakeXYWH(image_op->left, image_op->top,
- sk_image->width(), sk_image->height()),
- nullptr, image_op->flags);
- } else if (op_type == PaintOpType::DrawImageRect) {
- auto* image_rect_op = static_cast<DrawImageRectOp*>(op);
- SkMatrix matrix;
- matrix.setRectToRect(image_rect_op->src, image_rect_op->dst,
- SkMatrix::kFill_ScaleToFit);
- AddImage(image_rect_op->image, image_rect_op->src, image_rect_op->dst,
- &matrix, image_rect_op->flags);
- } else if (op_type == PaintOpType::DrawRecord) {
- GatherDiscardableImages(
- static_cast<const DrawRecordOp*>(op)->record.get());
- }
- } else {
- op->Raster(&canvas_, params);
- }
- }
- canvas_.restore();
+ DiscardableImageGenerator(int width,
+ int height,
+ const PaintOpBuffer* buffer) {
+ PaintTrackingCanvas canvas(width, height);
+ GatherDiscardableImages(buffer, nullptr, &canvas);
}
+ ~DiscardableImageGenerator() = default;
std::vector<std::pair<DrawImage, gfx::Rect>> TakeImages() {
return std::move(image_set_);
@@ -127,6 +91,11 @@ class DiscardableImageGenerator {
base::flat_map<PaintImage::Id, gfx::Rect> TakeImageIdToRectMap() {
return std::move(image_id_to_rect_);
}
+ std::vector<DiscardableImageMap::AnimatedImageMetadata>
+ TakeAnimatedImagesMetadata() {
+ return std::move(animated_images_metadata_);
+ }
+
void RecordColorHistograms() const {
if (color_stats_total_image_count_ > 0) {
int srgb_image_percent = (100 * color_stats_srgb_image_count_) /
@@ -148,47 +117,111 @@ class DiscardableImageGenerator {
}
private:
- void AddImageFromFlags(const SkRect& rect, const PaintFlags& flags) {
- if (!flags.HasShader() ||
- flags.getShader()->shader_type() != PaintShader::Type::kImage)
+ // Adds discardable images from |buffer| to the set of images tracked by
+ // this generator. If |buffer| is being used in a DrawOp that requires
+ // rasterization of the buffer as a pre-processing step for execution of the
+ // op (for instance, with PaintRecord backed PaintShaders),
+ // |top_level_op_rect| is set to the rect for that op. If provided, the
+ // |top_level_op_rect| will be used as the rect for tracking the position of
+ // this image in the top-level buffer.
+ void GatherDiscardableImages(const PaintOpBuffer* buffer,
+ const gfx::Rect* top_level_op_rect,
+ PaintTrackingCanvas* canvas) {
+ if (!buffer->HasDiscardableImages())
return;
- const PaintImage& paint_image = flags.getShader()->paint_image();
- SkMatrix local_matrix = flags.getShader()->GetLocalMatrix();
- AddImage(paint_image,
- SkRect::MakeWH(paint_image.width(), paint_image.height()), rect,
- &local_matrix, flags);
- }
+ // Prevent PaintOpBuffers from having side effects back into the canvas.
+ SkAutoCanvasRestore save_restore(canvas, true);
- void AddImage(PaintImage paint_image,
- const SkRect& src_rect,
- const SkRect& rect,
- const SkMatrix* local_matrix,
- const PaintFlags& flags) {
- if (!paint_image.IsLazyGenerated())
- return;
+ PlaybackParams params(nullptr, canvas->getTotalMatrix());
+ // TODO(khushalsagar): Optimize out save/restore blocks if there are no
+ // images in the draw ops between them.
+ for (auto* op : PaintOpBuffer::Iterator(buffer)) {
+ if (!op->IsDrawOp()) {
+ op->Raster(canvas, params);
+ continue;
+ } else if (!PaintOp::OpHasDiscardableImages(op)) {
+ continue;
+ }
+
+ gfx::Rect op_rect;
+ base::Optional<gfx::Rect> local_op_rect;
+
+ if (top_level_op_rect) {
+ op_rect = *top_level_op_rect;
+ } else {
+ local_op_rect = ComputePaintRect(op, canvas);
+ if (local_op_rect.value().IsEmpty())
+ continue;
+
+ op_rect = local_op_rect.value();
+ }
- const SkRect& clip_rect = SkRect::Make(canvas_.getDeviceClipBounds());
- const SkMatrix& ctm = canvas_.getTotalMatrix();
+ const SkMatrix& ctm = canvas->getTotalMatrix();
+ if (op->IsPaintOpWithFlags()) {
+ AddImageFromFlags(op_rect,
+ static_cast<const PaintOpWithFlags*>(op)->flags, ctm);
+ }
- SkRect paint_rect = MapRect(ctm, rect);
- SkPaint paint = flags.ToSkPaint();
- bool computed_paint_bounds =
- canvas_.ComputePaintBounds(paint_rect, &paint, &paint_rect);
- if (!computed_paint_bounds) {
- // TODO(vmpstr): UMA this case.
- paint_rect = clip_rect;
+ PaintOpType op_type = static_cast<PaintOpType>(op->type);
+ if (op_type == PaintOpType::DrawImage) {
+ auto* image_op = static_cast<DrawImageOp*>(op);
+ auto* sk_image = image_op->image.GetSkImage().get();
+ AddImage(image_op->image,
+ SkRect::MakeIWH(sk_image->width(), sk_image->height()),
+ op_rect, ctm, image_op->flags.getFilterQuality());
+ } else if (op_type == PaintOpType::DrawImageRect) {
+ auto* image_rect_op = static_cast<DrawImageRectOp*>(op);
+ SkMatrix matrix = ctm;
+ matrix.postConcat(SkMatrix::MakeRectToRect(image_rect_op->src,
+ image_rect_op->dst,
+ SkMatrix::kFill_ScaleToFit));
+ AddImage(image_rect_op->image, image_rect_op->src, op_rect, matrix,
+ image_rect_op->flags.getFilterQuality());
+ } else if (op_type == PaintOpType::DrawRecord) {
+ GatherDiscardableImages(
+ static_cast<const DrawRecordOp*>(op)->record.get(),
+ top_level_op_rect, canvas);
+ }
}
+ }
- // Clamp the image rect by the current clip rect.
- if (!paint_rect.intersect(clip_rect))
- return;
+ // Given the |op_rect|, which is the rect for the draw op, returns the
+ // transformed rect accounting for the current transform, clip and paint
+ // state on |canvas_|.
+ gfx::Rect ComputePaintRect(const PaintOp* op, PaintTrackingCanvas* canvas) {
+ const SkRect& clip_rect = SkRect::Make(canvas->getDeviceClipBounds());
+ const SkMatrix& ctm = canvas->getTotalMatrix();
+
+ gfx::Rect transformed_rect;
+ SkRect op_rect;
+ if (!PaintOp::GetBounds(op, &op_rect)) {
+ // If we can't provide a conservative bounding rect for the op, assume it
+ // covers the complete current clip.
+ transformed_rect = gfx::ToEnclosingRect(gfx::SkRectToRectF(clip_rect));
+ } else {
+ const PaintFlags* flags =
+ op->IsPaintOpWithFlags()
+ ? &static_cast<const PaintOpWithFlags*>(op)->flags
+ : nullptr;
+ SkPaint paint;
+ if (flags)
+ paint = flags->ToSkPaint();
+
+ SkRect paint_rect = MapRect(ctm, op_rect);
+ bool computed_paint_bounds =
+ canvas->ComputePaintBounds(paint_rect, &paint, &paint_rect);
+ if (!computed_paint_bounds) {
+ // TODO(vmpstr): UMA this case.
+ paint_rect = clip_rect;
+ }
- SkFilterQuality filter_quality = flags.getFilterQuality();
+ // Clamp the image rect by the current clip rect.
+ if (!paint_rect.intersect(clip_rect))
+ return gfx::Rect();
- SkIRect src_irect;
- src_rect.roundOut(&src_irect);
- gfx::Rect image_rect = gfx::ToEnclosingRect(gfx::SkRectToRectF(paint_rect));
+ transformed_rect = gfx::ToEnclosingRect(gfx::SkRectToRectF(paint_rect));
+ }
// During raster, we use the device clip bounds on the canvas, which outsets
// the actual clip by 1 due to the possibility of antialiasing. Account for
@@ -200,7 +233,52 @@ class DiscardableImageGenerator {
// raster time, since we might be sending a larger-than-one-item display
// item to skia, which means that skia will internally determine whether to
// raster the picture (using device clip bounds that are outset).
- image_rect.Inset(-1, -1);
+ transformed_rect.Inset(-1, -1);
+ return transformed_rect;
+ }
+
+ void AddImageFromFlags(const gfx::Rect& op_rect,
+ const PaintFlags& flags,
+ const SkMatrix& ctm) {
+ if (!flags.getShader())
+ return;
+
+ if (flags.getShader()->shader_type() == PaintShader::Type::kImage) {
+ const PaintImage& paint_image = flags.getShader()->paint_image();
+ SkMatrix matrix = ctm;
+ matrix.postConcat(flags.getShader()->GetLocalMatrix());
+ AddImage(paint_image,
+ SkRect::MakeWH(paint_image.width(), paint_image.height()),
+ op_rect, matrix, flags.getFilterQuality());
+ } else if (flags.getShader()->shader_type() ==
+ PaintShader::Type::kPaintRecord &&
+ flags.getShader()->paint_record()->HasDiscardableImages()) {
+ SkRect scaled_tile_rect;
+ if (!flags.getShader()->GetRasterizationTileRect(ctm,
+ &scaled_tile_rect)) {
+ return;
+ }
+
+ PaintTrackingCanvas canvas(scaled_tile_rect.width(),
+ scaled_tile_rect.height());
+ canvas.setMatrix(SkMatrix::MakeRectToRect(flags.getShader()->tile(),
+ scaled_tile_rect,
+ SkMatrix::kFill_ScaleToFit));
+ GatherDiscardableImages(flags.getShader()->paint_record().get(), &op_rect,
+ &canvas);
+ }
+ }
+
+ void AddImage(PaintImage paint_image,
+ const SkRect& src_rect,
+ const gfx::Rect& image_rect,
+ const SkMatrix& matrix,
+ SkFilterQuality filter_quality) {
+ if (!paint_image.IsLazyGenerated())
+ return;
+
+ SkIRect src_irect;
+ src_rect.roundOut(&src_irect);
// Make a note if any image was originally specified in a non-sRGB color
// space.
@@ -212,21 +290,24 @@ class DiscardableImageGenerator {
color_stats_srgb_image_count_++;
}
- SkMatrix matrix = ctm;
- if (local_matrix)
- matrix.postConcat(*local_matrix);
-
image_id_to_rect_[paint_image.stable_id()].Union(image_rect);
+
+ if (paint_image.ShouldAnimate()) {
+ animated_images_metadata_.emplace_back(
+ paint_image.stable_id(), paint_image.completion_state(),
+ paint_image.GetFrameMetadata(), paint_image.repetition_count(),
+ paint_image.reset_animation_sequence_id());
+ }
+
image_set_.emplace_back(
DrawImage(std::move(paint_image), src_irect, filter_quality, matrix),
image_rect);
}
- // This canvas is used only for tracking transform/clip/filter state from the
- // non-drawing ops.
- PaintTrackingCanvas canvas_;
std::vector<std::pair<DrawImage, gfx::Rect>> image_set_;
base::flat_map<PaintImage::Id, gfx::Rect> image_id_to_rect_;
+ std::vector<DiscardableImageMap::AnimatedImageMetadata>
+ animated_images_metadata_;
// Statistics about the number of images and pixels that will require color
// conversion if the target color space is not sRGB.
@@ -248,10 +329,11 @@ void DiscardableImageMap::Generate(const PaintOpBuffer* paint_op_buffer,
if (!paint_op_buffer->HasDiscardableImages())
return;
- DiscardableImageGenerator generator(bounds.right(), bounds.bottom());
- generator.GatherDiscardableImages(paint_op_buffer);
+ DiscardableImageGenerator generator(bounds.right(), bounds.bottom(),
+ paint_op_buffer);
generator.RecordColorHistograms();
image_id_to_rect_ = generator.TakeImageIdToRectMap();
+ animated_images_metadata_ = generator.TakeAnimatedImagesMetadata();
all_images_are_srgb_ = generator.all_images_are_srgb();
auto images = generator.TakeImages();
images_rtree_.Build(
@@ -279,4 +361,21 @@ void DiscardableImageMap::Reset() {
images_rtree_.Reset();
}
+DiscardableImageMap::AnimatedImageMetadata::AnimatedImageMetadata(
+ PaintImage::Id paint_image_id,
+ PaintImage::CompletionState completion_state,
+ std::vector<FrameMetadata> frames,
+ int repetition_count,
+ PaintImage::AnimationSequenceId reset_animation_sequence_id)
+ : paint_image_id(paint_image_id),
+ completion_state(completion_state),
+ frames(std::move(frames)),
+ repetition_count(repetition_count),
+ reset_animation_sequence_id(reset_animation_sequence_id) {}
+
+DiscardableImageMap::AnimatedImageMetadata::~AnimatedImageMetadata() = default;
+
+DiscardableImageMap::AnimatedImageMetadata::AnimatedImageMetadata(
+ const AnimatedImageMetadata& other) = default;
+
} // namespace cc
diff --git a/chromium/cc/paint/discardable_image_map.h b/chromium/cc/paint/discardable_image_map.h
index 1da2a0c06cc..69bf34cb124 100644
--- a/chromium/cc/paint/discardable_image_map.h
+++ b/chromium/cc/paint/discardable_image_map.h
@@ -11,6 +11,7 @@
#include "base/containers/flat_map.h"
#include "cc/base/rtree.h"
#include "cc/paint/draw_image.h"
+#include "cc/paint/image_animation_count.h"
#include "cc/paint/image_id.h"
#include "cc/paint/paint_export.h"
#include "cc/paint/paint_flags.h"
@@ -29,6 +30,23 @@ class PaintOpBuffer;
// rect and get back a list of DrawImages in that rect.
class CC_PAINT_EXPORT DiscardableImageMap {
public:
+ struct CC_PAINT_EXPORT AnimatedImageMetadata {
+ AnimatedImageMetadata(
+ PaintImage::Id paint_image_id,
+ PaintImage::CompletionState completion_state,
+ std::vector<FrameMetadata> frames,
+ int repetition_count,
+ PaintImage::AnimationSequenceId reset_animation_sequence_id);
+ AnimatedImageMetadata(const AnimatedImageMetadata& other);
+ ~AnimatedImageMetadata();
+
+ PaintImage::Id paint_image_id;
+ PaintImage::CompletionState completion_state;
+ std::vector<FrameMetadata> frames;
+ int repetition_count;
+ PaintImage::AnimationSequenceId reset_animation_sequence_id;
+ };
+
DiscardableImageMap();
~DiscardableImageMap();
@@ -37,6 +55,9 @@ class CC_PAINT_EXPORT DiscardableImageMap {
std::vector<const DrawImage*>* images) const;
gfx::Rect GetRectForImage(PaintImage::Id image_id) const;
bool all_images_are_srgb() const { return all_images_are_srgb_; }
+ const std::vector<AnimatedImageMetadata>& animated_images_metadata() const {
+ return animated_images_metadata_;
+ }
void Reset();
void Generate(const PaintOpBuffer* paint_op_buffer, const gfx::Rect& bounds);
@@ -52,6 +73,7 @@ class CC_PAINT_EXPORT DiscardableImageMap {
base::flat_map<PaintImage::Id, gfx::Rect> image_id_to_rect);
base::flat_map<PaintImage::Id, gfx::Rect> image_id_to_rect_;
+ std::vector<AnimatedImageMetadata> animated_images_metadata_;
bool all_images_are_srgb_ = false;
RTree<DrawImage> images_rtree_;
diff --git a/chromium/cc/paint/discardable_image_map_unittest.cc b/chromium/cc/paint/discardable_image_map_unittest.cc
index a00aee5205b..6eb8ba85761 100644
--- a/chromium/cc/paint/discardable_image_map_unittest.cc
+++ b/chromium/cc/paint/discardable_image_map_unittest.cc
@@ -9,6 +9,7 @@
#include <memory>
#include "base/memory/ref_counted.h"
+#include "base/test/gtest_util.h"
#include "base/values.h"
#include "cc/base/region.h"
#include "cc/paint/paint_flags.h"
@@ -60,7 +61,8 @@ class DiscardableImageMapTest : public testing::Test {
image_map.GetDiscardableImagesInRect(rect, &draw_image_ptrs);
std::vector<DrawImage> draw_images;
for (const auto* image : draw_image_ptrs)
- draw_images.push_back(DrawImage(*image, 1.f, target_color_space));
+ draw_images.push_back(DrawImage(
+ *image, 1.f, PaintImage::kDefaultFrameIndex, target_color_space));
std::vector<PositionScaleDrawImage> position_draw_images;
for (DrawImage& image : image_map.images_rtree_.Search(rect)) {
@@ -348,7 +350,8 @@ TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMassiveImage) {
content_layer_client.set_bounds(visible_rect.size());
PaintImage discardable_image =
- CreateDiscardablePaintImage(gfx::Size(1 << 25, 1 << 25));
+ CreateDiscardablePaintImage(gfx::Size(1 << 25, 1 << 25), nullptr,
+ false /* allocate_encoded_memory */);
PaintFlags flags;
content_layer_client.add_draw_image(discardable_image, gfx::Point(0, 0),
flags);
@@ -426,8 +429,10 @@ TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMaxImage) {
content_layer_client.set_bounds(visible_rect.size());
int dimension = std::numeric_limits<int>::max();
- PaintImage discardable_image =
- CreateDiscardablePaintImage(gfx::Size(dimension, dimension));
+ sk_sp<SkColorSpace> no_color_space;
+ PaintImage discardable_image = CreateDiscardablePaintImage(
+ gfx::Size(dimension, dimension), no_color_space,
+ false /* allocate_encoded_memory */);
PaintFlags flags;
content_layer_client.add_draw_image(discardable_image, gfx::Point(42, 42),
flags);
@@ -460,12 +465,16 @@ TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMaxImageMaxLayer) {
FakeContentLayerClient content_layer_client;
content_layer_client.set_bounds(visible_rect.size());
- PaintImage discardable_image1 =
- CreateDiscardablePaintImage(gfx::Size(dimension, dimension));
- PaintImage discardable_image2 =
- CreateDiscardablePaintImage(gfx::Size(dimension, dimension));
- PaintImage discardable_image3 =
- CreateDiscardablePaintImage(gfx::Size(dimension, dimension));
+ sk_sp<SkColorSpace> no_color_space;
+ PaintImage discardable_image1 = CreateDiscardablePaintImage(
+ gfx::Size(dimension, dimension), no_color_space,
+ false /* allocate_encoded_memory */);
+ PaintImage discardable_image2 = CreateDiscardablePaintImage(
+ gfx::Size(dimension, dimension), no_color_space,
+ false /* allocate_encoded_memory */);
+ PaintImage discardable_image3 = CreateDiscardablePaintImage(
+ gfx::Size(dimension, dimension), no_color_space,
+ false /* allocate_encoded_memory */);
PaintFlags flags;
content_layer_client.add_draw_image(discardable_image1, gfx::Point(0, 0),
@@ -574,7 +583,7 @@ TEST_F(DiscardableImageMapTest, GetDiscardableImagesInShader) {
for (int x = 0; x < 4; ++x) {
if ((x + y) & 1) {
discardable_image[y][x] =
- PaintImageBuilder()
+ PaintImageBuilder::WithDefault()
.set_id(y * 4 + x)
.set_paint_image_generator(
CreatePaintImageGenerator(gfx::Size(500, 500)))
@@ -693,6 +702,95 @@ TEST_F(DiscardableImageMapTest, GathersDiscardableImagesFromNestedOps) {
EXPECT_TRUE(discardable_image2 == images[0]->paint_image());
}
+TEST_F(DiscardableImageMapTest, GathersAnimatedImages) {
+ gfx::Rect visible_rect(1000, 1000);
+ FakeContentLayerClient content_layer_client;
+ content_layer_client.set_bounds(visible_rect.size());
+
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))};
+
+ gfx::Size image_size(100, 100);
+ PaintImage static_image = CreateDiscardablePaintImage(image_size);
+ PaintImage animated_loop_none =
+ CreateAnimatedImage(image_size, frames, kAnimationNone);
+ PaintImage animation_loop_infinite =
+ CreateAnimatedImage(image_size, frames, 1u);
+
+ PaintFlags flags;
+ content_layer_client.add_draw_image(static_image, gfx::Point(0, 0), flags);
+ content_layer_client.add_draw_image(animated_loop_none, gfx::Point(100, 100),
+ flags);
+ content_layer_client.add_draw_image(animation_loop_infinite,
+ gfx::Point(200, 200), flags);
+
+ scoped_refptr<DisplayItemList> display_list =
+ content_layer_client.PaintContentsToDisplayList(
+ ContentLayerClient::PAINTING_BEHAVIOR_NORMAL);
+ display_list->GenerateDiscardableImagesMetadata();
+ const auto& animated_images_metadata =
+ display_list->discardable_image_map().animated_images_metadata();
+
+ ASSERT_EQ(animated_images_metadata.size(), 1u);
+ EXPECT_EQ(animated_images_metadata[0].paint_image_id,
+ animation_loop_infinite.stable_id());
+ EXPECT_EQ(animated_images_metadata[0].completion_state,
+ animation_loop_infinite.completion_state());
+ EXPECT_EQ(animated_images_metadata[0].frames,
+ animation_loop_infinite.GetFrameMetadata());
+ EXPECT_EQ(animated_images_metadata[0].repetition_count,
+ animation_loop_infinite.repetition_count());
+
+ std::vector<const DrawImage*> images;
+ display_list->discardable_image_map().GetDiscardableImagesInRect(visible_rect,
+ &images);
+ ASSERT_EQ(images.size(), 3u);
+ EXPECT_EQ(images[0]->paint_image(), static_image);
+ EXPECT_DCHECK_DEATH(images[0]->frame_index());
+ EXPECT_EQ(images[1]->paint_image(), animated_loop_none);
+ EXPECT_DCHECK_DEATH(images[1]->frame_index());
+ EXPECT_EQ(images[2]->paint_image(), animation_loop_infinite);
+ EXPECT_DCHECK_DEATH(images[2]->frame_index());
+}
+
+TEST_F(DiscardableImageMapTest, CapturesImagesInPaintRecordShaders) {
+ // Create the record to use in the shader.
+ auto shader_record = sk_make_sp<PaintOpBuffer>();
+ shader_record->push<ScaleOp>(2.0f, 2.0f);
+ PaintImage paint_image = CreateDiscardablePaintImage(gfx::Size(100, 100));
+ shader_record->push<DrawImageOp>(paint_image, 0.f, 0.f, nullptr);
+
+ gfx::Rect visible_rect(500, 500);
+ scoped_refptr<DisplayItemList> display_list = new DisplayItemList();
+ display_list->StartPaint();
+ display_list->push<ScaleOp>(2.0f, 2.0f);
+ PaintFlags flags;
+ SkRect tile = SkRect::MakeWH(100, 100);
+ flags.setShader(PaintShader::MakePaintRecord(
+ shader_record, tile, SkShader::TileMode::kClamp_TileMode,
+ SkShader::TileMode::kClamp_TileMode, nullptr));
+ display_list->push<DrawRectOp>(SkRect::MakeWH(200, 200), flags);
+ display_list->EndPaintOfUnpaired(visible_rect);
+ display_list->Finalize();
+
+ display_list->GenerateDiscardableImagesMetadata();
+ const auto& image_map = display_list->discardable_image_map();
+
+ // The image rect is set to the rect for the DrawRectOp.
+ std::vector<PositionScaleDrawImage> draw_images =
+ GetDiscardableImagesInRect(image_map, visible_rect);
+ std::vector<gfx::Rect> inset_rects = InsetImageRects(draw_images);
+ ASSERT_EQ(draw_images.size(), 1u);
+ EXPECT_EQ(draw_images[0].image, paint_image);
+ // The position of the image is the position of the DrawRectOp that uses the
+ // shader.
+ EXPECT_EQ(gfx::Rect(400, 400), inset_rects[0]);
+ // The scale of the image includes the scale at which the shader record is
+ // rasterized.
+ EXPECT_EQ(SkSize::Make(4.f, 4.f), draw_images[0].scale);
+}
+
class DiscardableImageMapColorSpaceTest
: public DiscardableImageMapTest,
public testing::WithParamInterface<gfx::ColorSpace> {};
diff --git a/chromium/cc/paint/display_item_list_unittest.cc b/chromium/cc/paint/display_item_list_unittest.cc
index 5fec9fbff88..c0308cd7f69 100644
--- a/chromium/cc/paint/display_item_list_unittest.cc
+++ b/chromium/cc/paint/display_item_list_unittest.cc
@@ -72,7 +72,7 @@ TEST(DisplayItemListTest, SingleUnpairedRange) {
PaintFlags red_paint;
red_paint.setColor(SK_ColorRED);
unsigned char pixels[4 * 100 * 100] = {0};
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
gfx::Point offset(8, 9);
@@ -108,7 +108,7 @@ TEST(DisplayItemListTest, SingleUnpairedRange) {
TEST(DisplayItemListTest, EmptyUnpairedRangeDoesNotAddVisualRect) {
gfx::Rect layer_rect(100, 100);
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
{
list->StartPaint();
@@ -134,7 +134,7 @@ TEST(DisplayItemListTest, ClipPairedRange) {
PaintFlags red_paint;
red_paint.setColor(SK_ColorRED);
unsigned char pixels[4 * 100 * 100] = {0};
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
gfx::Point first_offset(8, 9);
gfx::Rect first_recording_rect(first_offset, layer_rect.size());
@@ -208,7 +208,7 @@ TEST(DisplayItemListTest, TransformPairedRange) {
PaintFlags red_paint;
red_paint.setColor(SK_ColorRED);
unsigned char pixels[4 * 100 * 100] = {0};
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
gfx::Point first_offset(8, 9);
gfx::Rect first_recording_rect(first_offset, layer_rect.size());
@@ -277,7 +277,7 @@ TEST(DisplayItemListTest, FilterPairedRange) {
gfx::Rect layer_rect(100, 100);
FilterOperations filters;
unsigned char pixels[4 * 100 * 100] = {0};
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
sk_sp<SkSurface> source_surface = SkSurface::MakeRasterN32Premul(50, 50);
SkCanvas* source_canvas = source_surface->getCanvas();
@@ -359,7 +359,7 @@ TEST(DisplayItemListTest, BytesUsed) {
const int kNumPaintOps = 1000;
size_t memory_usage;
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
gfx::Rect layer_rect(100, 100);
PaintFlags blue_flags;
@@ -378,7 +378,7 @@ TEST(DisplayItemListTest, BytesUsed) {
}
TEST(DisplayItemListTest, AsValueWithNoOps) {
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
list->Finalize();
// Pass |true| to ask for PaintOps even though there are none.
@@ -439,7 +439,7 @@ TEST(DisplayItemListTest, AsValueWithNoOps) {
TEST(DisplayItemListTest, AsValueWithOps) {
gfx::Rect layer_rect = gfx::Rect(1, 2, 8, 9);
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
gfx::Transform transform;
transform.Translate(6.f, 7.f);
@@ -540,12 +540,12 @@ TEST(DisplayItemListTest, AsValueWithOps) {
}
TEST(DisplayItemListTest, SizeEmpty) {
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
EXPECT_EQ(0u, list->op_count());
}
TEST(DisplayItemListTest, SizeOne) {
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
gfx::Rect drawing_bounds(5, 6, 1, 1);
{
list->StartPaint();
@@ -556,7 +556,7 @@ TEST(DisplayItemListTest, SizeOne) {
}
TEST(DisplayItemListTest, SizeMultiple) {
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
gfx::Rect clip_bounds(5, 6, 7, 8);
{
list->StartPaint();
@@ -574,7 +574,7 @@ TEST(DisplayItemListTest, SizeMultiple) {
}
TEST(DisplayItemListTest, AppendVisualRectSimple) {
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
// One drawing: D.
@@ -590,7 +590,7 @@ TEST(DisplayItemListTest, AppendVisualRectSimple) {
}
TEST(DisplayItemListTest, AppendVisualRectEmptyBlock) {
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
// One block: B1, E1.
@@ -615,7 +615,7 @@ TEST(DisplayItemListTest, AppendVisualRectEmptyBlock) {
}
TEST(DisplayItemListTest, AppendVisualRectEmptyBlockContainingEmptyBlock) {
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
// Two nested blocks: B1, B2, E2, E1.
@@ -654,7 +654,7 @@ TEST(DisplayItemListTest, AppendVisualRectEmptyBlockContainingEmptyBlock) {
}
TEST(DisplayItemListTest, AppendVisualRectBlockContainingDrawing) {
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
// One block with one drawing: B1, Da, E1.
@@ -688,7 +688,7 @@ TEST(DisplayItemListTest, AppendVisualRectBlockContainingDrawing) {
}
TEST(DisplayItemListTest, AppendVisualRectBlockContainingEscapedDrawing) {
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
// One block with one drawing: B1, Da (escapes), E1.
@@ -723,7 +723,7 @@ TEST(DisplayItemListTest, AppendVisualRectBlockContainingEscapedDrawing) {
TEST(DisplayItemListTest,
AppendVisualRectDrawingFollowedByBlockContainingEscapedDrawing) {
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
// One drawing followed by one block with one drawing: Da, B1, Db (escapes),
// E1.
@@ -766,7 +766,7 @@ TEST(DisplayItemListTest,
}
TEST(DisplayItemListTest, AppendVisualRectTwoBlocksTwoDrawings) {
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
// Multiple nested blocks with drawings amidst: B1, Da, B2, Db, E2, E1.
@@ -828,7 +828,7 @@ TEST(DisplayItemListTest, AppendVisualRectTwoBlocksTwoDrawings) {
TEST(DisplayItemListTest,
AppendVisualRectTwoBlocksTwoDrawingsInnerDrawingEscaped) {
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
// Multiple nested blocks with drawings amidst: B1, Da, B2, Db (escapes), E2,
// E1.
@@ -891,7 +891,7 @@ TEST(DisplayItemListTest,
TEST(DisplayItemListTest,
AppendVisualRectTwoBlocksTwoDrawingsOuterDrawingEscaped) {
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
// Multiple nested blocks with drawings amidst: B1, Da (escapes), B2, Db, E2,
// E1.
@@ -954,7 +954,7 @@ TEST(DisplayItemListTest,
TEST(DisplayItemListTest,
AppendVisualRectTwoBlocksTwoDrawingsBothDrawingsEscaped) {
- auto list = make_scoped_refptr(new DisplayItemList);
+ auto list = base::MakeRefCounted<DisplayItemList>();
// Multiple nested blocks with drawings amidst:
// B1, Da (escapes to the right), B2, Db (escapes to the left), E2, E1.
diff --git a/chromium/cc/paint/draw_image.cc b/chromium/cc/paint/draw_image.cc
index 7b7314b3cb1..a1a78af3b6c 100644
--- a/chromium/cc/paint/draw_image.cc
+++ b/chromium/cc/paint/draw_image.cc
@@ -32,16 +32,19 @@ DrawImage::DrawImage(PaintImage image,
const SkIRect& src_rect,
SkFilterQuality filter_quality,
const SkMatrix& matrix,
+ base::Optional<size_t> frame_index,
const base::Optional<gfx::ColorSpace>& color_space)
: paint_image_(std::move(image)),
src_rect_(src_rect),
filter_quality_(filter_quality),
+ frame_index_(frame_index),
target_color_space_(color_space) {
matrix_is_decomposable_ = ExtractScale(matrix, &scale_);
}
DrawImage::DrawImage(const DrawImage& other,
float scale_adjustment,
+ size_t frame_index,
const gfx::ColorSpace& color_space)
: paint_image_(other.paint_image_),
src_rect_(other.src_rect_),
@@ -49,6 +52,7 @@ DrawImage::DrawImage(const DrawImage& other,
scale_(SkSize::Make(other.scale_.width() * scale_adjustment,
other.scale_.height() * scale_adjustment)),
matrix_is_decomposable_(other.matrix_is_decomposable_),
+ frame_index_(frame_index),
target_color_space_(color_space) {}
DrawImage::DrawImage(const DrawImage& other) = default;
diff --git a/chromium/cc/paint/draw_image.h b/chromium/cc/paint/draw_image.h
index 58c46d98b58..81c45d1cfd2 100644
--- a/chromium/cc/paint/draw_image.h
+++ b/chromium/cc/paint/draw_image.h
@@ -25,11 +25,13 @@ class CC_PAINT_EXPORT DrawImage {
const SkIRect& src_rect,
SkFilterQuality filter_quality,
const SkMatrix& matrix,
+ base::Optional<size_t> frame_index = base::nullopt,
const base::Optional<gfx::ColorSpace>& color_space = base::nullopt);
// Constructs a DrawImage from |other| by adjusting its scale and setting a
// new color_space.
DrawImage(const DrawImage& other,
float scale_adjustment,
+ size_t frame_index,
const gfx::ColorSpace& color_space);
DrawImage(const DrawImage& other);
DrawImage(DrawImage&& other);
@@ -50,7 +52,11 @@ class CC_PAINT_EXPORT DrawImage {
return *target_color_space_;
}
PaintImage::FrameKey frame_key() const {
- return paint_image_.GetKeyForFrame(paint_image_.frame_index());
+ return paint_image_.GetKeyForFrame(frame_index());
+ }
+ size_t frame_index() const {
+ DCHECK(frame_index_.has_value());
+ return frame_index_.value();
}
private:
@@ -59,6 +65,7 @@ class CC_PAINT_EXPORT DrawImage {
SkFilterQuality filter_quality_;
SkSize scale_;
bool matrix_is_decomposable_;
+ base::Optional<size_t> frame_index_;
base::Optional<gfx::ColorSpace> target_color_space_;
};
diff --git a/chromium/cc/paint/frame_metadata.h b/chromium/cc/paint/frame_metadata.h
index d5efe8ec92c..d63bb0d4363 100644
--- a/chromium/cc/paint/frame_metadata.h
+++ b/chromium/cc/paint/frame_metadata.h
@@ -16,6 +16,10 @@ struct CC_PAINT_EXPORT FrameMetadata {
FrameMetadata(bool complete, base::TimeDelta duration)
: complete(complete), duration(duration) {}
+ bool operator==(const FrameMetadata& other) const {
+ return complete == other.complete && duration == other.duration;
+ }
+
// True if the decoder has all encoded content for this frame.
bool complete = true;
diff --git a/chromium/cc/paint/image_animation_count.h b/chromium/cc/paint/image_animation_count.h
new file mode 100644
index 00000000000..be39f0a6f44
--- /dev/null
+++ b/chromium/cc/paint/image_animation_count.h
@@ -0,0 +1,30 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_PAINT_IMAGE_ANIMATION_COUNT_H_
+#define CC_PAINT_IMAGE_ANIMATION_COUNT_H_
+
+namespace cc {
+
+// GIF and WebP support animation. The explanation below is in terms of GIF,
+// but the same constants are used for WebP, too.
+// GIFs have an optional 16-bit unsigned loop count that describes how an
+// animated GIF should be cycled. If the loop count is absent, the animation
+// cycles once; if it is 0, the animation cycles infinitely; otherwise the
+// animation plays n + 1 cycles (where n is the specified loop count). If the
+// GIF decoder defaults to kAnimationLoopOnce in the absence of any loop count
+// and translates an explicit "0" loop count to kAnimationLoopInfinite, then we
+// get a couple of nice side effects:
+// * By making kAnimationLoopOnce be 0, we allow the animation cycling code in
+// BitmapImage.cpp to avoid special-casing it, and simply treat all
+// non-negative loop counts identically.
+// * By making the other two constants negative, we avoid conflicts with any
+// real loop count values.
+const int kAnimationLoopOnce = 0;
+const int kAnimationLoopInfinite = -1;
+const int kAnimationNone = -2;
+
+} // namespace cc
+
+#endif // CC_PAINT_IMAGE_ANIMATION_COUNT_H_
diff --git a/chromium/cc/paint/image_provider.h b/chromium/cc/paint/image_provider.h
index f5230e6e7e4..3c2fc9b391b 100644
--- a/chromium/cc/paint/image_provider.h
+++ b/chromium/cc/paint/image_provider.h
@@ -7,8 +7,11 @@
#include "base/callback.h"
#include "cc/paint/decoded_draw_image.h"
+#include "cc/paint/draw_image.h"
#include "cc/paint/paint_export.h"
+#include <vector>
+
namespace cc {
class PaintImage;
@@ -43,13 +46,13 @@ class CC_PAINT_EXPORT ImageProvider {
virtual ~ImageProvider() {}
+ virtual void BeginRaster() {}
+ virtual void EndRaster() {}
+
// Returns the DecodedDrawImage to use for this PaintImage. If no image is
// provided, the draw for this image will be skipped during raster.
virtual ScopedDecodedDrawImage GetDecodedDrawImage(
- const PaintImage& paint_image,
- const SkRect& src_rect,
- SkFilterQuality filter_quality,
- const SkMatrix& matrix) = 0;
+ const DrawImage& draw_image) = 0;
};
} // namespace cc
diff --git a/chromium/cc/paint/paint_canvas.h b/chromium/cc/paint/paint_canvas.h
index dd389770670..7a7c75d7b7b 100644
--- a/chromium/cc/paint/paint_canvas.h
+++ b/chromium/cc/paint/paint_canvas.h
@@ -86,8 +86,6 @@ class CC_PAINT_EXPORT PaintCanvas {
clipPath(path, SkClipOp::kIntersect, do_anti_alias);
}
- virtual bool quickReject(const SkRect& rect) const = 0;
- virtual bool quickReject(const SkPath& path) const = 0;
virtual SkRect getLocalClipBounds() const = 0;
virtual bool getLocalClipBounds(SkRect* bounds) const = 0;
virtual SkIRect getDeviceClipBounds() const = 0;
diff --git a/chromium/cc/paint/paint_image.cc b/chromium/cc/paint/paint_image.cc
index ca109ec220b..a0d7a9cc68a 100644
--- a/chromium/cc/paint/paint_image.cc
+++ b/chromium/cc/paint/paint_image.cc
@@ -18,6 +18,9 @@ base::AtomicSequenceNumber s_next_id_;
base::AtomicSequenceNumber s_next_content_id_;
} // namespace
+const int PaintImage::kNonLazyStableId = -1;
+const size_t PaintImage::kDefaultFrameIndex = 0u;
+
PaintImage::PaintImage() = default;
PaintImage::PaintImage(const PaintImage& other) = default;
PaintImage::PaintImage(PaintImage&& other) = default;
@@ -35,8 +38,7 @@ bool PaintImage::operator==(const PaintImage& other) const {
completion_state_ == other.completion_state_ &&
subset_rect_ == other.subset_rect_ &&
frame_index_ == other.frame_index_ &&
- is_multipart_ == other.is_multipart_ &&
- sk_image_id_ == other.sk_image_id_;
+ is_multipart_ == other.is_multipart_;
}
PaintImage::Id PaintImage::GetNextId() {
@@ -48,26 +50,6 @@ PaintImage::ContentId PaintImage::GetNextContentId() {
}
const sk_sp<SkImage>& PaintImage::GetSkImage() const {
- if (cached_sk_image_)
- return cached_sk_image_;
-
- if (sk_image_) {
- cached_sk_image_ = sk_image_;
- } else if (paint_record_) {
- cached_sk_image_ = SkImage::MakeFromPicture(
- ToSkPicture(paint_record_, gfx::RectToSkRect(paint_record_rect_)),
- SkISize::Make(paint_record_rect_.width(), paint_record_rect_.height()),
- nullptr, nullptr, SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB());
- } else if (paint_image_generator_) {
- cached_sk_image_ =
- SkImage::MakeFromGenerator(base::MakeUnique<SkiaPaintImageGenerator>(
- paint_image_generator_, frame_index_, sk_image_id_));
- }
-
- if (!subset_rect_.IsEmpty() && cached_sk_image_) {
- cached_sk_image_ =
- cached_sk_image_->makeSubset(gfx::RectToSkIRect(subset_rect_));
- }
return cached_sk_image_;
}
@@ -87,20 +69,45 @@ PaintImage PaintImage::MakeSubset(const gfx::Rect& subset) const {
// Store the subset from the original image.
result.subset_rect_.Offset(subset_rect_.x(), subset_rect_.y());
- // Creating the |cached_sk_image_| is an optimization to allow re-use of the
- // original decode for image subsets in skia, for cases that rely on skia's
- // image decode cache.
- // TODO(khushalsagar): Remove this when we no longer have such cases. See
- // crbug.com/753639.
+ // Creating the |cached_sk_image_| using the SkImage from the original
+ // PaintImage is an optimization to allow re-use of the original decode for
+ // image subsets in skia, for cases that rely on skia's image decode cache.
result.cached_sk_image_ =
GetSkImage()->makeSubset(gfx::RectToSkIRect(subset));
return result;
}
+void PaintImage::CreateSkImage() {
+ DCHECK(!cached_sk_image_);
+
+ if (sk_image_) {
+ cached_sk_image_ = sk_image_;
+ } else if (paint_record_) {
+ cached_sk_image_ = SkImage::MakeFromPicture(
+ ToSkPicture(paint_record_, gfx::RectToSkRect(paint_record_rect_)),
+ SkISize::Make(paint_record_rect_.width(), paint_record_rect_.height()),
+ nullptr, nullptr, SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB());
+ } else if (paint_image_generator_) {
+ cached_sk_image_ =
+ SkImage::MakeFromGenerator(base::MakeUnique<SkiaPaintImageGenerator>(
+ paint_image_generator_, frame_index_));
+ }
+
+ if (!subset_rect_.IsEmpty() && cached_sk_image_) {
+ cached_sk_image_ =
+ cached_sk_image_->makeSubset(gfx::RectToSkIRect(subset_rect_));
+ }
+}
+
SkISize PaintImage::GetSupportedDecodeSize(
const SkISize& requested_size) const {
- // TODO(vmpstr): For now, we ignore the requested size and just return the
- // available image size.
+ // TODO(vmpstr): If this image is using subset_rect, then we don't support
+ // decoding to any scale other than the original. See the comment in Decode()
+ // explaining this in more detail.
+ // TODO(vmpstr): For now, always decode to the original size. This can be
+ // enabled with the following code, and should be done as a follow-up.
+ // if (paint_image_generator_ && subset_rect_.IsEmpty())
+ // return paint_image_generator_->GetSupportedDecodeSize(requested_size);
return SkISize::Make(width(), height());
}
@@ -113,8 +120,71 @@ SkImageInfo PaintImage::CreateDecodeImageInfo(const SkISize& size,
bool PaintImage::Decode(void* memory,
SkImageInfo* info,
- sk_sp<SkColorSpace> color_space) const {
- auto image = GetSkImage();
+ sk_sp<SkColorSpace> color_space,
+ size_t frame_index) const {
+ // We only support decode to supported decode size.
+ DCHECK(info->dimensions() == GetSupportedDecodeSize(info->dimensions()));
+
+ // TODO(vmpstr): If we're using a subset_rect_ then the info specifies the
+ // requested size relative to the subset. However, the generator isn't aware
+ // of this subsetting and would need a size that is relative to the original
+ // image size. We could still implement this case, but we need to convert the
+ // requested size into the space of the original image. For now, fallback to
+ // DecodeFromSkImage().
+ if (paint_image_generator_ && subset_rect_.IsEmpty())
+ return DecodeFromGenerator(memory, info, std::move(color_space),
+ frame_index);
+ return DecodeFromSkImage(memory, info, std::move(color_space), frame_index);
+}
+
+bool PaintImage::DecodeFromGenerator(void* memory,
+ SkImageInfo* info,
+ sk_sp<SkColorSpace> color_space,
+ size_t frame_index) const {
+ DCHECK(subset_rect_.IsEmpty());
+
+ // First convert the info to have the requested color space, since the decoder
+ // will convert this for us.
+ *info = info->makeColorSpace(std::move(color_space));
+ if (info->colorType() != kN32_SkColorType) {
+ // Since the decoders only support N32 color types, make one of those and
+ // decode into temporary memory. Then read the bitmap which will convert it
+ // to the target color type.
+ SkImageInfo n32info = info->makeColorType(kN32_SkColorType);
+ std::unique_ptr<char[]> n32memory(
+ new char[n32info.minRowBytes() * n32info.height()]);
+
+ bool result = paint_image_generator_->GetPixels(n32info, n32memory.get(),
+ n32info.minRowBytes(),
+ frame_index, unique_id());
+ if (!result)
+ return false;
+
+ // The following block will use Skia to do the color type conversion from
+ // N32 to the destination color type. Since color space conversion was
+ // already done in GetPixels() above, remove the color space information
+ // first in case Skia tries to use it for something. In practice, n32info
+ // and *info color spaces match, so it should work without removing the
+ // color spaces, but better be safe.
+ SkImageInfo n32info_no_colorspace = n32info.makeColorSpace(nullptr);
+ SkImageInfo info_no_colorspace = info->makeColorSpace(nullptr);
+
+ SkBitmap bitmap;
+ bitmap.installPixels(n32info_no_colorspace, n32memory.get(),
+ n32info.minRowBytes());
+ return bitmap.readPixels(info_no_colorspace, memory, info->minRowBytes(), 0,
+ 0);
+ }
+
+ return paint_image_generator_->GetPixels(*info, memory, info->minRowBytes(),
+ frame_index, unique_id());
+}
+
+bool PaintImage::DecodeFromSkImage(void* memory,
+ SkImageInfo* info,
+ sk_sp<SkColorSpace> color_space,
+ size_t frame_index) const {
+ auto image = GetSkImageForFrame(frame_index);
DCHECK(image);
if (color_space) {
image =
@@ -126,10 +196,15 @@ bool PaintImage::Decode(void* memory,
// given color space, since it can produce incorrect results.
bool result = image->readPixels(*info, memory, info->minRowBytes(), 0, 0,
SkImage::kDisallow_CachingHint);
- *info = info->makeColorSpace(color_space);
+ *info = info->makeColorSpace(std::move(color_space));
return result;
}
+bool PaintImage::ShouldAnimate() const {
+ return animation_type_ == AnimationType::ANIMATED &&
+ repetition_count_ != kAnimationNone && FrameCount() > 1;
+}
+
PaintImage::FrameKey PaintImage::GetKeyForFrame(size_t frame_index) const {
DCHECK_LT(frame_index, FrameCount());
DCHECK(paint_image_generator_ || paint_record_);
@@ -143,7 +218,7 @@ PaintImage::FrameKey PaintImage::GetKeyForFrame(size_t frame_index) const {
content_id = paint_record_content_id_;
DCHECK_NE(content_id, kInvalidContentId);
- return FrameKey(id_, content_id, frame_index, subset_rect_);
+ return FrameKey(content_id, frame_index, subset_rect_);
}
const std::vector<FrameMetadata>& PaintImage::GetFrameMetadata() const {
@@ -161,6 +236,19 @@ size_t PaintImage::FrameCount() const {
: 1u;
}
+sk_sp<SkImage> PaintImage::GetSkImageForFrame(size_t index) const {
+ DCHECK_LT(index, FrameCount());
+
+ if (index == frame_index_)
+ return GetSkImage();
+
+ sk_sp<SkImage> image = SkImage::MakeFromGenerator(
+ base::MakeUnique<SkiaPaintImageGenerator>(paint_image_generator_, index));
+ if (!subset_rect_.IsEmpty())
+ image = image->makeSubset(gfx::RectToSkIRect(subset_rect_));
+ return image;
+}
+
std::string PaintImage::ToString() const {
std::ostringstream str;
str << "sk_image_: " << sk_image_ << " paint_record_: " << paint_record_
@@ -171,22 +259,18 @@ std::string PaintImage::ToString() const {
<< " completion_state_: " << static_cast<int>(completion_state_)
<< " subset_rect_: " << subset_rect_.ToString()
<< " frame_index_: " << frame_index_
- << " is_multipart_: " << is_multipart_
- << " sk_image_id_: " << sk_image_id_;
+ << " is_multipart_: " << is_multipart_;
return str.str();
}
-PaintImage::FrameKey::FrameKey(Id paint_image_id,
- ContentId content_id,
+PaintImage::FrameKey::FrameKey(ContentId content_id,
size_t frame_index,
gfx::Rect subset_rect)
- : paint_image_id_(paint_image_id),
- content_id_(content_id),
+ : content_id_(content_id),
frame_index_(frame_index),
subset_rect_(subset_rect) {
- size_t original_hash = base::HashInts(
- static_cast<uint64_t>(base::HashInts(paint_image_id_, content_id_)),
- static_cast<uint64_t>(frame_index_));
+ size_t original_hash = base::HashInts(static_cast<uint64_t>(content_id_),
+ static_cast<uint64_t>(frame_index_));
if (subset_rect_.IsEmpty()) {
hash_ = original_hash;
} else {
@@ -200,8 +284,7 @@ PaintImage::FrameKey::FrameKey(Id paint_image_id,
}
bool PaintImage::FrameKey::operator==(const FrameKey& other) const {
- return paint_image_id_ == other.paint_image_id_ &&
- content_id_ == other.content_id_ &&
+ return content_id_ == other.content_id_ &&
frame_index_ == other.frame_index_ &&
subset_rect_ == other.subset_rect_;
}
@@ -212,8 +295,7 @@ bool PaintImage::FrameKey::operator!=(const FrameKey& other) const {
std::string PaintImage::FrameKey::ToString() const {
std::ostringstream str;
- str << "paint_image_id: " << paint_image_id_ << ","
- << "content_id: " << content_id_ << ","
+ str << "content_id: " << content_id_ << ","
<< "frame_index: " << frame_index_ << ","
<< "subset_rect: " << subset_rect_.ToString();
return str.str();
diff --git a/chromium/cc/paint/paint_image.h b/chromium/cc/paint/paint_image.h
index 8586e680317..1174e706347 100644
--- a/chromium/cc/paint/paint_image.h
+++ b/chromium/cc/paint/paint_image.h
@@ -10,6 +10,7 @@
#include "base/gtest_prod_util.h"
#include "base/logging.h"
#include "cc/paint/frame_metadata.h"
+#include "cc/paint/image_animation_count.h"
#include "cc/paint/paint_export.h"
#include "cc/paint/skia_paint_image_generator.h"
#include "third_party/skia/include/core/SkImage.h"
@@ -27,6 +28,7 @@ using PaintRecord = PaintOpBuffer;
class CC_PAINT_EXPORT PaintImage {
public:
using Id = int;
+ using AnimationSequenceId = uint32_t;
// A ContentId is used to identify the content for which images which can be
// lazily generated (generator/record backed images). As opposed to Id, which
@@ -38,26 +40,23 @@ class CC_PAINT_EXPORT PaintImage {
// An id that can be used for all non-lazy images. Note that if an image is
// not lazy, it does not mean that this id must be used; one can still use
// GetNextId to generate a stable id for such images.
- static const Id kNonLazyStableId = -1;
+ static const Id kNonLazyStableId;
// The default frame index to use if no index is provided. For multi-frame
// images, this would imply the first frame of the animation.
- static const size_t kDefaultFrameIndex = 0;
+ static const size_t kDefaultFrameIndex;
class CC_PAINT_EXPORT FrameKey {
public:
- FrameKey(Id paint_image_id,
- ContentId content_id,
- size_t frame_index,
- gfx::Rect subset_rect);
+ FrameKey(ContentId content_id, size_t frame_index, gfx::Rect subset_rect);
bool operator==(const FrameKey& other) const;
bool operator!=(const FrameKey& other) const;
uint64_t hash() const { return hash_; }
std::string ToString() const;
+ size_t frame_index() const { return frame_index_; }
private:
- Id paint_image_id_;
ContentId content_id_;
size_t frame_index_;
// TODO(khushalsagar): Remove this when callers take care of subsetting.
@@ -74,6 +73,7 @@ class CC_PAINT_EXPORT PaintImage {
enum class AnimationType { ANIMATED, VIDEO, STATIC };
enum class CompletionState { DONE, PARTIALLY_DONE };
+ enum class DecodingMode { kUnspecified, kSync, kAsync };
static Id GetNextId();
static ContentId GetNextContentId();
@@ -86,10 +86,6 @@ class CC_PAINT_EXPORT PaintImage {
PaintImage& operator=(const PaintImage& other);
PaintImage& operator=(PaintImage&& other);
- // Makes a new PaintImage representing a subset of the original image. The
- // subset must be non-empty and lie within the image bounds.
- PaintImage MakeSubset(const gfx::Rect& subset) const;
-
bool operator==(const PaintImage& other) const;
// Returns the smallest size that is at least as big as the requested_size
@@ -115,13 +111,21 @@ class CC_PAINT_EXPORT PaintImage {
// is texture backed.
bool Decode(void* memory,
SkImageInfo* info,
- sk_sp<SkColorSpace> color_space) const;
+ sk_sp<SkColorSpace> color_space,
+ size_t frame_index) const;
Id stable_id() const { return id_; }
const sk_sp<SkImage>& GetSkImage() const;
AnimationType animation_type() const { return animation_type_; }
CompletionState completion_state() const { return completion_state_; }
bool is_multipart() const { return is_multipart_; }
+ int repetition_count() const { return repetition_count_; }
+ bool ShouldAnimate() const;
+ size_t frame_index() const { return frame_index_; }
+ AnimationSequenceId reset_animation_sequence_id() const {
+ return reset_animation_sequence_id_;
+ }
+ DecodingMode decoding_mode() const { return decoding_mode_; }
// TODO(vmpstr): Don't get the SkImage here if you don't need to.
uint32_t unique_id() const { return GetSkImage()->uniqueID(); }
@@ -130,7 +134,6 @@ class CC_PAINT_EXPORT PaintImage {
int width() const { return GetSkImage()->width(); }
int height() const { return GetSkImage()->height(); }
SkColorSpace* color_space() const { return GetSkImage()->colorSpace(); }
- size_t frame_index() const { return frame_index_; }
// Returns a unique id for the pixel data for the frame at |frame_index|. Used
// only for lazy-generated images.
@@ -143,6 +146,9 @@ class CC_PAINT_EXPORT PaintImage {
// Returns the total number of frames known to exist in this image.
size_t FrameCount() const;
+ // Returns an SkImage for the frame at |index|.
+ sk_sp<SkImage> GetSkImageForFrame(size_t index) const;
+
std::string ToString() const;
private:
@@ -150,6 +156,17 @@ class CC_PAINT_EXPORT PaintImage {
friend class PaintImageBuilder;
FRIEND_TEST_ALL_PREFIXES(PaintImageTest, Subsetting);
+ bool DecodeFromGenerator(void* memory,
+ SkImageInfo* info,
+ sk_sp<SkColorSpace> color_space,
+ size_t frame_index) const;
+ bool DecodeFromSkImage(void* memory,
+ SkImageInfo* info,
+ sk_sp<SkColorSpace> color_space,
+ size_t frame_index) const;
+ void CreateSkImage();
+ PaintImage MakeSubset(const gfx::Rect& subset) const;
+
sk_sp<SkImage> sk_image_;
sk_sp<PaintRecord> paint_record_;
@@ -161,6 +178,7 @@ class CC_PAINT_EXPORT PaintImage {
Id id_ = 0;
AnimationType animation_type_ = AnimationType::STATIC;
CompletionState completion_state_ = CompletionState::DONE;
+ int repetition_count_ = kAnimationNone;
// If non-empty, holds the subset of this image relative to the original image
// at the origin.
@@ -172,11 +190,21 @@ class CC_PAINT_EXPORT PaintImage {
// Whether the data fetched for this image is a part of a multpart response.
bool is_multipart_ = false;
- // |sk_image_id_| is the id used when constructing an SkImage representation
- // for a generator backed image.
- // TODO(khushalsagar): Remove the use of this uniqueID. See crbug.com/753639.
- uint32_t sk_image_id_ = SkiaPaintImageGenerator::kNeedNewImageUniqueID;
- mutable sk_sp<SkImage> cached_sk_image_;
+ // An incrementing sequence number maintained by the painter to indicate if
+ // this animation should be reset in the compositor. Incrementing this number
+ // will reset this animation in the compositor for the first frame which has a
+ // recording with a PaintImage storing the updated sequence id.
+ AnimationSequenceId reset_animation_sequence_id_ = 0u;
+
+ DecodingMode decoding_mode_ = DecodingMode::kSync;
+
+ // The |cached_sk_image_| can be derived/created from other inputs present in
+ // the PaintImage but we always construct it at creation time for 2 reasons:
+ // 1) This ensures that the underlying SkImage is shared across PaintImage
+ // copies, which is necessary to allow reuse of decodes from this image in
+ // skia's cache.
+ // 2) Ensures that accesses to it are thread-safe.
+ sk_sp<SkImage> cached_sk_image_;
};
} // namespace cc
diff --git a/chromium/cc/paint/paint_image_builder.cc b/chromium/cc/paint/paint_image_builder.cc
index b6fc8eefa82..d6741c1cf99 100644
--- a/chromium/cc/paint/paint_image_builder.cc
+++ b/chromium/cc/paint/paint_image_builder.cc
@@ -6,21 +6,39 @@
namespace cc {
+// static
+PaintImageBuilder PaintImageBuilder::WithDefault() {
+ return PaintImageBuilder();
+}
+
+// static
+PaintImageBuilder PaintImageBuilder::WithCopy(PaintImage paint_image) {
+ return PaintImageBuilder(std::move(paint_image), false);
+}
+
+// static
+PaintImageBuilder PaintImageBuilder::WithProperties(PaintImage paint_image) {
+ return PaintImageBuilder(std::move(paint_image), true);
+}
+
PaintImageBuilder::PaintImageBuilder() = default;
-PaintImageBuilder::PaintImageBuilder(PaintImage image)
+PaintImageBuilder::PaintImageBuilder(PaintImage image, bool clear_contents)
: paint_image_(std::move(image)) {
#if DCHECK_IS_ON()
id_set_ = true;
#endif
- paint_image_.cached_sk_image_ = nullptr;
- paint_image_.sk_image_ = nullptr;
- paint_image_.paint_record_ = nullptr;
- paint_image_.paint_record_rect_ = gfx::Rect();
- paint_image_.paint_image_generator_ = nullptr;
+ if (clear_contents) {
+ paint_image_.sk_image_ = nullptr;
+ paint_image_.paint_record_ = nullptr;
+ paint_image_.paint_record_rect_ = gfx::Rect();
+ paint_image_.paint_image_generator_ = nullptr;
+ paint_image_.cached_sk_image_ = nullptr;
+ }
}
+PaintImageBuilder::PaintImageBuilder(PaintImageBuilder&& other) = default;
PaintImageBuilder::~PaintImageBuilder() = default;
-PaintImage PaintImageBuilder::TakePaintImage() const {
+PaintImage PaintImageBuilder::TakePaintImage() {
#if DCHECK_IS_ON()
DCHECK(id_set_);
if (paint_image_.sk_image_) {
@@ -28,7 +46,12 @@ PaintImage PaintImageBuilder::TakePaintImage() const {
DCHECK(!paint_image_.paint_image_generator_);
DCHECK(!paint_image_.sk_image_->isLazyGenerated());
// TODO(khushalsagar): Assert that we don't have an animated image type
- // here.
+ // here. The only case where this is possible is DragImage. There are 2 use
+ // cases going through that path, re-orienting the image and for use by the
+ // DragController. The first should never be triggered for an animated
+ // image (orientation changes can only be specified by JPEGs, none of the
+ // animation image types use it). For the latter the image is required to be
+ // decoded and used in blink, and should only need the default frame.
} else if (paint_image_.paint_record_) {
DCHECK(!paint_image_.sk_image_);
DCHECK(!paint_image_.paint_image_generator_);
@@ -38,8 +61,19 @@ PaintImage PaintImageBuilder::TakePaintImage() const {
DCHECK(!paint_image_.sk_image_);
DCHECK(!paint_image_.paint_record_);
}
+
+ if (paint_image_.ShouldAnimate()) {
+ DCHECK(paint_image_.paint_image_generator_)
+ << "Animated images must provide a generator";
+ for (const auto& frame : paint_image_.GetFrameMetadata())
+ DCHECK_GT(frame.duration, base::TimeDelta());
+ }
#endif
+ // We may already have a cached_sk_image_ if this builder was created with a
+ // copy.
+ if (!paint_image_.cached_sk_image_)
+ paint_image_.CreateSkImage();
return std::move(paint_image_);
}
diff --git a/chromium/cc/paint/paint_image_builder.h b/chromium/cc/paint/paint_image_builder.h
index 6585b798fc0..9e1e2398a12 100644
--- a/chromium/cc/paint/paint_image_builder.h
+++ b/chromium/cc/paint/paint_image_builder.h
@@ -18,72 +18,96 @@ namespace cc {
// Class used to construct a paint image.
class CC_PAINT_EXPORT PaintImageBuilder {
public:
- PaintImageBuilder();
+ static PaintImageBuilder WithDefault();
+
+ // Starts with the given images. Everything, including the "contents" of the
+ // image are copied.
+ static PaintImageBuilder WithCopy(PaintImage image);
+
// Starts with the given image's flags. Note that this does _not_ keep the
// "contents" of the image. That is, it clears the cached SkImage, the set
// SkImage, the set PaintRecord, and any other content type variables.
- explicit PaintImageBuilder(PaintImage starting_image);
+ static PaintImageBuilder WithProperties(PaintImage image);
+
+ PaintImageBuilder(PaintImageBuilder&& other);
~PaintImageBuilder();
- PaintImageBuilder& set_id(PaintImage::Id id) {
+ PaintImageBuilder&& set_id(PaintImage::Id id) {
paint_image_.id_ = id;
#if DCHECK_IS_ON()
id_set_ = true;
#endif
- return *this;
+ return std::move(*this);
}
- PaintImageBuilder& set_image(sk_sp<SkImage> sk_image) {
+ PaintImageBuilder&& set_image(sk_sp<SkImage> sk_image) {
paint_image_.sk_image_ = std::move(sk_image);
- return *this;
+ return std::move(*this);
}
- PaintImageBuilder& set_paint_record(sk_sp<PaintRecord> paint_record,
- const gfx::Rect& rect,
- PaintImage::ContentId content_id) {
+ PaintImageBuilder&& set_paint_record(sk_sp<PaintRecord> paint_record,
+ const gfx::Rect& rect,
+ PaintImage::ContentId content_id) {
DCHECK_NE(content_id, PaintImage::kInvalidContentId);
paint_image_.paint_record_ = std::move(paint_record);
paint_image_.paint_record_rect_ = rect;
paint_image_.paint_record_content_id_ = content_id;
- return *this;
+ return std::move(*this);
}
- PaintImageBuilder& set_paint_image_generator(
+ PaintImageBuilder&& set_paint_image_generator(
sk_sp<PaintImageGenerator> generator) {
paint_image_.paint_image_generator_ = std::move(generator);
- return *this;
+ return std::move(*this);
}
- PaintImageBuilder& set_animation_type(PaintImage::AnimationType type) {
+ PaintImageBuilder&& set_animation_type(PaintImage::AnimationType type) {
paint_image_.animation_type_ = type;
- return *this;
+ return std::move(*this);
}
- PaintImageBuilder& set_completion_state(PaintImage::CompletionState state) {
+ PaintImageBuilder&& set_completion_state(PaintImage::CompletionState state) {
paint_image_.completion_state_ = state;
- return *this;
+ return std::move(*this);
}
- PaintImageBuilder& set_is_multipart(bool is_multipart) {
+ PaintImageBuilder&& set_is_multipart(bool is_multipart) {
paint_image_.is_multipart_ = is_multipart;
- return *this;
+ return std::move(*this);
}
- PaintImageBuilder& set_frame_index(size_t frame_index) {
+ PaintImageBuilder&& set_frame_index(size_t frame_index) {
paint_image_.frame_index_ = frame_index;
- return *this;
+ return std::move(*this);
+ }
+ PaintImageBuilder&& set_repetition_count(int count) {
+ paint_image_.repetition_count_ = count;
+ return std::move(*this);
+ }
+ PaintImageBuilder&& set_reset_animation_sequence_id(
+ PaintImage::AnimationSequenceId id) {
+ paint_image_.reset_animation_sequence_id_ = id;
+ return std::move(*this);
}
- PaintImageBuilder& set_sk_image_id(uint32_t sk_image_id) {
- paint_image_.sk_image_id_ = sk_image_id;
- return *this;
+ // Makes the PaintImage represent a subset of the original image. The
+ // subset must be non-empty and lie within the image bounds.
+ PaintImageBuilder&& make_subset(const gfx::Rect& subset) {
+ paint_image_ = paint_image_.MakeSubset(subset);
+ return std::move(*this);
+ }
+ PaintImageBuilder&& set_decoding_mode(
+ PaintImage::DecodingMode decoding_mode) {
+ paint_image_.decoding_mode_ = decoding_mode;
+ return std::move(*this);
}
- PaintImage TakePaintImage() const;
+ PaintImage TakePaintImage();
private:
+ PaintImageBuilder();
+ PaintImageBuilder(PaintImage starting_image, bool clear_contents);
+
PaintImage paint_image_;
#if DCHECK_IS_ON()
bool id_set_ = false;
#endif
-
- DISALLOW_COPY_AND_ASSIGN(PaintImageBuilder);
};
} // namespace cc
diff --git a/chromium/cc/paint/paint_image_unittest.cc b/chromium/cc/paint/paint_image_unittest.cc
index 0fe9a4ffda1..78a2240bdce 100644
--- a/chromium/cc/paint/paint_image_unittest.cc
+++ b/chromium/cc/paint/paint_image_unittest.cc
@@ -5,6 +5,8 @@
#include "cc/paint/paint_image.h"
#include "base/test/gtest_util.h"
+#include "cc/paint/paint_image_builder.h"
+#include "cc/test/fake_paint_image_generator.h"
#include "cc/test/skia_common.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -15,20 +17,69 @@ TEST(PaintImageTest, Subsetting) {
EXPECT_EQ(image.width(), 100);
EXPECT_EQ(image.height(), 100);
- PaintImage subset_rect_1 = image.MakeSubset(gfx::Rect(25, 25, 50, 50));
+ PaintImage subset_rect_1 = PaintImageBuilder::WithCopy(image)
+ .make_subset(gfx::Rect(25, 25, 50, 50))
+ .TakePaintImage();
EXPECT_EQ(subset_rect_1.width(), 50);
EXPECT_EQ(subset_rect_1.height(), 50);
EXPECT_EQ(subset_rect_1.subset_rect_, gfx::Rect(25, 25, 50, 50));
- PaintImage subset_rect_2 =
- subset_rect_1.MakeSubset(gfx::Rect(25, 25, 25, 25));
+ PaintImage subset_rect_2 = PaintImageBuilder::WithCopy(subset_rect_1)
+ .make_subset(gfx::Rect(25, 25, 25, 25))
+ .TakePaintImage();
EXPECT_EQ(subset_rect_2.width(), 25);
EXPECT_EQ(subset_rect_2.height(), 25);
EXPECT_EQ(subset_rect_2.subset_rect_, gfx::Rect(50, 50, 25, 25));
- EXPECT_EQ(image, image.MakeSubset(gfx::Rect(100, 100)));
- EXPECT_DCHECK_DEATH(subset_rect_2.MakeSubset(gfx::Rect(10, 10, 25, 25)));
- EXPECT_DCHECK_DEATH(image.MakeSubset(gfx::Rect()));
+ EXPECT_EQ(image, PaintImageBuilder::WithCopy(image)
+ .make_subset(gfx::Rect(100, 100))
+ .TakePaintImage());
+ EXPECT_DCHECK_DEATH(PaintImageBuilder::WithCopy(subset_rect_2)
+ .make_subset(gfx::Rect(10, 10, 25, 25))
+ .TakePaintImage());
+ EXPECT_DCHECK_DEATH(PaintImageBuilder::WithCopy(image)
+ .make_subset(gfx::Rect())
+ .TakePaintImage());
+}
+
+TEST(PaintImageTest, DecodesCorrectFrames) {
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))};
+ sk_sp<FakePaintImageGenerator> generator =
+ sk_make_sp<FakePaintImageGenerator>(SkImageInfo::MakeN32Premul(10, 10),
+ frames);
+ PaintImage image = PaintImageBuilder::WithDefault()
+ .set_id(PaintImage::GetNextId())
+ .set_paint_image_generator(generator)
+ .set_frame_index(0u)
+ .TakePaintImage();
+
+ // The recorded index is 0u but ask for 1u frame.
+ SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
+ std::vector<size_t> memory(info.computeMinByteSize());
+ image.Decode(memory.data(), &info, nullptr, 1u);
+ ASSERT_EQ(generator->frames_decoded().size(), 1u);
+ EXPECT_EQ(generator->frames_decoded().count(1u), 1u);
+ generator->reset_frames_decoded();
+
+ // Subsetted.
+ PaintImage subset_image = PaintImageBuilder::WithCopy(image)
+ .make_subset(gfx::Rect(0, 0, 5, 5))
+ .TakePaintImage();
+ SkImageInfo subset_info = info.makeWH(5, 5);
+ subset_image.Decode(memory.data(), &subset_info, nullptr, 1u);
+ ASSERT_EQ(generator->frames_decoded().size(), 1u);
+ EXPECT_EQ(generator->frames_decoded().count(1u), 1u);
+ generator->reset_frames_decoded();
+
+ // Not N32 color type.
+ info.makeColorType(kRGB_565_SkColorType);
+ memory = std::vector<size_t>(info.computeMinByteSize());
+ image.Decode(memory.data(), &info, nullptr, 1u);
+ ASSERT_EQ(generator->frames_decoded().size(), 1u);
+ EXPECT_EQ(generator->frames_decoded().count(1u), 1u);
+ generator->reset_frames_decoded();
}
} // namespace cc
diff --git a/chromium/cc/paint/paint_op_buffer.cc b/chromium/cc/paint/paint_op_buffer.cc
index 2cecf129957..089746c439a 100644
--- a/chromium/cc/paint/paint_op_buffer.cc
+++ b/chromium/cc/paint/paint_op_buffer.cc
@@ -13,27 +13,17 @@
#include "cc/paint/paint_op_reader.h"
#include "cc/paint/paint_op_writer.h"
#include "cc/paint/paint_record.h"
+#include "cc/paint/scoped_image_flags.h"
#include "third_party/skia/include/core/SkAnnotation.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkRegion.h"
namespace cc {
namespace {
-
-bool IsImageShader(const PaintFlags& flags) {
- return flags.HasShader() &&
- flags.getShader()->shader_type() == PaintShader::Type::kImage;
-}
-
-bool IsImageOp(const PaintOp* op) {
- if (op->GetType() == PaintOpType::DrawImage)
- return true;
- else if (op->GetType() == PaintOpType::DrawImageRect)
- return true;
- else if (op->IsDrawOp() && op->IsPaintOpWithFlags())
- return IsImageShader(static_cast<const PaintOpWithFlags*>(op)->flags);
-
- return false;
+SkIRect RoundOutRect(const SkRect& rect) {
+ SkIRect result;
+ rect.roundOut(&result);
+ return result;
}
bool QuickRejectDraw(const PaintOp* op, const SkCanvas* canvas) {
@@ -53,63 +43,6 @@ bool QuickRejectDraw(const PaintOp* op, const SkCanvas* canvas) {
return canvas->quickReject(rect);
}
-// Encapsulates a ImageProvider::DecodedImageHolder and a SkPaint. Use of
-// this class ensures that the DecodedImageHolder outlives the dependent
-// SkPaint.
-class ScopedImageFlags {
- public:
- ScopedImageFlags(ImageProvider* image_provider,
- const PaintFlags& flags,
- const SkMatrix& ctm) {
- DCHECK(IsImageShader(flags));
-
- const PaintImage& paint_image = flags.getShader()->paint_image();
- SkMatrix matrix = flags.getShader()->GetLocalMatrix();
-
- SkMatrix total_image_matrix = matrix;
- total_image_matrix.preConcat(ctm);
- SkRect src_rect =
- SkRect::MakeIWH(paint_image.width(), paint_image.height());
- scoped_decoded_draw_image_ = image_provider->GetDecodedDrawImage(
- paint_image, src_rect, flags.getFilterQuality(), total_image_matrix);
-
- if (!scoped_decoded_draw_image_)
- return;
- const auto& decoded_image = scoped_decoded_draw_image_.decoded_image();
- DCHECK(decoded_image.image());
-
- bool need_scale = !decoded_image.is_scale_adjustment_identity();
- if (need_scale) {
- matrix.preScale(1.f / decoded_image.scale_adjustment().width(),
- 1.f / decoded_image.scale_adjustment().height());
- }
-
- sk_sp<SkImage> sk_image =
- sk_ref_sp<SkImage>(const_cast<SkImage*>(decoded_image.image().get()));
- PaintImage decoded_paint_image = PaintImageBuilder()
- .set_id(paint_image.stable_id())
- .set_image(std::move(sk_image))
- .TakePaintImage();
- decoded_flags_.emplace(flags);
- decoded_flags_.value().setFilterQuality(decoded_image.filter_quality());
- decoded_flags_.value().setShader(
- PaintShader::MakeImage(decoded_paint_image, flags.getShader()->tx(),
- flags.getShader()->ty(), &matrix));
- }
-
- PaintFlags* decoded_flags() {
- return decoded_flags_ ? &decoded_flags_.value() : nullptr;
- }
-
- ~ScopedImageFlags() = default;
-
- private:
- base::Optional<PaintFlags> decoded_flags_;
- ImageProvider::ScopedDecodedDrawImage scoped_decoded_draw_image_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedImageFlags);
-};
-
void RasterWithAlpha(const PaintOp* op,
SkCanvas* canvas,
const PlaybackParams& params,
@@ -126,7 +59,7 @@ void RasterWithAlpha(const PaintOp* op,
// ImageProvider if it consists of an image shader.
base::Optional<ScopedImageFlags> scoped_flags;
const PaintFlags* decoded_flags = &flags_op->flags;
- if (params.image_provider && IsImageShader(flags_op->flags)) {
+ if (params.image_provider && flags_op->HasDiscardableImagesFromFlags()) {
scoped_flags.emplace(params.image_provider, flags_op->flags,
canvas->getTotalMatrix());
decoded_flags = scoped_flags.value().decoded_flags();
@@ -743,7 +676,11 @@ PaintOp* ConcatOp::Deserialize(const volatile void* input,
void* output,
size_t output_size) {
DCHECK_GE(output_size, sizeof(ConcatOp));
- return SimpleDeserialize<ConcatOp>(input, input_size, output, output_size);
+ auto* op =
+ SimpleDeserialize<ConcatOp>(input, input_size, output, output_size);
+ if (op)
+ PaintOpReader::FixupMatrixPostSerialization(&op->matrix);
+ return op;
}
PaintOp* DrawColorOp::Deserialize(const volatile void* input,
@@ -1027,7 +964,11 @@ PaintOp* SetMatrixOp::Deserialize(const volatile void* input,
void* output,
size_t output_size) {
DCHECK_GE(output_size, sizeof(SetMatrixOp));
- return SimpleDeserialize<SetMatrixOp>(input, input_size, output, output_size);
+ auto* op =
+ SimpleDeserialize<SetMatrixOp>(input, input_size, output, output_size);
+ if (op)
+ PaintOpReader::FixupMatrixPostSerialization(&op->matrix);
+ return op;
}
PaintOp* TranslateOp::Deserialize(const volatile void* input,
@@ -1105,11 +1046,12 @@ void DrawImageOp::RasterWithFlags(const DrawImageOp* op,
return;
}
- SkRect image_rect = SkRect::MakeIWH(op->image.width(), op->image.height());
- auto scoped_decoded_draw_image = params.image_provider->GetDecodedDrawImage(
- op->image, image_rect,
+ DrawImage draw_image(
+ op->image, SkIRect::MakeWH(op->image.width(), op->image.height()),
flags ? flags->getFilterQuality() : kNone_SkFilterQuality,
canvas->getTotalMatrix());
+ auto scoped_decoded_draw_image =
+ params.image_provider->GetDecodedDrawImage(draw_image);
if (!scoped_decoded_draw_image)
return;
@@ -1150,9 +1092,11 @@ void DrawImageRectOp::RasterWithFlags(const DrawImageRectOp* op,
matrix.setRectToRect(op->src, op->dst, SkMatrix::kFill_ScaleToFit);
matrix.postConcat(canvas->getTotalMatrix());
- auto scoped_decoded_draw_image = params.image_provider->GetDecodedDrawImage(
- op->image, op->src,
+ DrawImage draw_image(
+ op->image, RoundOutRect(op->src),
flags ? flags->getFilterQuality() : kNone_SkFilterQuality, matrix);
+ auto scoped_decoded_draw_image =
+ params.image_provider->GetDecodedDrawImage(draw_image);
if (!scoped_decoded_draw_image)
return;
@@ -1437,12 +1381,47 @@ bool PaintOp::GetBounds(const PaintOp* op, SkRect* rect) {
return false;
}
+// static
+bool PaintOp::OpHasDiscardableImages(const PaintOp* op) {
+ if (op->IsPaintOpWithFlags() && static_cast<const PaintOpWithFlags*>(op)
+ ->HasDiscardableImagesFromFlags()) {
+ return true;
+ }
+
+ if (op->GetType() == PaintOpType::DrawImage &&
+ static_cast<const DrawImageOp*>(op)->HasDiscardableImages()) {
+ return true;
+ } else if (op->GetType() == PaintOpType::DrawImageRect &&
+ static_cast<const DrawImageRectOp*>(op)->HasDiscardableImages()) {
+ return true;
+ } else if (op->GetType() == PaintOpType::DrawRecord &&
+ static_cast<const DrawRecordOp*>(op)->HasDiscardableImages()) {
+ return true;
+ }
+
+ return false;
+}
+
void PaintOp::DestroyThis() {
auto func = g_destructor_functions[type];
if (func)
func(this);
}
+bool PaintOpWithFlags::HasDiscardableImagesFromFlags() const {
+ if (!IsDrawOp())
+ return false;
+
+ if (!flags.HasShader())
+ return false;
+ else if (flags.getShader()->shader_type() == PaintShader::Type::kImage)
+ return flags.getShader()->paint_image().IsLazyGenerated();
+ else if (flags.getShader()->shader_type() == PaintShader::Type::kPaintRecord)
+ return flags.getShader()->paint_record()->HasDiscardableImages();
+
+ return false;
+}
+
void PaintOpWithFlags::RasterWithFlags(SkCanvas* canvas,
const PaintFlags* flags,
const PlaybackParams& params) const {
@@ -1720,7 +1699,8 @@ void PaintOpBuffer::Playback(SkCanvas* canvas,
// general case we defer this to the SkCanvas but if we will be
// using an ImageProvider for pre-decoding images, we can save
// performing an expensive decode that will never be rasterized.
- const bool skip_op = params.image_provider && IsImageOp(draw_op) &&
+ const bool skip_op = params.image_provider &&
+ PaintOp::OpHasDiscardableImages(draw_op) &&
QuickRejectDraw(draw_op, canvas);
if (skip_op) {
// Now that we know this op will be skipped, we can push the save
@@ -1750,15 +1730,15 @@ void PaintOpBuffer::Playback(SkCanvas* canvas,
}
}
- if (params.image_provider && IsImageOp(op)) {
+ if (params.image_provider && PaintOp::OpHasDiscardableImages(op)) {
if (QuickRejectDraw(op, canvas))
continue;
auto* flags_op = op->IsPaintOpWithFlags()
? static_cast<const PaintOpWithFlags*>(op)
: nullptr;
- if (flags_op && IsImageShader(flags_op->flags)) {
- ScopedImageFlags scoped_flags(image_provider, flags_op->flags,
+ if (flags_op && flags_op->HasDiscardableImagesFromFlags()) {
+ ScopedImageFlags scoped_flags(params.image_provider, flags_op->flags,
canvas->getTotalMatrix());
// Only rasterize the op if we successfully decoded the image.
diff --git a/chromium/cc/paint/paint_op_buffer.h b/chromium/cc/paint/paint_op_buffer.h
index 17405ecac86..96eb7f7b124 100644
--- a/chromium/cc/paint/paint_op_buffer.h
+++ b/chromium/cc/paint/paint_op_buffer.h
@@ -15,6 +15,7 @@
#include "base/memory/aligned_memory.h"
#include "base/optional.h"
#include "cc/base/math_util.h"
+#include "cc/paint/image_provider.h"
#include "cc/paint/paint_canvas.h"
#include "cc/paint/paint_export.h"
#include "cc/paint/paint_flags.h"
@@ -29,7 +30,6 @@
namespace cc {
class ImageDecodeCache;
-class ImageProvider;
class CC_PAINT_EXPORT ThreadsafeMatrix : public SkMatrix {
public:
@@ -137,6 +137,10 @@ class CC_PAINT_EXPORT PaintOp {
// for the op.
static bool GetBounds(const PaintOp* op, SkRect* rect);
+ // Returns true if executing this op will require decoding of any lazy
+ // generated images.
+ static bool OpHasDiscardableImages(const PaintOp* op);
+
int CountSlowPaths() const { return 0; }
int CountSlowPathsFromFlags() const { return 0; }
@@ -195,14 +199,7 @@ class CC_PAINT_EXPORT PaintOpWithFlags : public PaintOp {
int CountSlowPathsFromFlags() const { return flags.getPathEffect() ? 1 : 0; }
bool HasNonAAPaint() const { return !flags.isAntiAlias(); }
- bool HasDiscardableImagesFromFlags() const {
- if (!IsDrawOp())
- return false;
-
- SkShader* shader = flags.getSkShader();
- SkImage* image = shader ? shader->isAImage(nullptr, nullptr) : nullptr;
- return image && image->isLazyGenerated();
- }
+ bool HasDiscardableImagesFromFlags() const;
void RasterWithFlags(SkCanvas* canvas,
const PaintFlags* flags,
@@ -981,6 +978,7 @@ class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt {
friend class DisplayItemList;
friend class PaintOpBufferOffsetsTest;
friend class SolidColorAnalyzer;
+ friend class ScopedImageFlags;
// Replays the paint op buffer into the canvas. If |indices| is specified, it
// contains indices in an increasing order and only the indices specified in
diff --git a/chromium/cc/paint/paint_op_buffer_unittest.cc b/chromium/cc/paint/paint_op_buffer_unittest.cc
index b9601e4a486..fdde146ca66 100644
--- a/chromium/cc/paint/paint_op_buffer_unittest.cc
+++ b/chromium/cc/paint/paint_op_buffer_unittest.cc
@@ -1280,7 +1280,11 @@ std::vector<uint8_t> test_uint8s = {
std::vector<SkRect> test_rects = {
SkRect::MakeXYWH(1, 2.5, 3, 4), SkRect::MakeXYWH(0, 0, 0, 0),
SkRect::MakeLargest(), SkRect::MakeXYWH(0.5f, 0.5f, 8.2f, 8.2f),
- SkRect::MakeXYWH(-1, -1, 0, 0), SkRect::MakeXYWH(-100, -101, -102, -103)};
+ SkRect::MakeXYWH(-1, -1, 0, 0), SkRect::MakeXYWH(-100, -101, -102, -103),
+ SkRect::MakeXYWH(0, 0, 0, 0), SkRect::MakeXYWH(0, 0, 0, 0),
+ SkRect::MakeXYWH(0, 0, 0, 0), SkRect::MakeXYWH(0, 0, 0, 0),
+ SkRect::MakeXYWH(0, 0, 0, 0), SkRect::MakeXYWH(0, 0, 0, 0),
+};
std::vector<SkRRect> test_rrects = {
SkRRect::MakeEmpty(), SkRRect::MakeOval(SkRect::MakeXYWH(1, 2, 3, 4)),
@@ -1298,7 +1302,7 @@ std::vector<SkIRect> test_irects = {
SkIRect::MakeXYWH(-1, -1, 0, 0), SkIRect::MakeXYWH(-100, -101, -102, -103)};
std::vector<SkMatrix> test_matrices = {
- SkMatrix(),
+ SkMatrix::I(),
SkMatrix::MakeScale(3.91f, 4.31f),
SkMatrix::MakeTrans(-5.2f, 8.7f),
[] {
@@ -1421,7 +1425,15 @@ std::vector<PaintFlags> test_flags = {
return flags;
}(),
- PaintFlags(),
+ [] {
+ PaintFlags flags;
+ SkColor colors[3] = {SkColorSetARGB(1, 2, 3, 4),
+ SkColorSetARGB(4, 3, 2, 1),
+ SkColorSetARGB(0, 10, 20, 30)};
+ flags.setShader(PaintShader::MakeSweepGradient(
+ 0.2f, -0.8f, colors, nullptr, 3, SkShader::kMirror_TileMode, 10, 20));
+ return flags;
+ }(),
PaintFlags(),
PaintFlags(),
};
@@ -1832,6 +1844,20 @@ void CompareFlags(const PaintFlags& original, const PaintFlags& written) {
void CompareImages(const PaintImage& original, const PaintImage& written) {}
+void CompareMatrices(const SkMatrix& original, const SkMatrix& written) {
+ // Compare the 3x3 matrix values.
+ EXPECT_EQ(original, written);
+
+ // If a serialized matrix says it is identity, then the original must have
+ // those values, as the serialization process clobbers the matrix values.
+ if (original.isIdentity()) {
+ EXPECT_EQ(SkMatrix::I(), original);
+ EXPECT_EQ(SkMatrix::I(), written);
+ }
+
+ EXPECT_EQ(original.getType(), written.getType());
+}
+
void CompareAnnotateOp(const AnnotateOp* original, const AnnotateOp* written) {
EXPECT_TRUE(original->IsValid());
EXPECT_TRUE(written->IsValid());
@@ -1873,8 +1899,7 @@ void CompareClipRRectOp(const ClipRRectOp* original,
void CompareConcatOp(const ConcatOp* original, const ConcatOp* written) {
EXPECT_TRUE(original->IsValid());
EXPECT_TRUE(written->IsValid());
- EXPECT_EQ(original->matrix, written->matrix);
- EXPECT_EQ(original->matrix.getType(), written->matrix.getType());
+ CompareMatrices(original->matrix, written->matrix);
}
void CompareDrawColorOp(const DrawColorOp* original,
@@ -2047,7 +2072,7 @@ void CompareSetMatrixOp(const SetMatrixOp* original,
const SetMatrixOp* written) {
EXPECT_TRUE(original->IsValid());
EXPECT_TRUE(written->IsValid());
- EXPECT_EQ(original->matrix, written->matrix);
+ CompareMatrices(original->matrix, written->matrix);
}
void CompareTranslateOp(const TranslateOp* original,
@@ -2796,10 +2821,8 @@ class MockImageProvider : public ImageProvider {
~MockImageProvider() override = default;
- ScopedDecodedDrawImage GetDecodedDrawImage(const PaintImage& paint_image,
- const SkRect& src_rect,
- SkFilterQuality filter_quality,
- const SkMatrix& matrix) override {
+ ScopedDecodedDrawImage GetDecodedDrawImage(
+ const DrawImage& draw_image) override {
if (fail_all_decodes_)
return ScopedDecodedDrawImage();
diff --git a/chromium/cc/paint/paint_op_reader.cc b/chromium/cc/paint/paint_op_reader.cc
index 692c5ac934b..19d64fe1a49 100644
--- a/chromium/cc/paint/paint_op_reader.cc
+++ b/chromium/cc/paint/paint_op_reader.cc
@@ -7,6 +7,7 @@
#include <stddef.h>
#include "cc/paint/paint_flags.h"
+#include "cc/paint/paint_op_buffer.h"
#include "cc/paint/paint_shader.h"
#include "third_party/skia/include/core/SkFlattenableSerialization.h"
#include "third_party/skia/include/core/SkPath.h"
@@ -35,6 +36,16 @@ bool IsValidPaintShaderScalingBehavior(PaintShader::ScalingBehavior behavior) {
} // namespace
+// static
+void PaintOpReader::FixupMatrixPostSerialization(SkMatrix* matrix) {
+ // Can't trust malicious clients to provide the correct derived matrix type.
+ // However, if a matrix thinks that it's identity, then make it so.
+ if (matrix->isIdentity())
+ matrix->setIdentity();
+ else
+ matrix->dirtyMatrixTypeCache();
+}
+
template <typename T>
void PaintOpReader::ReadSimple(T* val) {
static_assert(base::is_trivially_copyable<T>::value,
@@ -237,7 +248,7 @@ void PaintOpReader::Read(sk_sp<PaintShader>* shader) {
ReadSimple(&has_local_matrix);
if (has_local_matrix) {
ref.local_matrix_.emplace();
- ReadSimple(&*ref.local_matrix_);
+ Read(&*ref.local_matrix_);
}
ReadSimple(&ref.center_);
ReadSimple(&ref.tile_);
@@ -265,9 +276,8 @@ void PaintOpReader::Read(sk_sp<PaintShader>* shader) {
decltype(ref.positions_)::size_type positions_size = 0;
ReadSimple(&positions_size);
- // TODO(enne): positions and colors have to have the same count, so maybe
- // don't serialize this either?
- if (positions_size != colors_size) {
+ // Positions are optional. If they exist, they have the same count as colors.
+ if (positions_size > 0 && positions_size != colors_size) {
valid_ = false;
return;
}
@@ -296,6 +306,11 @@ void PaintOpReader::Read(sk_sp<PaintShader>* shader) {
}
}
+void PaintOpReader::Read(SkMatrix* matrix) {
+ ReadSimple(matrix);
+ FixupMatrixPostSerialization(matrix);
+}
+
bool PaintOpReader::AlignMemory(size_t alignment) {
// Due to the math below, alignment must be a power of two.
DCHECK_GT(alignment, 0u);
diff --git a/chromium/cc/paint/paint_op_reader.h b/chromium/cc/paint/paint_op_reader.h
index 8f1e9ac8228..afb8bea5b87 100644
--- a/chromium/cc/paint/paint_op_reader.h
+++ b/chromium/cc/paint/paint_op_reader.h
@@ -26,6 +26,8 @@ class CC_PAINT_EXPORT PaintOpReader {
valid_ = false;
}
+ static void FixupMatrixPostSerialization(SkMatrix* matrix);
+
bool valid() const { return valid_; }
void ReadData(size_t bytes, void* data);
@@ -44,6 +46,7 @@ class CC_PAINT_EXPORT PaintOpReader {
void Read(sk_sp<SkData>* data);
void Read(sk_sp<SkTextBlob>* blob);
void Read(sk_sp<PaintShader>* shader);
+ void Read(SkMatrix* matrix);
void Read(SkClipOp* op) {
uint8_t value = 0u;
diff --git a/chromium/cc/paint/paint_shader.cc b/chromium/cc/paint/paint_shader.cc
index 2257e6af4f3..0904ad06fc4 100644
--- a/chromium/cc/paint/paint_shader.cc
+++ b/chromium/cc/paint/paint_shader.cc
@@ -6,9 +6,25 @@
#include "base/memory/ptr_util.h"
#include "cc/paint/paint_record.h"
+#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
namespace cc {
+namespace {
+
+sk_sp<SkPicture> ToSkPicture(sk_sp<PaintRecord> record,
+ const SkRect& bounds,
+ const SkMatrix* matrix,
+ ImageProvider* image_provider) {
+ SkPictureRecorder recorder;
+ SkCanvas* canvas = recorder.beginRecording(bounds);
+ if (matrix)
+ canvas->setMatrix(*matrix);
+ record->Playback(canvas, image_provider);
+ return recorder.finishRecordingAsPicture();
+}
+
+} // namespace
sk_sp<PaintShader> PaintShader::MakeColor(SkColor color) {
sk_sp<PaintShader> shader(new PaintShader(Type::kColor));
@@ -16,6 +32,7 @@ sk_sp<PaintShader> PaintShader::MakeColor(SkColor color) {
// Just one color. Store it in the fallback color. Easy.
shader->fallback_color_ = color;
+ shader->CreateSkShader();
return shader;
}
@@ -36,6 +53,7 @@ sk_sp<PaintShader> PaintShader::MakeLinearGradient(const SkPoint points[],
shader->SetMatrixAndTiling(local_matrix, mode, mode);
shader->SetFlagsAndFallback(flags, fallback_color);
+ shader->CreateSkShader();
return shader;
}
@@ -56,6 +74,7 @@ sk_sp<PaintShader> PaintShader::MakeRadialGradient(const SkPoint& center,
shader->SetMatrixAndTiling(local_matrix, mode, mode);
shader->SetFlagsAndFallback(flags, fallback_color);
+ shader->CreateSkShader();
return shader;
}
@@ -81,6 +100,7 @@ sk_sp<PaintShader> PaintShader::MakeTwoPointConicalGradient(
shader->SetMatrixAndTiling(local_matrix, mode, mode);
shader->SetFlagsAndFallback(flags, fallback_color);
+ shader->CreateSkShader();
return shader;
}
@@ -104,6 +124,7 @@ sk_sp<PaintShader> PaintShader::MakeSweepGradient(SkScalar cx,
shader->SetMatrixAndTiling(local_matrix, mode, mode);
shader->SetFlagsAndFallback(flags, fallback_color);
+ shader->CreateSkShader();
return shader;
}
@@ -116,6 +137,7 @@ sk_sp<PaintShader> PaintShader::MakeImage(const PaintImage& image,
shader->image_ = image;
shader->SetMatrixAndTiling(local_matrix, tx, ty);
+ shader->CreateSkShader();
return shader;
}
@@ -133,15 +155,108 @@ sk_sp<PaintShader> PaintShader::MakePaintRecord(
shader->scaling_behavior_ = scaling_behavior;
shader->SetMatrixAndTiling(local_matrix, tx, ty);
+ shader->CreateSkShader();
return shader;
}
PaintShader::PaintShader(Type type) : shader_type_(type) {}
PaintShader::~PaintShader() = default;
+bool PaintShader::GetRasterizationTileRect(const SkMatrix& ctm,
+ SkRect* tile_rect) const {
+ DCHECK_EQ(shader_type_, Type::kPaintRecord);
+
+ // If we are using a fixed scale, the record is rasterized with the original
+ // tile size and scaling is applied to the generated output.
+ if (scaling_behavior_ == ScalingBehavior::kFixedScale) {
+ *tile_rect = tile_;
+ return true;
+ }
+
+ SkMatrix matrix = ctm;
+ if (local_matrix_.has_value())
+ matrix.preConcat(local_matrix_.value());
+
+ SkSize scale;
+ if (!matrix.decomposeScale(&scale)) {
+ // Decomposition failed, use an approximation.
+ scale.set(SkScalarSqrt(matrix.getScaleX() * matrix.getScaleX() +
+ matrix.getSkewX() * matrix.getSkewX()),
+ SkScalarSqrt(matrix.getScaleY() * matrix.getScaleY() +
+ matrix.getSkewY() * matrix.getSkewY()));
+ }
+ SkSize scaled_size =
+ SkSize::Make(SkScalarAbs(scale.width() * tile_.width()),
+ SkScalarAbs(scale.height() * tile_.height()));
+
+ // Clamp the tile size to about 4M pixels.
+ // TODO(khushalsagar): We need to consider the max texture size as well.
+ static const SkScalar kMaxTileArea = 2048 * 2048;
+ SkScalar tile_area = scaled_size.width() * scaled_size.height();
+ if (tile_area > kMaxTileArea) {
+ SkScalar clamp_scale = SkScalarSqrt(kMaxTileArea / tile_area);
+ scaled_size.set(scaled_size.width() * clamp_scale,
+ scaled_size.height() * clamp_scale);
+ }
+
+ scaled_size = scaled_size.toCeil();
+ if (scaled_size.isEmpty())
+ return false;
+
+ *tile_rect = SkRect::MakeWH(scaled_size.width(), scaled_size.height());
+ return true;
+}
+
+sk_sp<PaintShader> PaintShader::CreateDecodedPaintRecord(
+ const SkMatrix& ctm,
+ ImageProvider* image_provider) const {
+ DCHECK_EQ(shader_type_, Type::kPaintRecord);
+
+ // For creating a decoded PaintRecord shader, we need to do the following:
+ // 1) Figure out the scale at which the record should be rasterization given
+ // the ctm and local_matrix on the shader.
+ // 2) Transform this record to an SkPicture with this scale and replace
+ // encoded images in this record with decodes from the ImageProvider. This
+ // is done by setting the raster_matrix_ for this shader to be used
+ // in GetSkShader.
+ // 3) Since the SkShader will use a scaled SkPicture, we use a kFixedScale for
+ // the decoded shader which creates an SkPicture backed SkImage for
+ // creating the decoded SkShader.
+ // Note that the scaling logic here is replicated from
+ // SkPictureShader::refBitmapShader.
+ SkRect tile_rect;
+ if (!GetRasterizationTileRect(ctm, &tile_rect))
+ return nullptr;
+
+ sk_sp<PaintShader> shader(new PaintShader(Type::kPaintRecord));
+ shader->record_ = record_;
+ shader->tile_ = tile_rect;
+ // Use a fixed scale since we have already scaled the tile rect and fixed the
+ // raster scale.
+ shader->scaling_behavior_ = ScalingBehavior::kFixedScale;
+ shader->tx_ = tx_;
+ shader->ty_ = ty_;
+
+ const SkSize tile_scale =
+ SkSize::Make(SkIntToScalar(tile_rect.width()) / tile_.width(),
+ SkIntToScalar(tile_rect.height()) / tile_.height());
+ shader->local_matrix_ = GetLocalMatrix();
+ shader->local_matrix_->preScale(1 / tile_scale.width(),
+ 1 / tile_scale.height());
+
+ SkMatrix raster_matrix =
+ SkMatrix::MakeRectToRect(tile_, tile_rect, SkMatrix::kFill_ScaleToFit);
+ shader->CreateSkShader(image_provider, &raster_matrix);
+ return shader;
+}
+
sk_sp<SkShader> PaintShader::GetSkShader() const {
- if (cached_shader_)
- return cached_shader_;
+ return cached_shader_;
+}
+
+void PaintShader::CreateSkShader(ImageProvider* image_provider,
+ const SkMatrix* raster_matrix) {
+ DCHECK(!cached_shader_);
switch (shader_type_) {
case Type::kColor:
@@ -182,7 +297,9 @@ sk_sp<SkShader> PaintShader::GetSkShader() const {
tx_, ty_, local_matrix_ ? &*local_matrix_ : nullptr);
break;
case Type::kPaintRecord: {
- auto picture = ToSkPicture(record_, tile_);
+ // Create a recording at the desired scale if this record has images which
+ // have been decoded before raster.
+ auto picture = ToSkPicture(record_, tile_, raster_matrix, image_provider);
switch (scaling_behavior_) {
// For raster scale, we create a picture shader directly.
@@ -191,7 +308,7 @@ sk_sp<SkShader> PaintShader::GetSkShader() const {
std::move(picture), tx_, ty_,
local_matrix_ ? &*local_matrix_ : nullptr, nullptr);
break;
- // For fixed scale, we create an image shader with and image backed by
+ // For fixed scale, we create an image shader with an image backed by
// the picture.
case ScalingBehavior::kFixedScale: {
auto image = SkImage::MakeFromPicture(
@@ -214,7 +331,6 @@ sk_sp<SkShader> PaintShader::GetSkShader() const {
// one.
if (!cached_shader_)
cached_shader_ = SkShader::MakeColorShader(fallback_color_);
- return cached_shader_;
}
void PaintShader::SetColorsAndPositions(const SkColor* colors,
@@ -257,10 +373,15 @@ bool PaintShader::IsValid() const {
switch (shader_type_) {
case Type::kColor:
return true;
+ case Type::kSweepGradient:
+ if (!std::isfinite(start_degrees_) || !std::isfinite(end_degrees_) ||
+ start_degrees_ >= end_degrees_) {
+ return false;
+ }
+ // Fallthrough.
case Type::kLinearGradient:
case Type::kRadialGradient:
case Type::kTwoPointConicalGradient:
- case Type::kSweepGradient:
return colors_.size() >= 2 &&
(positions_.empty() || positions_.size() == colors_.size());
case Type::kImage:
diff --git a/chromium/cc/paint/paint_shader.h b/chromium/cc/paint/paint_shader.h
index 8a133709b2c..0c76dde2f50 100644
--- a/chromium/cc/paint/paint_shader.h
+++ b/chromium/cc/paint/paint_shader.h
@@ -16,7 +16,7 @@
#include "third_party/skia/include/core/SkShader.h"
namespace cc {
-
+class ImageProvider;
class PaintOpBuffer;
using PaintRecord = PaintOpBuffer;
@@ -111,8 +111,12 @@ class CC_PAINT_EXPORT PaintShader : public SkRefCnt {
return image_;
}
+ const sk_sp<PaintRecord>& paint_record() const { return record_; }
+ bool GetRasterizationTileRect(const SkMatrix& ctm, SkRect* tile_rect) const;
+
SkShader::TileMode tx() const { return tx_; }
SkShader::TileMode ty() const { return ty_; }
+ SkRect tile() const { return tile_; }
bool IsOpaque() const;
@@ -127,10 +131,18 @@ class CC_PAINT_EXPORT PaintShader : public SkRefCnt {
friend class PaintOpReader;
friend class PaintOpSerializationTestUtils;
friend class PaintOpWriter;
+ friend class ScopedImageFlags;
+ FRIEND_TEST_ALL_PREFIXES(PaintShaderTest, DecodePaintRecord);
explicit PaintShader(Type type);
sk_sp<SkShader> GetSkShader() const;
+ void CreateSkShader(ImageProvider* = nullptr,
+ const SkMatrix* raster_matrix = nullptr);
+
+ sk_sp<PaintShader> CreateDecodedPaintRecord(
+ const SkMatrix& ctm,
+ ImageProvider* image_provider) const;
void SetColorsAndPositions(const SkColor* colors,
const SkScalar* positions,
@@ -166,7 +178,10 @@ class CC_PAINT_EXPORT PaintShader : public SkRefCnt {
std::vector<SkColor> colors_;
std::vector<SkScalar> positions_;
- mutable sk_sp<SkShader> cached_shader_;
+ // The |cached_shader_| can be derived/creates from other inputs present in
+ // the PaintShader but we always construct it at creation time to ensure that
+ // accesses to it are thread-safe.
+ sk_sp<SkShader> cached_shader_;
DISALLOW_COPY_AND_ASSIGN(PaintShader);
};
diff --git a/chromium/cc/paint/paint_shader_unittest.cc b/chromium/cc/paint/paint_shader_unittest.cc
new file mode 100644
index 00000000000..d74a30772d9
--- /dev/null
+++ b/chromium/cc/paint/paint_shader_unittest.cc
@@ -0,0 +1,120 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/paint/paint_shader.h"
+
+#include "cc/paint/draw_image.h"
+#include "cc/paint/image_provider.h"
+#include "cc/paint/paint_image_builder.h"
+#include "cc/paint/paint_op_buffer.h"
+#include "cc/test/fake_paint_image_generator.h"
+#include "cc/test/skia_common.h"
+#include "cc/test/test_skcanvas.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/skia/include/core/SkSurface.h"
+
+namespace cc {
+namespace {
+
+class MockImageGenerator : public FakePaintImageGenerator {
+ public:
+ explicit MockImageGenerator(const gfx::Size& size)
+ : FakePaintImageGenerator(
+ SkImageInfo::MakeN32Premul(size.width(), size.height())) {}
+
+ MOCK_METHOD5(GetPixels,
+ bool(const SkImageInfo&, void*, size_t, size_t, uint32_t));
+};
+
+class MockImageProvider : public ImageProvider {
+ public:
+ MockImageProvider() = default;
+ ~MockImageProvider() override = default;
+
+ ScopedDecodedDrawImage GetDecodedDrawImage(
+ const DrawImage& draw_image) override {
+ draw_image_ = draw_image;
+
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(10, 10);
+ bitmap.eraseColor(SK_ColorBLACK);
+ sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
+ return ScopedDecodedDrawImage(
+ DecodedDrawImage(image, SkSize::MakeEmpty(), SkSize::Make(1.0f, 1.0f),
+ draw_image.filter_quality()));
+ }
+
+ const DrawImage& draw_image() const { return draw_image_; }
+
+ private:
+ DrawImage draw_image_;
+};
+
+} // namespace
+
+TEST(PaintShaderTest, RasterizationRectForRecordShaders) {
+ SkMatrix local_matrix = SkMatrix::MakeScale(0.5f, 0.5f);
+ auto record_shader = PaintShader::MakePaintRecord(
+ sk_make_sp<PaintOpBuffer>(), SkRect::MakeWH(100, 100),
+ SkShader::TileMode::kClamp_TileMode, SkShader::TileMode::kClamp_TileMode,
+ &local_matrix);
+
+ SkRect tile_rect;
+ SkMatrix ctm = SkMatrix::MakeScale(0.5f, 0.5f);
+ EXPECT_TRUE(record_shader->GetRasterizationTileRect(ctm, &tile_rect));
+ EXPECT_EQ(tile_rect, SkRect::MakeWH(25, 25));
+}
+
+TEST(PaintShaderTest, DecodePaintRecord) {
+ auto record = sk_make_sp<PaintOpBuffer>();
+
+ // Use a strict mock for the generator. It should never be used when
+ // rasterizing this shader, since the decode should be done by the
+ // ImageProvider.
+ auto generator =
+ sk_make_sp<testing::StrictMock<MockImageGenerator>>(gfx::Size(100, 100));
+ PaintImage paint_image = PaintImageBuilder::WithDefault()
+ .set_id(PaintImage::GetNextId())
+ .set_paint_image_generator(generator)
+ .TakePaintImage();
+
+ record->push<DrawImageOp>(paint_image, 0.f, 0.f, nullptr);
+ SkMatrix local_matrix = SkMatrix::MakeScale(0.5f, 0.5f);
+ auto record_shader = PaintShader::MakePaintRecord(
+ record, SkRect::MakeWH(100, 100), SkShader::TileMode::kClamp_TileMode,
+ SkShader::TileMode::kClamp_TileMode, &local_matrix);
+
+ PaintOpBuffer buffer;
+ PaintFlags flags;
+ flags.setShader(record_shader);
+ buffer.push<ScaleOp>(0.5f, 0.5f);
+ buffer.push<DrawRectOp>(SkRect::MakeWH(100, 100), flags);
+
+ MockImageProvider image_provider;
+ SaveCountingCanvas canvas;
+ buffer.Playback(&canvas, &image_provider);
+
+ EXPECT_EQ(canvas.draw_rect_, SkRect::MakeWH(100, 100));
+ SkShader* shader = canvas.paint_.getShader();
+ ASSERT_TRUE(shader);
+ SkMatrix decoded_local_matrix;
+ SkShader::TileMode xy[2];
+ SkImage* skia_image = shader->isAImage(&decoded_local_matrix, xy);
+ ASSERT_TRUE(skia_image);
+ EXPECT_TRUE(skia_image->isLazyGenerated());
+ EXPECT_EQ(xy[0], record_shader->tx());
+ EXPECT_EQ(xy[1], record_shader->ty());
+ EXPECT_EQ(decoded_local_matrix, SkMatrix::MakeScale(2.f, 2.f));
+
+ // The rasterization of the shader is internal to skia, so use a raster canvas
+ // to verify that the decoded paint does not have the encoded image.
+ auto surface = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100));
+ surface->getCanvas()->drawPaint(canvas.paint_);
+
+ // Using the shader requests decode for images at the correct scale.
+ EXPECT_EQ(image_provider.draw_image().paint_image(), paint_image);
+ EXPECT_EQ(image_provider.draw_image().scale(), SkSize::Make(0.25f, 0.25f));
+}
+
+} // namespace cc
diff --git a/chromium/cc/paint/record_paint_canvas.cc b/chromium/cc/paint/record_paint_canvas.cc
index 4fd83234b7e..1ecd86f238f 100644
--- a/chromium/cc/paint/record_paint_canvas.cc
+++ b/chromium/cc/paint/record_paint_canvas.cc
@@ -165,14 +165,6 @@ void RecordPaintCanvas::clipPath(const SkPath& path,
return;
}
-bool RecordPaintCanvas::quickReject(const SkRect& rect) const {
- return GetCanvas()->quickReject(rect);
-}
-
-bool RecordPaintCanvas::quickReject(const SkPath& path) const {
- return GetCanvas()->quickReject(path);
-}
-
SkRect RecordPaintCanvas::getLocalClipBounds() const {
return GetCanvas()->getLocalClipBounds();
}
@@ -275,7 +267,7 @@ void RecordPaintCanvas::drawBitmap(const SkBitmap& bitmap,
// TODO(enne): Move into base class?
if (bitmap.drawsNothing())
return;
- drawImage(PaintImageBuilder()
+ drawImage(PaintImageBuilder::WithDefault()
.set_id(PaintImage::kNonLazyStableId)
.set_image(SkImage::MakeFromBitmap(bitmap))
.TakePaintImage(),
diff --git a/chromium/cc/paint/record_paint_canvas.h b/chromium/cc/paint/record_paint_canvas.h
index b54c9efc6bf..cc187c59b7e 100644
--- a/chromium/cc/paint/record_paint_canvas.h
+++ b/chromium/cc/paint/record_paint_canvas.h
@@ -50,8 +50,6 @@ class CC_PAINT_EXPORT RecordPaintCanvas final : public PaintCanvas {
void clipRect(const SkRect& rect, SkClipOp op, bool antialias) override;
void clipRRect(const SkRRect& rrect, SkClipOp op, bool antialias) override;
void clipPath(const SkPath& path, SkClipOp op, bool antialias) override;
- bool quickReject(const SkRect& rect) const override;
- bool quickReject(const SkPath& path) const override;
SkRect getLocalClipBounds() const override;
bool getLocalClipBounds(SkRect* bounds) const override;
SkIRect getDeviceClipBounds() const override;
diff --git a/chromium/cc/paint/scoped_image_flags.cc b/chromium/cc/paint/scoped_image_flags.cc
new file mode 100644
index 00000000000..48fb839d9cf
--- /dev/null
+++ b/chromium/cc/paint/scoped_image_flags.cc
@@ -0,0 +1,103 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/paint/scoped_image_flags.h"
+
+#include "cc/paint/image_provider.h"
+#include "cc/paint/paint_image_builder.h"
+
+namespace cc {
+namespace {
+SkIRect RoundOutRect(const SkRect& rect) {
+ SkIRect result;
+ rect.roundOut(&result);
+ return result;
+}
+} // namespace
+
+ScopedImageFlags::DecodeStashingImageProvider::DecodeStashingImageProvider(
+ ImageProvider* source_provider)
+ : source_provider_(source_provider) {}
+ScopedImageFlags::DecodeStashingImageProvider::~DecodeStashingImageProvider() =
+ default;
+
+ImageProvider::ScopedDecodedDrawImage
+ScopedImageFlags::DecodeStashingImageProvider::GetDecodedDrawImage(
+ const DrawImage& draw_image) {
+ auto decode = source_provider_->GetDecodedDrawImage(draw_image);
+ if (!decode)
+ return ScopedDecodedDrawImage();
+
+ // No need to add any destruction callback to the returned image. The images
+ // decoded here match the lifetime of this provider.
+ auto image_to_return = ScopedDecodedDrawImage(decode.decoded_image());
+ decoded_images_.push_back(std::move(decode));
+ return image_to_return;
+}
+
+ScopedImageFlags::ScopedImageFlags(ImageProvider* image_provider,
+ const PaintFlags& flags,
+ const SkMatrix& ctm)
+ : decode_stashing_image_provider_(image_provider) {
+ if (flags.getShader()->shader_type() == PaintShader::Type::kImage) {
+ DecodeImageShader(flags, ctm);
+ } else {
+ DCHECK_EQ(flags.getShader()->shader_type(),
+ PaintShader::Type::kPaintRecord);
+ DecodeRecordShader(flags, ctm);
+ }
+}
+
+ScopedImageFlags::~ScopedImageFlags() = default;
+
+void ScopedImageFlags::DecodeImageShader(const PaintFlags& flags,
+ const SkMatrix& ctm) {
+ const PaintImage& paint_image = flags.getShader()->paint_image();
+ SkMatrix matrix = flags.getShader()->GetLocalMatrix();
+
+ SkMatrix total_image_matrix = matrix;
+ total_image_matrix.preConcat(ctm);
+ SkRect src_rect = SkRect::MakeIWH(paint_image.width(), paint_image.height());
+ DrawImage draw_image(paint_image, RoundOutRect(src_rect),
+ flags.getFilterQuality(), total_image_matrix);
+ auto decoded_draw_image =
+ decode_stashing_image_provider_.GetDecodedDrawImage(draw_image);
+
+ if (!decoded_draw_image)
+ return;
+
+ const auto& decoded_image = decoded_draw_image.decoded_image();
+ DCHECK(decoded_image.image());
+
+ bool need_scale = !decoded_image.is_scale_adjustment_identity();
+ if (need_scale) {
+ matrix.preScale(1.f / decoded_image.scale_adjustment().width(),
+ 1.f / decoded_image.scale_adjustment().height());
+ }
+
+ sk_sp<SkImage> sk_image =
+ sk_ref_sp<SkImage>(const_cast<SkImage*>(decoded_image.image().get()));
+ PaintImage decoded_paint_image = PaintImageBuilder::WithDefault()
+ .set_id(paint_image.stable_id())
+ .set_image(std::move(sk_image))
+ .TakePaintImage();
+ decoded_flags_.emplace(flags);
+ decoded_flags_.value().setFilterQuality(decoded_image.filter_quality());
+ decoded_flags_.value().setShader(
+ PaintShader::MakeImage(decoded_paint_image, flags.getShader()->tx(),
+ flags.getShader()->ty(), &matrix));
+}
+
+void ScopedImageFlags::DecodeRecordShader(const PaintFlags& flags,
+ const SkMatrix& ctm) {
+ auto decoded_shader = flags.getShader()->CreateDecodedPaintRecord(
+ ctm, &decode_stashing_image_provider_);
+ if (!decoded_shader)
+ return;
+
+ decoded_flags_.emplace(flags);
+ decoded_flags_.value().setShader(std::move(decoded_shader));
+}
+
+} // namespace cc
diff --git a/chromium/cc/paint/scoped_image_flags.h b/chromium/cc/paint/scoped_image_flags.h
new file mode 100644
index 00000000000..9c39bf8fa9a
--- /dev/null
+++ b/chromium/cc/paint/scoped_image_flags.h
@@ -0,0 +1,66 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_PAINT_SCOPED_IMAGE_FLAGS_H_
+#define CC_PAINT_SCOPED_IMAGE_FLAGS_H_
+
+#include "base/macros.h"
+#include "cc/paint/paint_export.h"
+#include "cc/paint/paint_op_buffer.h"
+
+namespace cc {
+class ImageProvider;
+
+// A helper class to decode images inside the provided |flags| and provide a
+// PaintFlags with the decoded images that can directly be used for
+// rasterization.
+// This class should only be used if |flags| has any discardable images.
+class CC_PAINT_EXPORT ScopedImageFlags {
+ public:
+ // |image_provider| must outlive this class.
+ ScopedImageFlags(ImageProvider* image_provider,
+ const PaintFlags& flags,
+ const SkMatrix& ctm);
+ ~ScopedImageFlags();
+
+ // The usage of these flags should not extend beyond the lifetime of this
+ // object.
+ PaintFlags* decoded_flags() {
+ return decoded_flags_ ? &decoded_flags_.value() : nullptr;
+ }
+
+ private:
+ // An ImageProvider that passes decode requests through to the
+ // |source_provider| but keeps the decode cached throughtout its lifetime,
+ // instead of passing the ref to the caller.
+ class DecodeStashingImageProvider : public ImageProvider {
+ public:
+ // |source_provider| must outlive this class.
+ explicit DecodeStashingImageProvider(ImageProvider* source_provider);
+ ~DecodeStashingImageProvider() override;
+
+ // ImageProvider implementation.
+ ScopedDecodedDrawImage GetDecodedDrawImage(
+ const DrawImage& draw_image) override;
+
+ private:
+ ImageProvider* source_provider_;
+ std::vector<ScopedDecodedDrawImage> decoded_images_;
+
+ DISALLOW_COPY_AND_ASSIGN(DecodeStashingImageProvider);
+ };
+
+ void DecodeImageShader(const PaintFlags& flags, const SkMatrix& ctm);
+
+ void DecodeRecordShader(const PaintFlags& flags, const SkMatrix& ctm);
+
+ base::Optional<PaintFlags> decoded_flags_;
+ DecodeStashingImageProvider decode_stashing_image_provider_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedImageFlags);
+};
+
+} // namespace cc
+
+#endif // CC_PAINT_SCOPED_IMAGE_FLAGS_H_
diff --git a/chromium/cc/paint/scoped_image_flags_unittest.cc b/chromium/cc/paint/scoped_image_flags_unittest.cc
new file mode 100644
index 00000000000..b8e919a97ed
--- /dev/null
+++ b/chromium/cc/paint/scoped_image_flags_unittest.cc
@@ -0,0 +1,70 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/paint/scoped_image_flags.h"
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "cc/test/skia_common.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace cc {
+namespace {
+class MockImageProvider : public ImageProvider {
+ public:
+ MockImageProvider() = default;
+ ~MockImageProvider() override { EXPECT_EQ(ref_count_, 0); }
+
+ ScopedDecodedDrawImage GetDecodedDrawImage(
+ const DrawImage& draw_image) override {
+ ref_count_++;
+
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(10, 10);
+ sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
+
+ return ScopedDecodedDrawImage(
+ DecodedDrawImage(image, SkSize::MakeEmpty(), SkSize::Make(1.0f, 1.0f),
+ draw_image.filter_quality()),
+ base::BindOnce(&MockImageProvider::UnrefImage, base::Unretained(this)));
+ }
+
+ void UnrefImage(DecodedDrawImage decoded_image) {
+ ref_count_--;
+ CHECK_GE(ref_count_, 0);
+ }
+
+ int ref_count() const { return ref_count_; }
+
+ private:
+ int ref_count_ = 0;
+};
+} // namespace
+
+TEST(ScopedImageFlagsTest, KeepsDecodesAlive) {
+ auto record = sk_make_sp<PaintOpBuffer>();
+ record->push<DrawImageOp>(CreateDiscardablePaintImage(gfx::Size(10, 10)), 0.f,
+ 0.f, nullptr);
+ record->push<DrawImageOp>(CreateDiscardablePaintImage(gfx::Size(10, 10)), 0.f,
+ 0.f, nullptr);
+ record->push<DrawImageOp>(CreateDiscardablePaintImage(gfx::Size(10, 10)), 0.f,
+ 0.f, nullptr);
+ auto record_shader = PaintShader::MakePaintRecord(
+ record, SkRect::MakeWH(100, 100), SkShader::TileMode::kClamp_TileMode,
+ SkShader::TileMode::kClamp_TileMode, &SkMatrix::I());
+
+ MockImageProvider provider;
+ PaintFlags flags;
+ flags.setShader(record_shader);
+ {
+ ScopedImageFlags scoped_flags(&provider, flags, SkMatrix::I());
+ ASSERT_TRUE(scoped_flags.decoded_flags());
+ SkPaint paint = scoped_flags.decoded_flags()->ToSkPaint();
+ ASSERT_TRUE(paint.getShader());
+ EXPECT_EQ(provider.ref_count(), 3);
+ }
+ EXPECT_EQ(provider.ref_count(), 0);
+}
+
+} // namespace cc
diff --git a/chromium/cc/paint/skia_paint_canvas.cc b/chromium/cc/paint/skia_paint_canvas.cc
index c3a6e415630..79428b85a6c 100644
--- a/chromium/cc/paint/skia_paint_canvas.cc
+++ b/chromium/cc/paint/skia_paint_canvas.cc
@@ -125,14 +125,6 @@ void SkiaPaintCanvas::clipPath(const SkPath& path,
canvas_->clipPath(path, op, do_anti_alias);
}
-bool SkiaPaintCanvas::quickReject(const SkRect& rect) const {
- return canvas_->quickReject(rect);
-}
-
-bool SkiaPaintCanvas::quickReject(const SkPath& path) const {
- return canvas_->quickReject(path);
-}
-
SkRect SkiaPaintCanvas::getLocalClipBounds() const {
return canvas_->getLocalClipBounds();
}
diff --git a/chromium/cc/paint/skia_paint_canvas.h b/chromium/cc/paint/skia_paint_canvas.h
index 36547517619..f60610f8269 100644
--- a/chromium/cc/paint/skia_paint_canvas.h
+++ b/chromium/cc/paint/skia_paint_canvas.h
@@ -58,8 +58,6 @@ class CC_PAINT_EXPORT SkiaPaintCanvas final : public PaintCanvas {
SkClipOp op,
bool do_anti_alias) override;
void clipPath(const SkPath& path, SkClipOp op, bool do_anti_alias) override;
- bool quickReject(const SkRect& rect) const override;
- bool quickReject(const SkPath& path) const override;
SkRect getLocalClipBounds() const override;
bool getLocalClipBounds(SkRect* bounds) const override;
SkIRect getDeviceClipBounds() const override;
diff --git a/chromium/cc/paint/skia_paint_image_generator.cc b/chromium/cc/paint/skia_paint_image_generator.cc
index 8d8479b7d42..40b30df340f 100644
--- a/chromium/cc/paint/skia_paint_image_generator.cc
+++ b/chromium/cc/paint/skia_paint_image_generator.cc
@@ -10,9 +10,8 @@ namespace cc {
SkiaPaintImageGenerator::SkiaPaintImageGenerator(
sk_sp<PaintImageGenerator> paint_image_generator,
- size_t frame_index,
- uint32_t unique_id)
- : SkImageGenerator(paint_image_generator->GetSkImageInfo(), unique_id),
+ size_t frame_index)
+ : SkImageGenerator(paint_image_generator->GetSkImageInfo()),
paint_image_generator_(std::move(paint_image_generator)),
frame_index_(frame_index) {}
diff --git a/chromium/cc/paint/skia_paint_image_generator.h b/chromium/cc/paint/skia_paint_image_generator.h
index 7c51bd8d37e..97da522e806 100644
--- a/chromium/cc/paint/skia_paint_image_generator.h
+++ b/chromium/cc/paint/skia_paint_image_generator.h
@@ -14,14 +14,8 @@ class PaintImageGenerator;
class CC_PAINT_EXPORT SkiaPaintImageGenerator final : public SkImageGenerator {
public:
- // This is required only by the DecodingImageGenerator in Blink for caching
- // of animated image frames.
- // TODO(khushalsagar): Remove the use of this uniqueID. See crbug.com/753639.
- enum { kNeedNewImageUniqueID = SkImageGenerator::kNeedNewImageUniqueID };
-
SkiaPaintImageGenerator(sk_sp<PaintImageGenerator> paint_image_generator,
- size_t frame_index,
- uint32_t unique_id = kNeedNewImageUniqueID);
+ size_t frame_index);
~SkiaPaintImageGenerator() override;
SkData* onRefEncodedData() override;
diff --git a/chromium/cc/paint/solid_color_analyzer.cc b/chromium/cc/paint/solid_color_analyzer.cc
index fe341d2ef04..79b3a43911e 100644
--- a/chromium/cc/paint/solid_color_analyzer.cc
+++ b/chromium/cc/paint/solid_color_analyzer.cc
@@ -45,9 +45,13 @@ bool IsSolidColorPaint(const PaintFlags& flags) {
flags.getStyle() == PaintFlags::kFill_Style;
}
-// Returns true if the specified drawn_rect will cover the entire canvas, and
-// that the canvas is not clipped (i.e. it covers ALL of the canvas).
-bool IsFullQuad(const SkCanvas& canvas, const SkRect& drawn_rect) {
+// Returns true if the specified |drawn_shape| will cover the entire canvas
+// and that the canvas is not clipped (i.e. it covers ALL of the canvas).
+template <typename T>
+bool IsFullQuad(const SkCanvas& canvas, const T& drawn_shape) {
+ if (!canvas.isClipRect())
+ return false;
+
SkIRect clip_irect;
if (!canvas.getDeviceClipBounds(&clip_irect))
return false;
@@ -62,11 +66,13 @@ bool IsFullQuad(const SkCanvas& canvas, const SkRect& drawn_rect) {
if (!matrix.rectStaysRect())
return false;
- SkRect device_rect;
- matrix.mapRect(&device_rect, drawn_rect);
- SkRect clip_rect;
- clip_rect.set(clip_irect);
- return device_rect.contains(clip_rect);
+ SkMatrix inverse;
+ if (!matrix.invert(&inverse))
+ return false;
+
+ SkRect clip_rect = SkRect::Make(clip_irect);
+ inverse.mapRect(&clip_rect, clip_rect);
+ return drawn_shape.contains(clip_rect);
}
void CheckIfSolidColor(const SkCanvas& canvas,
@@ -97,18 +103,19 @@ void CheckIfSolidColor(const SkCanvas& canvas,
}
}
-void CheckIfSolidRect(const SkCanvas& canvas,
- const SkRect& rect,
- const PaintFlags& flags,
- bool* is_solid_color,
- bool* is_transparent,
- SkColor* color) {
+template <typename T>
+void CheckIfSolidShape(const SkCanvas& canvas,
+ const T& shape,
+ const PaintFlags& flags,
+ bool* is_solid_color,
+ bool* is_transparent,
+ SkColor* color) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
- "SolidColorAnalyzer::HandleDrawRect");
+ "SolidColorAnalyzer::CheckIfSolidShape");
if (flags.nothingToDraw())
return;
- bool does_cover_canvas = IsFullQuad(canvas, rect);
+ bool does_cover_canvas = IsFullQuad(canvas, shape);
SkBlendMode blendmode = flags.getBlendMode();
if (does_cover_canvas && ActsLikeClear(blendmode, flags.getAlpha()))
*is_transparent = true;
@@ -123,6 +130,13 @@ void CheckIfSolidRect(const SkCanvas& canvas,
}
}
+bool CheckIfRRectClipCoversCanvas(const SkCanvas& canvas,
+ const SkRRect& rrect) {
+ TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
+ "SolidColorAnalyzer::CheckIfRRectClipCoversCanvas");
+ return IsFullQuad(canvas, rrect);
+}
+
} // namespace
base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor(
@@ -160,7 +174,7 @@ base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor(
stack.emplace_back(PaintOpBuffer::CompositeIterator(buffer, offsets),
canvas.getTotalMatrix(), canvas.getSaveCount());
- int num_ops = 0;
+ int num_draw_ops = 0;
while (!stack.empty()) {
auto& frame = stack.back();
if (!frame.iter) {
@@ -191,7 +205,15 @@ base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor(
case PaintOpType::DrawOval:
case PaintOpType::DrawPath:
return base::nullopt;
- case PaintOpType::DrawRRect:
+ // TODO(vmpstr): Add more tests on exceeding max_ops_to_analyze.
+ case PaintOpType::DrawRRect: {
+ if (++num_draw_ops > max_ops_to_analyze)
+ return base::nullopt;
+ const DrawRRectOp* rrect_op = static_cast<const DrawRRectOp*>(op);
+ CheckIfSolidShape(canvas, rrect_op->rrect, rrect_op->flags, &is_solid,
+ &is_transparent, &color);
+ break;
+ }
case PaintOpType::DrawTextBlob:
// Anything that has to do a save layer is probably not solid. As it will
// likely need more than one draw op.
@@ -202,18 +224,27 @@ base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor(
// cover the canvas.
// TODO(vmpstr): We could investigate handling these.
case PaintOpType::ClipPath:
- case PaintOpType::ClipRRect:
return base::nullopt;
+ case PaintOpType::ClipRRect: {
+ const ClipRRectOp* rrect_op = static_cast<const ClipRRectOp*>(op);
+ bool does_cover_canvas =
+ CheckIfRRectClipCoversCanvas(canvas, rrect_op->rrect);
+ // If the clip covers the full canvas, we can treat it as if there's no
+ // clip at all and continue, otherwise this is no longer a solid color.
+ if (!does_cover_canvas)
+ return base::nullopt;
+ break;
+ }
case PaintOpType::DrawRect: {
- if (++num_ops > max_ops_to_analyze)
+ if (++num_draw_ops > max_ops_to_analyze)
return base::nullopt;
const DrawRectOp* rect_op = static_cast<const DrawRectOp*>(op);
- CheckIfSolidRect(canvas, rect_op->rect, rect_op->flags, &is_solid,
- &is_transparent, &color);
+ CheckIfSolidShape(canvas, rect_op->rect, rect_op->flags, &is_solid,
+ &is_transparent, &color);
break;
}
case PaintOpType::DrawColor: {
- if (++num_ops > max_ops_to_analyze)
+ if (++num_draw_ops > max_ops_to_analyze)
return base::nullopt;
const DrawColorOp* color_op = static_cast<const DrawColorOp*>(op);
CheckIfSolidColor(canvas, color_op->color, color_op->mode, &is_solid,
diff --git a/chromium/cc/paint/solid_color_analyzer_unittest.cc b/chromium/cc/paint/solid_color_analyzer_unittest.cc
index a944cc6faed..c73cbe9c7ff 100644
--- a/chromium/cc/paint/solid_color_analyzer_unittest.cc
+++ b/chromium/cc/paint/solid_color_analyzer_unittest.cc
@@ -29,6 +29,11 @@ class SolidColorAnalyzerTest : public testing::Test {
buffer_ = nullptr;
}
+ void Reset() {
+ TearDown();
+ SetUp();
+ }
+
void Initialize(const gfx::Rect& rect = gfx::Rect(0, 0, 100, 100)) {
canvas_.emplace(display_item_list_.get(), gfx::RectToSkRect(rect));
rect_ = rect;
@@ -127,6 +132,21 @@ TEST_F(SolidColorAnalyzerTest, DrawRect) {
EXPECT_EQ(color, GetColor());
}
+// TODO(vmpstr): Generalize the DrawRect test cases so that we can test both
+// Rect and RRect.
+TEST_F(SolidColorAnalyzerTest, DrawRRect) {
+ SkRect rect = SkRect::MakeWH(200, 200);
+ SkRRect rrect;
+ rrect.setRectXY(rect, 5, 5);
+ gfx::Rect canvas_rect(5, 5, 190, 190);
+ Initialize(canvas_rect);
+ PaintFlags flags;
+ SkColor color = SkColorSetARGB(255, 11, 22, 33);
+ flags.setColor(color);
+ canvas()->drawRRect(rrect, flags);
+ EXPECT_EQ(color, GetColor());
+}
+
TEST_F(SolidColorAnalyzerTest, DrawRectClipped) {
Initialize();
PaintFlags flags;
@@ -278,5 +298,85 @@ TEST_F(SolidColorAnalyzerTest, SaveLayer) {
EXPECT_FALSE(IsSolidColor());
}
+TEST_F(SolidColorAnalyzerTest, ClipRRectCoversCanvas) {
+ SkVector radii[4] = {
+ SkVector::Make(10.0, 15.0), SkVector::Make(20.0, 25.0),
+ SkVector::Make(30.0, 35.0), SkVector::Make(40.0, 45.0),
+ };
+
+ SkVector radii_scale[4] = {
+ SkVector::Make(100.0, 150.0), SkVector::Make(200.0, 250.0),
+ SkVector::Make(300.0, 350.0), SkVector::Make(400.0, 450.0),
+ };
+
+ int rr_size = 600;
+ int canvas_size = 255;
+ gfx::Rect canvas_rect(canvas_size, canvas_size);
+ PaintFlags flags;
+ flags.setColor(SK_ColorWHITE);
+
+ struct {
+ SkVector offset;
+ SkVector offset_scale;
+ bool expected;
+ } cases[] = {
+ // Not within bounding box of |rr|.
+ {SkVector::Make(100, 100), SkVector::Make(100, 100), false},
+
+ // Intersects UL corner.
+ {SkVector::Make(0, 0), SkVector::Make(0, 0), false},
+
+ // Between UL and UR.
+ {SkVector::Make(-50, 0), SkVector::Make(-50, -15), true},
+
+ // Intersects UR corner.
+ {SkVector::Make(canvas_size - rr_size, 0),
+ SkVector::Make(canvas_size - rr_size, 0), false},
+
+ // Between UR and LR.
+ {SkVector::Make(canvas_size - rr_size, -50), SkVector::Make(-305, -80),
+ true},
+
+ // Intersects LR corner.
+ {SkVector::Make(canvas_size - rr_size, canvas_size - rr_size),
+ SkVector::Make(canvas_size - rr_size, canvas_size - rr_size), false},
+
+ // Between LL and LR
+ {SkVector::Make(-50, canvas_size - rr_size), SkVector::Make(-205, -310),
+ true},
+
+ // Intersects LL corner
+ {SkVector::Make(0, canvas_size - rr_size),
+ SkVector::Make(0, canvas_size - rr_size), false},
+
+ // Between UL and LL
+ {SkVector::Make(0, -50), SkVector::Make(-15, -60), true},
+
+ // In center
+ {SkVector::Make(-100, -100), SkVector::Make(-100, -100), true},
+ };
+
+ for (int case_scale = 0; case_scale < 2; ++case_scale) {
+ bool scaled = case_scale > 0;
+ for (size_t i = 0; i < arraysize(cases); ++i) {
+ Reset();
+ Initialize(canvas_rect);
+
+ SkRect bounding_rect = SkRect::MakeXYWH(
+ scaled ? cases[i].offset_scale.x() : cases[i].offset.x(),
+ scaled ? cases[i].offset_scale.y() : cases[i].offset.y(), rr_size,
+ rr_size);
+
+ SkRRect rr;
+ rr.setRectRadii(bounding_rect, scaled ? radii_scale : radii);
+
+ canvas()->clipRRect(rr, SkClipOp::kIntersect, false);
+ canvas()->drawRect(RectToSkRect(canvas_rect), flags);
+ EXPECT_EQ(cases[i].expected, IsSolidColor())
+ << "Case " << i << ", " << scaled << " failed.";
+ }
+ }
+}
+
} // namespace
} // namespace cc
diff --git a/chromium/cc/quads/content_draw_quad_base.cc b/chromium/cc/quads/content_draw_quad_base.cc
deleted file mode 100644
index 18e9e766d0f..00000000000
--- a/chromium/cc/quads/content_draw_quad_base.cc
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/content_draw_quad_base.h"
-
-#include "base/logging.h"
-#include "base/trace_event/trace_event_argument.h"
-#include "base/values.h"
-#include "cc/base/math_util.h"
-
-namespace cc {
-
-ContentDrawQuadBase::ContentDrawQuadBase()
- : swizzle_contents(false) {
-}
-
-ContentDrawQuadBase::~ContentDrawQuadBase() {
-}
-
-void ContentDrawQuadBase::SetNew(const viz::SharedQuadState* shared_quad_state,
- DrawQuad::Material material,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- const gfx::RectF& tex_coord_rect,
- const gfx::Size& texture_size,
- bool swizzle_contents,
- bool nearest_neighbor) {
- DrawQuad::SetAll(shared_quad_state, material, rect, visible_rect,
- needs_blending);
- this->tex_coord_rect = tex_coord_rect;
- this->texture_size = texture_size;
- this->swizzle_contents = swizzle_contents;
- this->nearest_neighbor = nearest_neighbor;
-}
-
-void ContentDrawQuadBase::SetAll(const viz::SharedQuadState* shared_quad_state,
- DrawQuad::Material material,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- const gfx::RectF& tex_coord_rect,
- const gfx::Size& texture_size,
- bool swizzle_contents,
- bool nearest_neighbor) {
- DrawQuad::SetAll(shared_quad_state, material, rect, visible_rect,
- needs_blending);
- this->tex_coord_rect = tex_coord_rect;
- this->texture_size = texture_size;
- this->swizzle_contents = swizzle_contents;
- this->nearest_neighbor = nearest_neighbor;
-}
-
-void ContentDrawQuadBase::ExtendValue(
- base::trace_event::TracedValue* value) const {
- MathUtil::AddToTracedValue("tex_coord_rect", tex_coord_rect, value);
- MathUtil::AddToTracedValue("texture_size", texture_size, value);
-
- value->SetBoolean("swizzle_contents", swizzle_contents);
- value->SetBoolean("nearest_neighbor", nearest_neighbor);
-}
-
-} // namespace cc
diff --git a/chromium/cc/quads/content_draw_quad_base.h b/chromium/cc/quads/content_draw_quad_base.h
deleted file mode 100644
index 08dba8568ae..00000000000
--- a/chromium/cc/quads/content_draw_quad_base.h
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_QUADS_CONTENT_DRAW_QUAD_BASE_H_
-#define CC_QUADS_CONTENT_DRAW_QUAD_BASE_H_
-
-#include <memory>
-
-#include "cc/cc_export.h"
-#include "cc/quads/draw_quad.h"
-#include "ui/gfx/geometry/rect_f.h"
-#include "ui/gfx/geometry/size.h"
-
-namespace gfx {
-class Rect;
-}
-
-namespace cc {
-
-class CC_EXPORT ContentDrawQuadBase : public DrawQuad {
- public:
- void SetNew(const viz::SharedQuadState* shared_quad_state,
- DrawQuad::Material material,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- const gfx::RectF& tex_coord_rect,
- const gfx::Size& texture_size,
- bool swizzle_contents,
- bool nearest_neighbor);
-
- void SetAll(const viz::SharedQuadState* shared_quad_state,
- DrawQuad::Material material,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- const gfx::RectF& tex_coord_rect,
- const gfx::Size& texture_size,
- bool swizzle_contents,
- bool nearest_neighbor);
-
- gfx::RectF tex_coord_rect;
- gfx::Size texture_size;
- bool swizzle_contents;
- bool nearest_neighbor;
-
- protected:
- ContentDrawQuadBase();
- ~ContentDrawQuadBase() override;
- void ExtendValue(base::trace_event::TracedValue* value) const override;
-};
-
-} // namespace cc
-
-#endif // CC_QUADS_CONTENT_DRAW_QUAD_BASE_H_
diff --git a/chromium/cc/quads/debug_border_draw_quad.cc b/chromium/cc/quads/debug_border_draw_quad.cc
deleted file mode 100644
index cabffff5969..00000000000
--- a/chromium/cc/quads/debug_border_draw_quad.cc
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/debug_border_draw_quad.h"
-
-#include "base/logging.h"
-#include "base/trace_event/trace_event_argument.h"
-#include "base/values.h"
-
-namespace cc {
-
-DebugBorderDrawQuad::DebugBorderDrawQuad()
- : color(0),
- width(0) {
-}
-
-void DebugBorderDrawQuad::SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- SkColor color,
- int width) {
- bool needs_blending = SkColorGetA(color) < 255;
- DrawQuad::SetAll(shared_quad_state, DrawQuad::DEBUG_BORDER, rect,
- visible_rect, needs_blending);
- this->color = color;
- this->width = width;
-}
-
-void DebugBorderDrawQuad::SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- SkColor color,
- int width) {
- DrawQuad::SetAll(shared_quad_state, DrawQuad::DEBUG_BORDER, rect,
- visible_rect, needs_blending);
- this->color = color;
- this->width = width;
-}
-
-const DebugBorderDrawQuad* DebugBorderDrawQuad::MaterialCast(
- const DrawQuad* quad) {
- DCHECK(quad->material == DrawQuad::DEBUG_BORDER);
- return static_cast<const DebugBorderDrawQuad*>(quad);
-}
-
-void DebugBorderDrawQuad::ExtendValue(
- base::trace_event::TracedValue* value) const {
- value->SetInteger("color", color);
- value->SetInteger("width", width);
-}
-
-} // namespace cc
diff --git a/chromium/cc/quads/debug_border_draw_quad.h b/chromium/cc/quads/debug_border_draw_quad.h
deleted file mode 100644
index 217c55ff61b..00000000000
--- a/chromium/cc/quads/debug_border_draw_quad.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_QUADS_DEBUG_BORDER_DRAW_QUAD_H_
-#define CC_QUADS_DEBUG_BORDER_DRAW_QUAD_H_
-
-#include <memory>
-
-#include "cc/cc_export.h"
-#include "cc/quads/draw_quad.h"
-#include "third_party/skia/include/core/SkColor.h"
-
-namespace cc {
-
-class CC_EXPORT DebugBorderDrawQuad : public DrawQuad {
- public:
- DebugBorderDrawQuad();
-
- void SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- SkColor color,
- int width);
-
- void SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- SkColor color,
- int width);
-
- SkColor color;
- int width;
-
- static const DebugBorderDrawQuad* MaterialCast(const DrawQuad*);
-
- private:
- void ExtendValue(base::trace_event::TracedValue* value) const override;
-};
-
-} // namespace cc
-
-#endif // CC_QUADS_DEBUG_BORDER_DRAW_QUAD_H_
diff --git a/chromium/cc/quads/draw_polygon.cc b/chromium/cc/quads/draw_polygon.cc
deleted file mode 100644
index 2b664f05835..00000000000
--- a/chromium/cc/quads/draw_polygon.cc
+++ /dev/null
@@ -1,351 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/draw_polygon.h"
-
-#include <stddef.h>
-
-#include <vector>
-
-#include "base/memory/ptr_util.h"
-#include "cc/quads/draw_quad.h"
-
-namespace {
-// This threshold controls how "thick" a plane is. If a point's distance is
-// <= |split_threshold|, then it is considered on the plane for the purpose of
-// polygon splitting.
-static const float split_threshold = 0.05f;
-
-static const float normalized_threshold = 0.001f;
-
-void PointInterpolate(const gfx::Point3F& from,
- const gfx::Point3F& to,
- double delta,
- gfx::Point3F* out) {
- out->SetPoint(from.x() + (to.x() - from.x()) * delta,
- from.y() + (to.y() - from.y()) * delta,
- from.z() + (to.z() - from.z()) * delta);
-}
-} // namespace
-
-namespace cc {
-
-DrawPolygon::DrawPolygon() {
-}
-
-DrawPolygon::DrawPolygon(const DrawQuad* original,
- const std::vector<gfx::Point3F>& in_points,
- const gfx::Vector3dF& normal,
- int draw_order_index)
- : normal_(normal),
- order_index_(draw_order_index),
- original_ref_(original),
- is_split_(true) {
- for (size_t i = 0; i < in_points.size(); i++) {
- points_.push_back(in_points[i]);
- }
- // If life was fair, we could recalculate the normal from the given points
- // and assert it was roughly the same. This causes unhelpful breaks on
- // trivial slices of split polygons. Similarly, when splitting, it is
- // better to keep the normal that was constructed from the original.
-}
-
-// This takes the original DrawQuad that this polygon should be based on,
-// a visible content rect to make the 4 corner points from, and a transformation
-// to move it and its normal into screen space.
-DrawPolygon::DrawPolygon(const DrawQuad* original_ref,
- const gfx::RectF& visible_layer_rect,
- const gfx::Transform& transform,
- int draw_order_index)
- : normal_(0.0f, 0.0f, 1.0f),
- order_index_(draw_order_index),
- original_ref_(original_ref),
- is_split_(false) {
- gfx::Point3F points[6];
- int num_vertices_in_clipped_quad;
- gfx::QuadF send_quad(visible_layer_rect);
-
- // Doing this mapping here is very important, since we can't just transform
- // the points without clipping and not run into strange geometry issues when
- // crossing w = 0. At this point, in the constructor, we know that we're
- // working with a quad, so we can reuse the MathUtil::MapClippedQuad3d
- // function instead of writing a generic polygon version of it.
- MathUtil::MapClippedQuad3d(
- transform, send_quad, points, &num_vertices_in_clipped_quad);
- for (int i = 0; i < num_vertices_in_clipped_quad; i++) {
- points_.push_back(points[i]);
- }
- transform.TransformVector(&normal_);
- ConstructNormal();
-}
-
-DrawPolygon::~DrawPolygon() {
-}
-
-std::unique_ptr<DrawPolygon> DrawPolygon::CreateCopy() {
- std::unique_ptr<DrawPolygon> new_polygon(new DrawPolygon());
- new_polygon->order_index_ = order_index_;
- new_polygon->original_ref_ = original_ref_;
- new_polygon->points_.reserve(points_.size());
- new_polygon->points_ = points_;
- new_polygon->normal_.set_x(normal_.x());
- new_polygon->normal_.set_y(normal_.y());
- new_polygon->normal_.set_z(normal_.z());
- return new_polygon;
-}
-
-//
-// If this were to be more generally used and expected to be applicable
-// replacing this with Newell's algorithm (or an improvement thereof)
-// would be preferable, but usually this is coming in from a rectangle
-// that has been transformed to screen space and clipped.
-// Averaging a few near diagonal cross products is pretty good in that case.
-//
-void DrawPolygon::ConstructNormal() {
- gfx::Vector3dF new_normal(0.0f, 0.0f, 0.0f);
- int delta = points_.size() / 2;
- for (size_t i = 1; i + delta < points_.size(); i++) {
- new_normal +=
- CrossProduct(points_[i] - points_[0], points_[i + delta] - points_[0]);
- }
- float normal_magnitude = new_normal.Length();
- // Here we constrain the new normal to point in the same sense as the old one.
- // This allows us to handle winding-reversing transforms better.
- if (gfx::DotProduct(normal_, new_normal) < 0.0) {
- normal_magnitude *= -1.0;
- }
- if (normal_magnitude != 0 && normal_magnitude != 1) {
- new_normal.Scale(1.0f / normal_magnitude);
- }
- normal_ = new_normal;
-}
-
-#if defined(OS_WIN)
-//
-// Allows the unittest to invoke this for the more general constructor.
-//
-void DrawPolygon::RecomputeNormalForTesting() {
- ConstructNormal();
-}
-#endif
-
-float DrawPolygon::SignedPointDistance(const gfx::Point3F& point) const {
- return gfx::DotProduct(point - points_[0], normal_);
-}
-
-// This function is separate from ApplyTransform because it is often unnecessary
-// to transform the normal with the rest of the polygon.
-// When drawing these polygons, it is necessary to move them back into layer
-// space before sending them to OpenGL, which requires using ApplyTransform,
-// but normal information is no longer needed after sorting.
-void DrawPolygon::ApplyTransformToNormal(const gfx::Transform& transform) {
- // Now we use the inverse transpose of |transform| to transform the normal.
- gfx::Transform inverse_transform;
- bool inverted = transform.GetInverse(&inverse_transform);
- DCHECK(inverted);
- if (!inverted)
- return;
- inverse_transform.Transpose();
-
- gfx::Point3F new_normal(normal_.x(), normal_.y(), normal_.z());
- inverse_transform.TransformPoint(&new_normal);
- // Make sure our normal is still normalized.
- normal_ = gfx::Vector3dF(new_normal.x(), new_normal.y(), new_normal.z());
- float normal_magnitude = normal_.Length();
- if (normal_magnitude != 0 && normal_magnitude != 1) {
- normal_.Scale(1.0f / normal_magnitude);
- }
-}
-
-void DrawPolygon::ApplyTransform(const gfx::Transform& transform) {
- for (size_t i = 0; i < points_.size(); i++) {
- transform.TransformPoint(&points_[i]);
- }
-}
-
-// TransformToScreenSpace assumes we're moving a layer from its layer space
-// into 3D screen space, which for sorting purposes requires the normal to
-// be transformed along with the vertices.
-void DrawPolygon::TransformToScreenSpace(const gfx::Transform& transform) {
- ApplyTransform(transform);
- transform.TransformVector(&normal_);
- ConstructNormal();
-}
-
-// In the case of TransformToLayerSpace, we assume that we are giving the
-// inverse transformation back to the polygon to move it back into layer space
-// but we can ignore the costly process of applying the inverse to the normal
-// since we know the normal will just reset to its original state.
-void DrawPolygon::TransformToLayerSpace(
- const gfx::Transform& inverse_transform) {
- ApplyTransform(inverse_transform);
- normal_ = gfx::Vector3dF(0.0f, 0.0f, -1.0f);
-}
-
-// Split |polygon| based upon |this|, leaving the results in |front| and |back|.
-// If |polygon| is not split by |this|, then move it to either |front| or |back|
-// depending on its orientation relative to |this|. Sets |is_coplanar| to true
-// if |polygon| is actually coplanar with |this| (in which case whether it is
-// front facing or back facing is determined by the dot products of normals, and
-// document order).
-void DrawPolygon::SplitPolygon(std::unique_ptr<DrawPolygon> polygon,
- std::unique_ptr<DrawPolygon>* front,
- std::unique_ptr<DrawPolygon>* back,
- bool* is_coplanar) const {
- DCHECK_GE(normalized_threshold, std::abs(normal_.LengthSquared() - 1.0f));
-
- const size_t num_points = polygon->points_.size();
- const auto next = [num_points](size_t i) { return (i + 1) % num_points; };
- const auto prev = [num_points](size_t i) {
- return (i + num_points - 1) % num_points;
- };
-
- std::vector<float> vertex_distance;
- size_t pos_count = 0;
- size_t neg_count = 0;
-
- // Compute plane distances for each vertex of polygon.
- vertex_distance.resize(num_points);
- for (size_t i = 0; i < num_points; i++) {
- vertex_distance[i] = SignedPointDistance(polygon->points_[i]);
- if (vertex_distance[i] < -split_threshold) {
- ++neg_count;
- } else if (vertex_distance[i] > split_threshold) {
- ++pos_count;
- } else {
- vertex_distance[i] = 0.0;
- }
- }
-
- // Handle non-splitting cases.
- if (!pos_count && !neg_count) {
- double dot = gfx::DotProduct(normal_, polygon->normal_);
- if ((dot >= 0.0f && polygon->order_index_ >= order_index_) ||
- (dot <= 0.0f && polygon->order_index_ <= order_index_)) {
- *back = std::move(polygon);
- } else {
- *front = std::move(polygon);
- }
- *is_coplanar = true;
- return;
- }
-
- *is_coplanar = false;
- if (!neg_count) {
- *front = std::move(polygon);
- return;
- } else if (!pos_count) {
- *back = std::move(polygon);
- return;
- }
-
- // Handle splitting case.
- size_t front_begin;
- size_t back_begin;
- size_t pre_front_begin;
- size_t pre_back_begin;
-
- // Find the first vertex that is part of the front split polygon.
- front_begin = std::find_if(vertex_distance.begin(), vertex_distance.end(),
- [](float val) { return val > 0.0; }) -
- vertex_distance.begin();
- while (vertex_distance[pre_front_begin = prev(front_begin)] > 0.0)
- front_begin = pre_front_begin;
-
- // Find the first vertex that is part of the back split polygon.
- back_begin = std::find_if(vertex_distance.begin(), vertex_distance.end(),
- [](float val) { return val < 0.0; }) -
- vertex_distance.begin();
- while (vertex_distance[pre_back_begin = prev(back_begin)] < 0.0)
- back_begin = pre_back_begin;
-
- DCHECK(vertex_distance[front_begin] > 0.0);
- DCHECK(vertex_distance[pre_front_begin] <= 0.0);
- DCHECK(vertex_distance[back_begin] < 0.0);
- DCHECK(vertex_distance[pre_back_begin] >= 0.0);
-
- gfx::Point3F pre_pos_intersection;
- gfx::Point3F pre_neg_intersection;
-
- // Compute the intersection points. N.B.: If the "pre" vertex is on
- // the thick plane, then the intersection will be at the same point, because
- // we set vertex_distance to 0 in this case.
- PointInterpolate(
- polygon->points_[pre_front_begin], polygon->points_[front_begin],
- -vertex_distance[pre_front_begin] /
- gfx::DotProduct(normal_, polygon->points_[front_begin] -
- polygon->points_[pre_front_begin]),
- &pre_pos_intersection);
- PointInterpolate(
- polygon->points_[pre_back_begin], polygon->points_[back_begin],
- -vertex_distance[pre_back_begin] /
- gfx::DotProduct(normal_, polygon->points_[back_begin] -
- polygon->points_[pre_back_begin]),
- &pre_neg_intersection);
-
- // Build the front and back polygons.
- std::vector<gfx::Point3F> out_points;
-
- out_points.push_back(pre_pos_intersection);
- for (size_t index = front_begin; index != back_begin; index = next(index)) {
- out_points.push_back(polygon->points_[index]);
- }
- if (out_points.back() != pre_neg_intersection) {
- out_points.push_back(pre_neg_intersection);
- }
- *front =
- std::make_unique<DrawPolygon>(polygon->original_ref_, out_points,
- polygon->normal_, polygon->order_index_);
-
- out_points.clear();
-
- out_points.push_back(pre_neg_intersection);
- for (size_t index = back_begin; index != front_begin; index = next(index)) {
- out_points.push_back(polygon->points_[index]);
- }
- if (out_points.back() != pre_pos_intersection) {
- out_points.push_back(pre_pos_intersection);
- }
- *back =
- std::make_unique<DrawPolygon>(polygon->original_ref_, out_points,
- polygon->normal_, polygon->order_index_);
-
- DCHECK_GE((*front)->points().size(), 3u);
- DCHECK_GE((*back)->points().size(), 3u);
-}
-
-// This algorithm takes the first vertex in the polygon and uses that as a
-// pivot point to fan out and create quads from the rest of the vertices.
-// |offset| starts off as the second vertex, and then |op1| and |op2| indicate
-// offset+1 and offset+2 respectively.
-// After the first quad is created, the first vertex in the next quad is the
-// same as all the rest, the pivot point. The second vertex in the next quad is
-// the old |op2|, the last vertex added to the previous quad. This continues
-// until all points are exhausted.
-// The special case here is where there are only 3 points remaining, in which
-// case we use the same values for vertex 3 and 4 to make a degenerate quad
-// that represents a triangle.
-void DrawPolygon::ToQuads2D(std::vector<gfx::QuadF>* quads) const {
- if (points_.size() <= 2)
- return;
-
- gfx::PointF first(points_[0].x(), points_[0].y());
- size_t offset = 1;
- while (offset < points_.size() - 1) {
- size_t op1 = offset + 1;
- size_t op2 = offset + 2;
- if (op2 >= points_.size()) {
- // It's going to be a degenerate triangle.
- op2 = op1;
- }
- quads->push_back(
- gfx::QuadF(first,
- gfx::PointF(points_[offset].x(), points_[offset].y()),
- gfx::PointF(points_[op1].x(), points_[op1].y()),
- gfx::PointF(points_[op2].x(), points_[op2].y())));
- offset = op2;
- }
-}
-
-} // namespace cc
diff --git a/chromium/cc/quads/draw_polygon.h b/chromium/cc/quads/draw_polygon.h
deleted file mode 100644
index 34625dc83c9..00000000000
--- a/chromium/cc/quads/draw_polygon.h
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_QUADS_DRAW_POLYGON_H_
-#define CC_QUADS_DRAW_POLYGON_H_
-
-#include <vector>
-
-#include "cc/base/math_util.h"
-#include "cc/cc_export.h"
-#include "ui/gfx/geometry/point3_f.h"
-#include "ui/gfx/geometry/quad_f.h"
-#include "ui/gfx/geometry/rect_f.h"
-#include "ui/gfx/geometry/vector3d_f.h"
-#include "ui/gfx/transform.h"
-
-namespace cc {
-
-class DrawQuad;
-
-class CC_EXPORT DrawPolygon {
- public:
- DrawPolygon();
- ~DrawPolygon();
-
- DrawPolygon(const DrawQuad* original_ref,
- const std::vector<gfx::Point3F>& in_points,
- const gfx::Vector3dF& normal,
- int draw_order_index = 0);
- DrawPolygon(const DrawQuad* original_ref,
- const gfx::RectF& visible_layer_rect,
- const gfx::Transform& transform,
- int draw_order_index = 0);
-
- // Split takes this DrawPolygon and splits it into two pieces that are on
- // either side of |splitter|. Any edges of this polygon that cross the plane
- // of |splitter| will have an intersection point that is shared by both
- // polygons on either side.
- // Split will only return true if it determines that we got back 2
- // intersection points. Only when it returns true will front and back both be
- // valid new polygons that are on opposite sides of the splitting plane.
- void SplitPolygon(std::unique_ptr<DrawPolygon> polygon,
- std::unique_ptr<DrawPolygon>* front,
- std::unique_ptr<DrawPolygon>* back,
- bool* is_coplanar) const;
- float SignedPointDistance(const gfx::Point3F& point) const;
- void ToQuads2D(std::vector<gfx::QuadF>* quads) const;
- void TransformToScreenSpace(const gfx::Transform& transform);
- void TransformToLayerSpace(const gfx::Transform& inverse_transform);
-
- const std::vector<gfx::Point3F>& points() const { return points_; }
- const gfx::Vector3dF& normal() const { return normal_; }
- const DrawQuad* original_ref() const { return original_ref_; }
- int order_index() const { return order_index_; }
- bool is_split() const { return is_split_; }
- std::unique_ptr<DrawPolygon> CreateCopy();
-
- // These are helper functions for testing.
- void RecomputeNormalForTesting();
- friend bool IsPlanarForTesting(const DrawPolygon& p);
- friend bool IsConvexForTesting(const DrawPolygon& p);
-
- private:
- void ApplyTransform(const gfx::Transform& transform);
- void ApplyTransformToNormal(const gfx::Transform& transform);
-
- void ConstructNormal();
-
- std::vector<gfx::Point3F> points_;
- // Normalized, necessitated by distance calculations and tests of coplanarity.
- gfx::Vector3dF normal_;
- // This is an index that can be used to test whether a quad comes before or
- // after another in document order, useful for tie-breaking when it comes
- // to coplanar surfaces.
- int order_index_;
- // The pointer to the original quad, which gives us all the drawing info
- // we need.
- // This DrawQuad is owned by the caller and its lifetime must be preserved
- // as long as this DrawPolygon is alive.
- const DrawQuad* original_ref_;
- bool is_split_;
-};
-
-} // namespace cc
-
-#endif // CC_QUADS_DRAW_POLYGON_H_
diff --git a/chromium/cc/quads/draw_polygon_unittest.cc b/chromium/cc/quads/draw_polygon_unittest.cc
deleted file mode 100644
index 870a867df84..00000000000
--- a/chromium/cc/quads/draw_polygon_unittest.cc
+++ /dev/null
@@ -1,630 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// We would like to use M_PI on windows too.
-#ifdef _WIN32
-#define _USE_MATH_DEFINES
-#endif
-
-#include <stddef.h>
-
-#include <limits>
-#include <vector>
-
-#include "base/memory/ptr_util.h"
-#include "base/stl_util.h"
-#include "cc/output/bsp_compare_result.h"
-#include "cc/quads/draw_polygon.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/transform.h"
-
-namespace cc {
-
-#if !defined(OS_WIN)
-void DrawPolygon::RecomputeNormalForTesting() {
- ConstructNormal();
-}
-#endif
-
-static int sign(float v) {
- static const float epsilon = 0.00001f;
-
- if (v > epsilon)
- return 1;
- if (v < -epsilon)
- return -1;
- return 0;
-}
-
-bool IsPlanarForTesting(const DrawPolygon& p) {
- static const float epsilon = 0.00001f;
- for (size_t i = 1; i < p.points_.size(); i++) {
- if (gfx::DotProduct(p.points_[i] - p.points_[0], p.normal_) > epsilon)
- return false;
- }
- return true;
-}
-
-bool IsConvexForTesting(const DrawPolygon& p) {
- if (p.points_.size() < 3)
- return true;
-
- gfx::Vector3dF prev =
- p.points_[p.points_.size() - 1] - p.points_[p.points_.size() - 2];
- gfx::Vector3dF next = p.points_[0] - p.points_[p.points_.size() - 1];
- int ccw = sign(gfx::DotProduct(CrossProduct(prev, next), p.normal_));
- for (size_t i = 1; i < p.points_.size(); i++) {
- prev = next;
- next = p.points_[i] - p.points_[i - 1];
- int next_sign = sign(gfx::DotProduct(CrossProduct(prev, next), p.normal_));
- if (ccw == 0)
- ccw = next_sign;
- if (next_sign != 0 && next_sign != ccw)
- return false;
- }
- return true;
-}
-
-namespace {
-
-#define CREATE_NEW_DRAW_POLYGON(name, points_vector, normal, polygon_id) \
- DrawPolygon name(NULL, points_vector, normal, polygon_id)
-
-#define CREATE_NEW_DRAW_POLYGON_PTR(name, points_vector, normal, polygon_id) \
- std::unique_ptr<DrawPolygon> name(std::make_unique<DrawPolygon>( \
- nullptr, points_vector, normal, polygon_id))
-
-#define CREATE_TEST_DRAW_FORWARD_POLYGON(name, points_vector, id) \
- DrawPolygon name(NULL, points_vector, gfx::Vector3dF(0, 0, 1.0f), id); \
- name.RecomputeNormalForTesting()
-
-#define CREATE_TEST_DRAW_REVERSE_POLYGON(name, points_vector, id) \
- DrawPolygon name(NULL, points_vector, gfx::Vector3dF(0, 0, -1.0f), id); \
- name.RecomputeNormalForTesting()
-
-#define EXPECT_FLOAT_WITHIN_EPSILON_OF(a, b) \
- LOG(WARNING) << "a=" << a << " b= " << b << " diff=" << std::abs(a - b); \
- EXPECT_TRUE(std::abs(a - b) < std::numeric_limits<float>::epsilon());
-
-#define EXPECT_POINT_EQ(point_a, point_b) \
- EXPECT_FLOAT_EQ(point_a.x(), point_b.x()); \
- EXPECT_FLOAT_EQ(point_a.y(), point_b.y()); \
- EXPECT_FLOAT_EQ(point_a.z(), point_b.z());
-
-#define EXPECT_NORMAL(poly, n_x, n_y, n_z) \
- EXPECT_FLOAT_WITHIN_EPSILON_OF(poly.normal().x(), n_x); \
- EXPECT_FLOAT_WITHIN_EPSILON_OF(poly.normal().y(), n_y); \
- EXPECT_FLOAT_WITHIN_EPSILON_OF(poly.normal().z(), n_z);
-
-static void ValidatePoints(const DrawPolygon& polygon,
- const std::vector<gfx::Point3F>& points) {
- EXPECT_EQ(polygon.points().size(), points.size());
- for (size_t i = 0; i < points.size(); i++) {
- EXPECT_POINT_EQ(polygon.points()[i], points[i]);
- }
-}
-
-static void ValidatePointsWithinDeltaOf(const DrawPolygon& polygon,
- const std::vector<gfx::Point3F>& points,
- float delta) {
- EXPECT_EQ(polygon.points().size(), points.size());
- for (size_t i = 0; i < points.size(); i++) {
- EXPECT_LE((polygon.points()[i] - points[i]).Length(), delta);
- }
-}
-
-// A simple square in a plane.
-TEST(DrawPolygonConstructionTest, NormalNormal) {
- gfx::Transform Identity;
- DrawPolygon polygon(NULL, gfx::RectF(10.0f, 10.0f), Identity, 1);
- EXPECT_NORMAL(polygon, 0.0f, 0.0f, 1.0f);
-}
-
-// More complicated shapes.
-TEST(DrawPolygonConstructionTest, TestNormal) {
- std::vector<gfx::Point3F> vertices;
- vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
- vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
- vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
- vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
-
- CREATE_TEST_DRAW_FORWARD_POLYGON(polygon, vertices, 1);
- EXPECT_NORMAL(polygon, 0.0f, 0.0f, 1.0f);
-}
-
-TEST(DrawPolygonConstructionTest, ClippedNormal) {
- std::vector<gfx::Point3F> vertices;
- vertices.push_back(gfx::Point3F(0.1f, 10.0f, 0.0f));
- vertices.push_back(gfx::Point3F(0.0f, 9.9f, 0.0f));
- vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
- vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
- vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
- vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
-
- CREATE_TEST_DRAW_FORWARD_POLYGON(polygon, vertices, 1);
- EXPECT_NORMAL(polygon, 0.0f, 0.0f, 1.0f);
-}
-
-TEST(DrawPolygonConstructionTest, SlimTriangleNormal) {
- std::vector<gfx::Point3F> vertices;
- vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
- vertices.push_back(gfx::Point3F(5000.0f, 0.0f, 0.0f));
- vertices.push_back(gfx::Point3F(10000.0f, 1.0f, 0.0f));
-
- CREATE_TEST_DRAW_FORWARD_POLYGON(polygon, vertices, 2);
- EXPECT_NORMAL(polygon, 0.0f, 0.0f, 1.0f);
-}
-
-TEST(DrawPolygonConstructionTest, ManyVertexNormal) {
- std::vector<gfx::Point3F> vertices_c;
- std::vector<gfx::Point3F> vertices_d;
- for (int i = 0; i < 100; i++) {
- vertices_c.push_back(
- gfx::Point3F(cos(i * M_PI / 50), sin(i * M_PI / 50), 0.0f));
- vertices_d.push_back(gfx::Point3F(cos(i * M_PI / 50) + 99.0f,
- sin(i * M_PI / 50) + 99.0f, 100.0f));
- }
- CREATE_TEST_DRAW_FORWARD_POLYGON(polygon_c, vertices_c, 3);
- EXPECT_NORMAL(polygon_c, 0.0f, 0.0f, 1.0f);
-
- CREATE_TEST_DRAW_FORWARD_POLYGON(polygon_d, vertices_d, 4);
- EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, 1.0f);
-}
-
-// A simple rect being transformed.
-TEST(DrawPolygonConstructionTest, SimpleNormal) {
- gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
-
- gfx::Transform transform_i(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
- DrawPolygon polygon_i(NULL, src, transform_i, 1);
-
- EXPECT_NORMAL(polygon_i, 0.0f, 0.0f, 1.0f);
-}
-
-TEST(DrawPolygonConstructionTest, DISABLED_NormalInvertXY) {
- gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
-
- gfx::Transform transform(0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
- DrawPolygon polygon_a(NULL, src, transform, 2);
-
- EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, 1.0f);
-}
-
-TEST(DrawPolygonConstructionTest, DISABLED_NormalInvertXZ) {
- gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
-
- gfx::Transform transform(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1);
- DrawPolygon polygon_b(NULL, src, transform, 3);
-
- EXPECT_NORMAL(polygon_b, 1.0f, 0.0f, 0.0f);
-}
-
-TEST(DrawPolygonConstructionTest, DISABLED_NormalInvertYZ) {
- gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
-
- gfx::Transform transform(1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1);
- DrawPolygon polygon_c(NULL, src, transform, 4);
-
- EXPECT_NORMAL(polygon_c, 0.0f, 1.0f, 0.0f);
-}
-
-TEST(DrawPolygonConstructionTest, NormalRotate90) {
- gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
-
- gfx::Transform transform(0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1);
- DrawPolygon polygon_b(NULL, src, transform, 3);
-
- EXPECT_NORMAL(polygon_b, 0.0f, 0.0f, 1.0f);
-}
-
-TEST(DrawPolygonConstructionTest, InvertXNormal) {
- gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
-
- gfx::Transform transform(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
- DrawPolygon polygon_d(NULL, src, transform, 5);
-
- EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, 1.0f);
-}
-
-TEST(DrawPolygonConstructionTest, InvertYNormal) {
- gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
-
- gfx::Transform transform(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
- DrawPolygon polygon_d(NULL, src, transform, 5);
-
- EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, 1.0f);
-}
-
-TEST(DrawPolygonConstructionTest, InvertZNormal) {
- gfx::RectF src(-0.1f, -10.0f, 0.2f, 20.0f);
-
- gfx::Transform transform(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1);
- DrawPolygon polygon_d(NULL, src, transform, 5);
-
- EXPECT_NORMAL(polygon_d, 0.0f, 0.0f, -1.0f);
-}
-
-// Two quads are nearly touching but definitely ordered. Second one should
-// compare in front.
-TEST(DrawPolygonSplitTest, NearlyTouchingOrder) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(0.0f, 10.0f, -1.0f));
- vertices_b.push_back(gfx::Point3F(0.0f, 0.0f, -1.0f));
- vertices_b.push_back(gfx::Point3F(10.0f, 0.0f, -1.0f));
- vertices_b.push_back(gfx::Point3F(10.0f, 10.0f, -1.0f));
- gfx::Vector3dF normal(0.0f, 0.0f, 1.0f);
-
- CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, normal, 0);
- CREATE_NEW_DRAW_POLYGON_PTR(polygon_b, vertices_b, normal, 1);
-
- std::unique_ptr<DrawPolygon> front;
- std::unique_ptr<DrawPolygon> back;
- bool is_coplanar;
- polygon_a.SplitPolygon(std::move(polygon_b), &front, &back, &is_coplanar);
- EXPECT_EQ(is_coplanar, false);
- EXPECT_EQ(front, nullptr);
- EXPECT_NE(back, nullptr);
-}
-
-// Two quads are definitely not touching and so no split should occur.
-TEST(DrawPolygonSplitTest, NotClearlyInFront) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(87.2f, 1185.0f, 0.9f));
- vertices_a.push_back(gfx::Point3F(288.3f, 1185.0f, -0.7f));
- vertices_a.push_back(gfx::Point3F(288.3f, 1196.0f, -0.7f));
- vertices_a.push_back(gfx::Point3F(87.2f, 1196.0f, 0.9f));
- gfx::Vector3dF normal_a = gfx::CrossProduct(vertices_a[1] - vertices_a[0],
- vertices_a[1] - vertices_a[2]);
- normal_a.Scale(1.0f / normal_a.Length());
-
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(62.1f, 1034.7f, 1.0f));
- vertices_b.push_back(gfx::Point3F(313.4f, 1035.3f, -1.0f));
- vertices_b.push_back(gfx::Point3F(313.4f, 1196.0f, -1.0f));
- vertices_b.push_back(gfx::Point3F(62.1f, 1196.0f, 1.0f));
- gfx::Vector3dF normal_b = gfx::CrossProduct(vertices_b[1] - vertices_b[0],
- vertices_b[1] - vertices_b[2]);
- normal_b.Scale(1.0f / normal_b.Length());
-
- CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, normal_a, 0);
- CREATE_NEW_DRAW_POLYGON_PTR(polygon_b, vertices_b, normal_b, 1);
-
- std::unique_ptr<DrawPolygon> front;
- std::unique_ptr<DrawPolygon> back;
- bool is_coplanar;
- polygon_a.SplitPolygon(std::move(polygon_b), &front, &back, &is_coplanar);
- EXPECT_EQ(is_coplanar, false);
- EXPECT_NE(front, nullptr);
- EXPECT_EQ(back, nullptr);
-}
-
-// Two quads are definitely not touching and so no split should occur.
-TEST(DrawPolygonSplitTest, NotTouchingNoSplit) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f));
- vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 15.0f));
- vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 15.0f));
- vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 5.0f));
-
- CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a,
- gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0);
- CREATE_NEW_DRAW_POLYGON_PTR(polygon_b, vertices_b,
- gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1);
-
- std::unique_ptr<DrawPolygon> front;
- std::unique_ptr<DrawPolygon> back;
- bool is_coplanar;
- polygon_a.SplitPolygon(std::move(polygon_b), &front, &back, &is_coplanar);
- EXPECT_EQ(is_coplanar, false);
- EXPECT_NE(front, nullptr);
- EXPECT_EQ(back, nullptr);
-}
-
-// One quad is resting against another, but doesn't cross its plane so no
-// split
-// should occur.
-TEST(DrawPolygonSplitTest, BarelyTouchingNoSplit) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f));
- vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, -10.0f));
- vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, -10.0f));
- vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 0.0f));
-
- CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a,
- gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0);
- CREATE_NEW_DRAW_POLYGON_PTR(polygon_b, vertices_b,
- gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1);
-
- std::unique_ptr<DrawPolygon> front;
- std::unique_ptr<DrawPolygon> back;
- bool is_coplanar;
- polygon_a.SplitPolygon(std::move(polygon_b), &front, &back, &is_coplanar);
- EXPECT_EQ(is_coplanar, false);
- EXPECT_EQ(front, nullptr);
- EXPECT_NE(back, nullptr);
-}
-
-// One quad intersects a pent with an occluded side.
-TEST(DrawPolygonSplitTest, SlimClip) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(9.0f, 9.0f, 5.000f));
- vertices_b.push_back(gfx::Point3F(1.0f, 1.0f, 0.001f));
- vertices_b.push_back(gfx::Point3F(1.0f, 1.0f, 0.000f));
- vertices_b.push_back(gfx::Point3F(1.002f, 1.002f, -0.005f));
- vertices_b.push_back(gfx::Point3F(9.0f, 9.0f, -4.000f));
-
- CREATE_NEW_DRAW_POLYGON_PTR(polygon_a, vertices_a,
- gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0);
- CREATE_NEW_DRAW_POLYGON_PTR(
- polygon_b, vertices_b,
- gfx::Vector3dF(sqrt(2) / 2, -sqrt(2) / 2, 0.000000), 1);
-
- // These are well formed, convex polygons.
- EXPECT_TRUE(IsPlanarForTesting(*polygon_a));
- EXPECT_TRUE(IsConvexForTesting(*polygon_a));
- EXPECT_TRUE(IsPlanarForTesting(*polygon_b));
- EXPECT_TRUE(IsConvexForTesting(*polygon_b));
-
- std::unique_ptr<DrawPolygon> front_polygon;
- std::unique_ptr<DrawPolygon> back_polygon;
- bool is_coplanar;
-
- polygon_a->SplitPolygon(std::move(polygon_b), &front_polygon, &back_polygon,
- &is_coplanar);
-
- EXPECT_FALSE(is_coplanar);
- EXPECT_TRUE(front_polygon != nullptr);
- EXPECT_TRUE(back_polygon != nullptr);
-}
-
-// One quad intersects another and becomes two pieces.
-TEST(DrawPolygonSplitTest, BasicSplit) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, -5.0f));
- vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, -5.0f));
- vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 5.0f));
- vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f));
-
- CREATE_NEW_DRAW_POLYGON_PTR(polygon_a, vertices_a,
- gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0);
- CREATE_NEW_DRAW_POLYGON_PTR(polygon_b, vertices_b,
- gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1);
-
- std::unique_ptr<DrawPolygon> front_polygon;
- std::unique_ptr<DrawPolygon> back_polygon;
- bool is_coplanar;
-
- polygon_a->SplitPolygon(std::move(polygon_b), &front_polygon, &back_polygon,
- &is_coplanar);
- EXPECT_FALSE(is_coplanar);
- EXPECT_TRUE(front_polygon != nullptr);
- EXPECT_TRUE(back_polygon != nullptr);
-
- std::vector<gfx::Point3F> test_points_a;
- test_points_a.push_back(gfx::Point3F(5.0f, 0.0f, 0.0f));
- test_points_a.push_back(gfx::Point3F(5.0f, 0.0f, 5.0f));
- test_points_a.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f));
- test_points_a.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f));
- std::vector<gfx::Point3F> test_points_b;
- test_points_b.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f));
- test_points_b.push_back(gfx::Point3F(5.0f, 10.0f, -5.0f));
- test_points_b.push_back(gfx::Point3F(5.0f, 0.0f, -5.0f));
- test_points_b.push_back(gfx::Point3F(5.0f, 0.0f, 0.0f));
- ValidatePoints(*front_polygon, test_points_a);
- ValidatePoints(*back_polygon, test_points_b);
-
- EXPECT_EQ(4u, front_polygon->points().size());
- EXPECT_EQ(4u, back_polygon->points().size());
-}
-
-// In this test we cut the corner of a quad so that it creates a triangle and
-// a pentagon as a result.
-TEST(DrawPolygonSplitTest, AngledSplit) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 10.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 10.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(2.0f, 5.0f, 1.0f));
- vertices_b.push_back(gfx::Point3F(2.0f, -5.0f, 1.0f));
- vertices_b.push_back(gfx::Point3F(-1.0f, -5.0f, -2.0f));
- vertices_b.push_back(gfx::Point3F(-1.0f, 5.0f, -2.0f));
-
- CREATE_NEW_DRAW_POLYGON_PTR(polygon_a, vertices_a,
- gfx::Vector3dF(0.0f, 1.0f, 0.0f), 0);
- CREATE_NEW_DRAW_POLYGON_PTR(polygon_b, vertices_b,
- gfx::Vector3dF(0.707107f, 0.0f, -0.707107f), 1);
-
- std::unique_ptr<DrawPolygon> front_polygon;
- std::unique_ptr<DrawPolygon> back_polygon;
- bool is_coplanar;
-
- polygon_b->SplitPolygon(std::move(polygon_a), &front_polygon, &back_polygon,
- &is_coplanar);
- EXPECT_FALSE(is_coplanar);
- EXPECT_TRUE(front_polygon != nullptr);
- EXPECT_TRUE(back_polygon != nullptr);
-
- std::vector<gfx::Point3F> test_points_a;
- test_points_a.push_back(gfx::Point3F(10.0f, 0.0f, 9.0f));
- test_points_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
- test_points_a.push_back(gfx::Point3F(1.0f, 0.0f, 0.0f));
- std::vector<gfx::Point3F> test_points_b;
- test_points_b.push_back(gfx::Point3F(1.0f, 0.0f, 0.0f));
- test_points_b.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
- test_points_b.push_back(gfx::Point3F(0.0f, 0.0f, 10.0f));
- test_points_b.push_back(gfx::Point3F(10.0f, 0.0f, 10.0f));
- test_points_b.push_back(gfx::Point3F(10.0f, 0.0f, 9.0f));
-
- ValidatePointsWithinDeltaOf(*front_polygon, test_points_a, 1e-6f);
- ValidatePointsWithinDeltaOf(*back_polygon, test_points_b, 1e-6f);
-}
-
-// This test was derived from crbug.com/693826. An almost coplanar
-// pair of polygons are used for splitting. In this case, the
-// splitting plane distance signs are [ 0 0 + - ]. This configuration
-// represents a case where snapping to the splitting plane causes the
-// polygon to become twisted. Splitting should still give a valid
-// result, indicated by all four of the input split polygon vertices
-// being present in the output polygons.
-TEST(DrawPolygonSplitTest, AlmostCoplanarSplit) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(723.814758300781250f, 552.810119628906250f,
- -206.656036376953125f));
- vertices_a.push_back(gfx::Point3F(797.634155273437500f, 549.095703125000000f,
- -209.802902221679688f));
- vertices_a.push_back(gfx::Point3F(799.264648437500000f, 490.325805664062500f,
- -172.261627197265625f));
- vertices_a.push_back(gfx::Point3F(720.732421875000000f, 493.944458007812500f,
- -168.700469970703125f));
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(720.631286621093750f, 487.595977783203125f,
- -164.681198120117188f));
- vertices_b.push_back(gfx::Point3F(799.672851562500000f, 484.059020996093750f,
- -168.219161987304688f));
- vertices_b.push_back(gfx::Point3F(801.565490722656250f, 416.416809082031250f,
- -125.007690429687500f));
- vertices_b.push_back(gfx::Point3F(717.096801757812500f, 419.792327880859375f,
- -120.967689514160156f));
-
- CREATE_NEW_DRAW_POLYGON_PTR(
- splitting_polygon, vertices_a,
- gfx::Vector3dF(-0.062916249036789f, -0.538499474525452f,
- -0.840273618698120f),
- 0);
- CREATE_NEW_DRAW_POLYGON_PTR(
- split_polygon, vertices_b,
- gfx::Vector3dF(-0.061713f, -0.538550f, -0.840330f), 1);
-
- std::unique_ptr<DrawPolygon> front_polygon;
- std::unique_ptr<DrawPolygon> back_polygon;
- bool is_coplanar;
-
- splitting_polygon->SplitPolygon(std::move(split_polygon), &front_polygon,
- &back_polygon, &is_coplanar);
-
- EXPECT_FALSE(is_coplanar);
- EXPECT_TRUE(front_polygon != nullptr);
- EXPECT_TRUE(back_polygon != nullptr);
-
- for (auto vertex : vertices_b) {
- EXPECT_TRUE(base::ContainsValue(front_polygon->points(), vertex) ||
- base::ContainsValue(back_polygon->points(), vertex));
- }
-}
-
-// In this test we cut the corner of a quad so that it creates a triangle and
-// a pentagon as a result, and then cut the pentagon.
-TEST(DrawPolygonSplitTest, DoubleSplit) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
- vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 10.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 10.0f));
- vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
- std::vector<gfx::Point3F> vertices_b;
- vertices_b.push_back(gfx::Point3F(2.0f, 5.0f, 1.0f));
- vertices_b.push_back(gfx::Point3F(2.0f, -5.0f, 1.0f));
- vertices_b.push_back(gfx::Point3F(-1.0f, -5.0f, -2.0f));
- vertices_b.push_back(gfx::Point3F(-1.0f, 5.0f, -2.0f));
-
- CREATE_NEW_DRAW_POLYGON_PTR(polygon_a, vertices_a,
- gfx::Vector3dF(0.0f, 1.0f, 0.0f), 0);
- CREATE_NEW_DRAW_POLYGON_PTR(polygon_b, vertices_b,
- gfx::Vector3dF(sqrt(2) / 2, 0.0f, -sqrt(2) / 2),
- 1);
-
- std::unique_ptr<DrawPolygon> front_polygon;
- std::unique_ptr<DrawPolygon> back_polygon;
- bool is_coplanar;
-
- polygon_b->SplitPolygon(std::move(polygon_a), &front_polygon, &back_polygon,
- &is_coplanar);
- EXPECT_FALSE(is_coplanar);
- EXPECT_TRUE(front_polygon != nullptr);
- EXPECT_TRUE(back_polygon != nullptr);
-
- EXPECT_EQ(3u, front_polygon->points().size());
- EXPECT_EQ(5u, back_polygon->points().size());
- std::vector<gfx::Point3F> saved_back_polygon_vertices =
- back_polygon->points();
-
- std::vector<gfx::Point3F> vertices_c;
- vertices_c.push_back(gfx::Point3F(0.0f, 0.0f, 10.0f));
- vertices_c.push_back(gfx::Point3F(1.0f, -0.05f, 0.0f));
- vertices_c.push_back(gfx::Point3F(10.0f, 0.05f, 9.0f));
-
- CREATE_NEW_DRAW_POLYGON_PTR(polygon_c, vertices_c,
- gfx::Vector3dF(0.005555f, -0.99997f, 0.005555f),
- 0);
- polygon_c->RecomputeNormalForTesting();
-
- std::unique_ptr<DrawPolygon> second_front_polygon;
- std::unique_ptr<DrawPolygon> second_back_polygon;
-
- polygon_c->SplitPolygon(std::move(back_polygon), &second_front_polygon,
- &second_back_polygon, &is_coplanar);
- EXPECT_FALSE(is_coplanar);
- EXPECT_TRUE(second_front_polygon != nullptr);
- EXPECT_TRUE(second_back_polygon != nullptr);
-
- EXPECT_EQ(4u, second_front_polygon->points().size());
- EXPECT_EQ(3u, second_back_polygon->points().size());
-
- for (auto vertex : saved_back_polygon_vertices) {
- EXPECT_TRUE(base::ContainsValue(second_front_polygon->points(), vertex) ||
- base::ContainsValue(second_back_polygon->points(), vertex));
- }
-}
-
-TEST(DrawPolygonTransformTest, TransformNormal) {
- std::vector<gfx::Point3F> vertices_a;
- vertices_a.push_back(gfx::Point3F(1.0f, 0.0f, 1.0f));
- vertices_a.push_back(gfx::Point3F(-1.0f, 0.0f, -1.0f));
- vertices_a.push_back(gfx::Point3F(0.0f, 1.0f, 0.0f));
- CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a,
- gfx::Vector3dF(sqrt(2) / 2, 0.0f, -sqrt(2) / 2), 0);
- EXPECT_NORMAL(polygon_a, sqrt(2) / 2, 0.0f, -sqrt(2) / 2);
-
- gfx::Transform transform;
- transform.RotateAboutYAxis(45.0f);
- // This would transform the vertices as well, but we are transforming a
- // DrawPolygon with 0 vertices just to make sure our normal transformation
- // using the inverse tranpose matrix gives us the right result.
- polygon_a.TransformToScreenSpace(transform);
-
- // Note: We use EXPECT_FLOAT_WITHIN_EPSILON instead of EXPECT_FLOAT_EQUAL here
- // because some architectures (e.g., Arm64) employ a fused multiply-add
- // instruction which causes rounding asymmetry and reduces precision.
- // http://crbug.com/401117.
- EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, -1.0f);
-}
-
-} // namespace
-} // namespace cc
diff --git a/chromium/cc/quads/draw_quad.cc b/chromium/cc/quads/draw_quad.cc
deleted file mode 100644
index 560f27f773c..00000000000
--- a/chromium/cc/quads/draw_quad.cc
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/draw_quad.h"
-
-#include <stddef.h>
-
-#include "base/logging.h"
-#include "base/trace_event/trace_event_argument.h"
-#include "base/values.h"
-#include "cc/base/math_util.h"
-#include "components/viz/common/traced_value.h"
-#include "ui/gfx/geometry/quad_f.h"
-
-namespace cc {
-
-DrawQuad::DrawQuad()
- : material(INVALID), needs_blending(false), shared_quad_state(0) {
-}
-
-DrawQuad::DrawQuad(const DrawQuad& other) = default;
-
-void DrawQuad::SetAll(const viz::SharedQuadState* shared_quad_state,
- Material material,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending) {
- DCHECK(rect.Contains(visible_rect)) << "rect: " << rect.ToString()
- << " visible_rect: "
- << visible_rect.ToString();
-
- this->material = material;
- this->rect = rect;
- this->visible_rect = visible_rect;
- this->needs_blending = needs_blending;
- this->shared_quad_state = shared_quad_state;
-
- DCHECK(shared_quad_state);
- DCHECK(material != INVALID);
-}
-
-DrawQuad::~DrawQuad() {
-}
-
-void DrawQuad::AsValueInto(base::trace_event::TracedValue* value) const {
- value->SetInteger("material", material);
- viz::TracedValue::SetIDRef(shared_quad_state, value, "shared_state");
-
- MathUtil::AddToTracedValue("content_space_rect", rect, value);
-
- bool rect_is_clipped;
- gfx::QuadF rect_as_target_space_quad =
- MathUtil::MapQuad(shared_quad_state->quad_to_target_transform,
- gfx::QuadF(gfx::RectF(rect)), &rect_is_clipped);
- MathUtil::AddToTracedValue("rect_as_target_space_quad",
- rect_as_target_space_quad, value);
-
- value->SetBoolean("rect_is_clipped", rect_is_clipped);
-
- MathUtil::AddToTracedValue("content_space_visible_rect", visible_rect, value);
-
- bool visible_rect_is_clipped;
- gfx::QuadF visible_rect_as_target_space_quad = MathUtil::MapQuad(
- shared_quad_state->quad_to_target_transform,
- gfx::QuadF(gfx::RectF(visible_rect)), &visible_rect_is_clipped);
-
- MathUtil::AddToTracedValue("visible_rect_as_target_space_quad",
- visible_rect_as_target_space_quad, value);
-
- value->SetBoolean("visible_rect_is_clipped", visible_rect_is_clipped);
-
- value->SetBoolean("needs_blending", needs_blending);
- value->SetBoolean("should_draw_with_blending", ShouldDrawWithBlending());
- ExtendValue(value);
-}
-
-DrawQuad::Resources::Resources() : count(0) {
- for (size_t i = 0; i < kMaxResourceIdCount; ++i)
- ids[i] = 0;
-}
-
-} // namespace cc
diff --git a/chromium/cc/quads/draw_quad.h b/chromium/cc/quads/draw_quad.h
deleted file mode 100644
index 81b956e9f98..00000000000
--- a/chromium/cc/quads/draw_quad.h
+++ /dev/null
@@ -1,142 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_QUADS_DRAW_QUAD_H_
-#define CC_QUADS_DRAW_QUAD_H_
-
-#include <stddef.h>
-
-#include "base/callback.h"
-#include "cc/cc_export.h"
-#include "components/viz/common/quads/shared_quad_state.h"
-#include "components/viz/common/resources/resource_id.h"
-
-namespace base {
-namespace trace_event {
-class TracedValue;
-}
-}
-
-namespace cc {
-
-// DrawQuad is a bag of data used for drawing a quad. Because different
-// materials need different bits of per-quad data to render, classes that derive
-// from DrawQuad store additional data in their derived instance. The Material
-// enum is used to "safely" downcast to the derived class.
-// Note: quads contain rects and sizes, which live in different spaces. There is
-// the "content space", which is the arbitrary space in which the quad's
-// geometry is defined (generally related to the layer that produced the quad,
-// e.g. the geometry space for PictureLayerImpls or the layer's coordinate space
-// for most other layers). There is also the "target space", which is the space,
-// in "physical" pixels, of the render target where the quads is drawn. The
-// quad's transform maps the content space to the target space.
-class CC_EXPORT DrawQuad {
- public:
- enum Material {
- INVALID,
- DEBUG_BORDER,
- PICTURE_CONTENT,
- RENDER_PASS,
- SOLID_COLOR,
- STREAM_VIDEO_CONTENT,
- SURFACE_CONTENT,
- TEXTURE_CONTENT,
- TILED_CONTENT,
- YUV_VIDEO_CONTENT,
- MATERIAL_LAST = YUV_VIDEO_CONTENT
- };
-
- DrawQuad(const DrawQuad& other);
- virtual ~DrawQuad();
-
- Material material;
-
- // This rect, after applying the quad_transform(), gives the geometry that
- // this quad should draw to. This rect lives in content space.
- gfx::Rect rect;
-
- // Allows changing the rect that gets drawn to make it smaller. This value
- // should be clipped to |rect|. This rect lives in content space.
- gfx::Rect visible_rect;
-
- // By default blending is used when some part of the quad is not opaque.
- // With this setting, it is possible to force blending on regardless of the
- // opaque area.
- bool needs_blending;
-
- // Stores state common to a large bundle of quads; kept separate for memory
- // efficiency. There is special treatment to reconstruct these pointers
- // during serialization.
- const viz::SharedQuadState* shared_quad_state;
-
- bool IsDebugQuad() const { return material == DEBUG_BORDER; }
-
- bool ShouldDrawWithBlending() const {
- return needs_blending || shared_quad_state->opacity < 1.0f;
- }
-
- // Is the left edge of this tile aligned with the originating layer's
- // left edge?
- bool IsLeftEdge() const { return !rect.x(); }
-
- // Is the top edge of this tile aligned with the originating layer's
- // top edge?
- bool IsTopEdge() const { return !rect.y(); }
-
- // Is the right edge of this tile aligned with the originating layer's
- // right edge?
- bool IsRightEdge() const {
- return rect.right() == shared_quad_state->quad_layer_rect.right();
- }
-
- // Is the bottom edge of this tile aligned with the originating layer's
- // bottom edge?
- bool IsBottomEdge() const {
- return rect.bottom() == shared_quad_state->quad_layer_rect.bottom();
- }
-
- // Is any edge of this tile aligned with the originating layer's
- // corresponding edge?
- bool IsEdge() const {
- return IsLeftEdge() || IsTopEdge() || IsRightEdge() || IsBottomEdge();
- }
-
- void AsValueInto(base::trace_event::TracedValue* value) const;
-
- struct CC_EXPORT Resources {
- enum : size_t { kMaxResourceIdCount = 4 };
- Resources();
-
- viz::ResourceId* begin() { return ids; }
- viz::ResourceId* end() {
- DCHECK_LE(count, kMaxResourceIdCount);
- return ids + count;
- }
-
- const viz::ResourceId* begin() const { return ids; }
- const viz::ResourceId* end() const {
- DCHECK_LE(count, kMaxResourceIdCount);
- return ids + count;
- }
-
- uint32_t count;
- viz::ResourceId ids[kMaxResourceIdCount];
- };
-
- Resources resources;
-
- protected:
- DrawQuad();
-
- void SetAll(const viz::SharedQuadState* shared_quad_state,
- Material material,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending);
- virtual void ExtendValue(base::trace_event::TracedValue* value) const = 0;
-};
-
-} // namespace cc
-
-#endif // CC_QUADS_DRAW_QUAD_H_
diff --git a/chromium/cc/quads/draw_quad_perftest.cc b/chromium/cc/quads/draw_quad_perftest.cc
deleted file mode 100644
index b10b75e2f16..00000000000
--- a/chromium/cc/quads/draw_quad_perftest.cc
+++ /dev/null
@@ -1,114 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <vector>
-
-#include "base/bind.h"
-#include "base/time/time.h"
-#include "cc/base/lap_timer.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/render_pass.h"
-#include "cc/quads/texture_draw_quad.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "testing/perf/perf_test.h"
-
-namespace cc {
-namespace {
-
-static const int kTimeLimitMillis = 2000;
-static const int kWarmupRuns = 5;
-static const int kTimeCheckInterval = 10;
-
-viz::SharedQuadState* CreateSharedQuadState(RenderPass* render_pass) {
- gfx::Transform quad_transform = gfx::Transform(1.0, 0.0, 0.5, 1.0, 0.5, 0.0);
- gfx::Rect content_rect(26, 28);
- gfx::Rect visible_layer_rect(10, 12, 14, 16);
- gfx::Rect clip_rect(19, 21, 23, 25);
- bool is_clipped = false;
- float opacity = 1.f;
- int sorting_context_id = 65536;
- SkBlendMode blend_mode = SkBlendMode::kSrcOver;
-
- viz::SharedQuadState* state = render_pass->CreateAndAppendSharedQuadState();
- state->SetAll(quad_transform, content_rect, visible_layer_rect, clip_rect,
- is_clipped, opacity, blend_mode, sorting_context_id);
- return state;
-}
-
-class DrawQuadPerfTest : public testing::Test {
- public:
- DrawQuadPerfTest()
- : timer_(kWarmupRuns,
- base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
- kTimeCheckInterval) {}
-
- void CreateRenderPass() {
- render_pass_ = RenderPass::Create();
- viz::SharedQuadState* new_shared_state(
- CreateSharedQuadState(render_pass_.get()));
- shared_state_ = render_pass_->CreateAndAppendSharedQuadState();
- *shared_state_ = *new_shared_state;
- }
-
- void CleanUpRenderPass() {
- render_pass_.reset();
- shared_state_ = nullptr;
- }
-
- void GenerateTextureDrawQuads(int count, std::vector<DrawQuad*>* quads) {
- for (int i = 0; i < count; ++i) {
- TextureDrawQuad* quad =
- render_pass_->CreateAndAppendDrawQuad<TextureDrawQuad>();
- gfx::Rect rect(0, 0, 100, 100);
- bool needs_blending = false;
- viz::ResourceId resource_id = 1;
- bool premultiplied_alpha = true;
- gfx::PointF uv_top_left(0, 0);
- gfx::PointF uv_bottom_right(1, 1);
- SkColor background_color = SK_ColorRED;
- float vertex_opacity[4] = {1.f, 1.f, 1.f, 1.f};
- bool y_flipped = false;
- bool nearest_neighbor = true;
-
- quad->SetNew(shared_state_, rect, rect, needs_blending, resource_id,
- premultiplied_alpha, uv_top_left, uv_bottom_right,
- background_color, vertex_opacity, y_flipped,
- nearest_neighbor, false);
- quads->push_back(quad);
- }
- }
-
- void RunIterateResourceTest(const std::string& test_name, int quad_count) {
- CreateRenderPass();
- std::vector<DrawQuad*> quads;
- GenerateTextureDrawQuads(quad_count, &quads);
-
- timer_.Reset();
- do {
- for (auto* quad : quads) {
- for (viz::ResourceId& resource_id : quad->resources)
- ++resource_id;
- }
- timer_.NextLap();
- } while (!timer_.HasTimeLimitExpired());
-
- perf_test::PrintResult("draw_quad_iterate_resources", "", test_name,
- timer_.LapsPerSecond(), "runs/s", true);
- CleanUpRenderPass();
- }
-
- private:
- std::unique_ptr<RenderPass> render_pass_;
- viz::SharedQuadState* shared_state_;
- LapTimer timer_;
-};
-
-TEST_F(DrawQuadPerfTest, IterateResources) {
- RunIterateResourceTest("10_quads", 10);
- RunIterateResourceTest("100_quads", 100);
- RunIterateResourceTest("500_quads", 500);
-}
-
-} // namespace
-} // namespace cc
diff --git a/chromium/cc/quads/draw_quad_unittest.cc b/chromium/cc/quads/draw_quad_unittest.cc
deleted file mode 100644
index dbc820d85e1..00000000000
--- a/chromium/cc/quads/draw_quad_unittest.cc
+++ /dev/null
@@ -1,732 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/draw_quad.h"
-
-#include <stddef.h>
-
-#include <algorithm>
-
-#include "base/bind.h"
-#include "base/compiler_specific.h"
-#include "cc/base/filter_operations.h"
-#include "cc/base/math_util.h"
-#include "cc/quads/debug_border_draw_quad.h"
-#include "cc/quads/largest_draw_quad.h"
-#include "cc/quads/picture_draw_quad.h"
-#include "cc/quads/render_pass.h"
-#include "cc/quads/render_pass_draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/stream_video_draw_quad.h"
-#include "cc/quads/surface_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
-#include "cc/quads/tile_draw_quad.h"
-#include "cc/quads/yuv_video_draw_quad.h"
-#include "cc/test/fake_raster_source.h"
-#include "cc/test/geometry_test_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/skia/include/effects/SkBlurImageFilter.h"
-#include "ui/gfx/transform.h"
-
-namespace cc {
-namespace {
-
-static constexpr viz::FrameSinkId kArbitraryFrameSinkId(1, 1);
-
-TEST(DrawQuadTest, CopySharedQuadState) {
- gfx::Transform quad_transform = gfx::Transform(1.0, 0.0, 0.5, 1.0, 0.5, 0.0);
- gfx::Rect layer_rect(26, 28);
- gfx::Rect visible_layer_rect(10, 12, 14, 16);
- gfx::Rect clip_rect(19, 21, 23, 25);
- bool is_clipped = true;
- float opacity = 0.25f;
- SkBlendMode blend_mode = SkBlendMode::kMultiply;
- int sorting_context_id = 65536;
-
- auto state = std::make_unique<viz::SharedQuadState>();
- state->SetAll(quad_transform, layer_rect, visible_layer_rect, clip_rect,
- is_clipped, opacity, blend_mode, sorting_context_id);
-
- auto copy = std::make_unique<viz::SharedQuadState>(*state);
- EXPECT_EQ(quad_transform, copy->quad_to_target_transform);
- EXPECT_EQ(visible_layer_rect, copy->visible_quad_layer_rect);
- EXPECT_EQ(opacity, copy->opacity);
- EXPECT_EQ(clip_rect, copy->clip_rect);
- EXPECT_EQ(is_clipped, copy->is_clipped);
- EXPECT_EQ(blend_mode, copy->blend_mode);
-}
-
-viz::SharedQuadState* CreateSharedQuadState(RenderPass* render_pass) {
- gfx::Transform quad_transform = gfx::Transform(1.0, 0.0, 0.5, 1.0, 0.5, 0.0);
- gfx::Rect layer_rect(26, 28);
- gfx::Rect visible_layer_rect(10, 12, 14, 16);
- gfx::Rect clip_rect(19, 21, 23, 25);
- bool is_clipped = false;
- float opacity = 1.f;
- int sorting_context_id = 65536;
- SkBlendMode blend_mode = SkBlendMode::kSrcOver;
-
- viz::SharedQuadState* state = render_pass->CreateAndAppendSharedQuadState();
- state->SetAll(quad_transform, layer_rect, visible_layer_rect, clip_rect,
- is_clipped, opacity, blend_mode, sorting_context_id);
- return state;
-}
-
-void CompareSharedQuadState(const viz::SharedQuadState* source_sqs,
- const viz::SharedQuadState* copy_sqs) {
- EXPECT_EQ(source_sqs->quad_to_target_transform,
- copy_sqs->quad_to_target_transform);
- EXPECT_EQ(source_sqs->quad_layer_rect, copy_sqs->quad_layer_rect);
- EXPECT_EQ(source_sqs->visible_quad_layer_rect,
- copy_sqs->visible_quad_layer_rect);
- EXPECT_EQ(source_sqs->clip_rect, copy_sqs->clip_rect);
- EXPECT_EQ(source_sqs->is_clipped, copy_sqs->is_clipped);
- EXPECT_EQ(source_sqs->opacity, copy_sqs->opacity);
- EXPECT_EQ(source_sqs->blend_mode, copy_sqs->blend_mode);
- EXPECT_EQ(source_sqs->sorting_context_id, copy_sqs->sorting_context_id);
-}
-
-void CompareDrawQuad(DrawQuad* quad, DrawQuad* copy) {
- EXPECT_EQ(quad->material, copy->material);
- EXPECT_EQ(quad->rect, copy->rect);
- EXPECT_EQ(quad->visible_rect, copy->visible_rect);
- EXPECT_EQ(quad->needs_blending, copy->needs_blending);
- CompareSharedQuadState(quad->shared_quad_state, copy->shared_quad_state);
-}
-
-#define CREATE_SHARED_STATE() \
- std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); \
- viz::SharedQuadState* shared_state( \
- CreateSharedQuadState(render_pass.get())); \
- viz::SharedQuadState* copy_shared_state = \
- render_pass->CreateAndAppendSharedQuadState(); \
- *copy_shared_state = *shared_state;
-
-#define QUAD_DATA \
- gfx::Rect quad_rect(30, 40, 50, 60); \
- gfx::Rect quad_visible_rect(40, 50, 30, 20); \
- bool needs_blending = true; \
- ALLOW_UNUSED_LOCAL(needs_blending);
-
-#define SETUP_AND_COPY_QUAD_NEW(Type, quad) \
- DrawQuad* copy_new = render_pass->CopyFromAndAppendDrawQuad(quad_new); \
- CompareDrawQuad(quad_new, copy_new); \
- const Type* copy_quad = Type::MaterialCast(copy_new); \
- ALLOW_UNUSED_LOCAL(copy_quad);
-
-#define SETUP_AND_COPY_QUAD_ALL(Type, quad) \
- DrawQuad* copy_all = render_pass->CopyFromAndAppendDrawQuad(quad_all); \
- CompareDrawQuad(quad_all, copy_all); \
- copy_quad = Type::MaterialCast(copy_all);
-
-#define SETUP_AND_COPY_QUAD_NEW_RP(Type, quad, a) \
- DrawQuad* copy_new = \
- render_pass->CopyFromAndAppendRenderPassDrawQuad(quad_new, a); \
- CompareDrawQuad(quad_new, copy_new); \
- const Type* copy_quad = Type::MaterialCast(copy_new); \
- ALLOW_UNUSED_LOCAL(copy_quad);
-
-#define SETUP_AND_COPY_QUAD_ALL_RP(Type, quad, a) \
- DrawQuad* copy_all = \
- render_pass->CopyFromAndAppendRenderPassDrawQuad(quad_all, a); \
- CompareDrawQuad(quad_all, copy_all); \
- copy_quad = Type::MaterialCast(copy_all);
-
-#define CREATE_QUAD_ALL(Type, ...) \
- Type* quad_all = render_pass->CreateAndAppendDrawQuad<Type>(); \
- { \
- QUAD_DATA quad_all->SetAll(shared_state, quad_rect, quad_visible_rect, \
- needs_blending, __VA_ARGS__); \
- } \
- SETUP_AND_COPY_QUAD_ALL(Type, quad_all);
-
-#define CREATE_QUAD_NEW(Type, ...) \
- Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \
- { QUAD_DATA quad_new->SetNew(shared_state, quad_rect, __VA_ARGS__); } \
- SETUP_AND_COPY_QUAD_NEW(Type, quad_new);
-
-#define CREATE_QUAD_ALL_RP(Type, a, b, c, d, e, f, g, copy_a) \
- Type* quad_all = render_pass->CreateAndAppendDrawQuad<Type>(); \
- { \
- QUAD_DATA quad_all->SetAll(shared_state, quad_rect, quad_visible_rect, \
- needs_blending, a, b, c, d, e, f, g); \
- } \
- SETUP_AND_COPY_QUAD_ALL_RP(Type, quad_all, copy_a);
-
-#define CREATE_QUAD_NEW_RP(Type, a, b, c, d, e, f, g, h, copy_a) \
- Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \
- { \
- QUAD_DATA quad_new->SetNew(shared_state, quad_rect, a, b, c, d, e, f, g, \
- h); \
- } \
- SETUP_AND_COPY_QUAD_NEW_RP(Type, quad_new, copy_a);
-
-TEST(DrawQuadTest, CopyDebugBorderDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- SkColor color = 0xfabb0011;
- int width = 99;
- CREATE_SHARED_STATE();
-
- CREATE_QUAD_NEW(DebugBorderDrawQuad, visible_rect, color, width);
- EXPECT_EQ(DrawQuad::DEBUG_BORDER, copy_quad->material);
- EXPECT_EQ(visible_rect, copy_quad->visible_rect);
- EXPECT_EQ(color, copy_quad->color);
- EXPECT_EQ(width, copy_quad->width);
-
- CREATE_QUAD_ALL(DebugBorderDrawQuad, color, width);
- EXPECT_EQ(DrawQuad::DEBUG_BORDER, copy_quad->material);
- EXPECT_EQ(color, copy_quad->color);
- EXPECT_EQ(width, copy_quad->width);
-}
-
-TEST(DrawQuadTest, CopyRenderPassDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- RenderPassId render_pass_id = 61;
- viz::ResourceId mask_resource_id = 78;
- gfx::RectF mask_uv_rect(0, 0, 33.f, 19.f);
- gfx::Size mask_texture_size(128, 134);
- gfx::Vector2dF filters_scale;
- gfx::PointF filters_origin;
- gfx::RectF tex_coord_rect(1, 1, 255, 254);
-
- RenderPassId copied_render_pass_id = 235;
- CREATE_SHARED_STATE();
-
- CREATE_QUAD_NEW_RP(RenderPassDrawQuad, visible_rect, render_pass_id,
- mask_resource_id, mask_uv_rect, mask_texture_size,
- filters_scale, filters_origin, tex_coord_rect,
- copied_render_pass_id);
- EXPECT_EQ(DrawQuad::RENDER_PASS, copy_quad->material);
- EXPECT_EQ(visible_rect, copy_quad->visible_rect);
- EXPECT_EQ(copied_render_pass_id, copy_quad->render_pass_id);
- EXPECT_EQ(mask_resource_id, copy_quad->mask_resource_id());
- EXPECT_EQ(mask_uv_rect.ToString(), copy_quad->mask_uv_rect.ToString());
- EXPECT_EQ(mask_texture_size.ToString(),
- copy_quad->mask_texture_size.ToString());
- EXPECT_EQ(filters_scale, copy_quad->filters_scale);
- EXPECT_EQ(filters_origin, copy_quad->filters_origin);
- EXPECT_EQ(tex_coord_rect.ToString(), copy_quad->tex_coord_rect.ToString());
-
- CREATE_QUAD_ALL_RP(RenderPassDrawQuad, render_pass_id, mask_resource_id,
- mask_uv_rect, mask_texture_size, filters_scale,
- filters_origin, tex_coord_rect, copied_render_pass_id);
- EXPECT_EQ(DrawQuad::RENDER_PASS, copy_quad->material);
- EXPECT_EQ(copied_render_pass_id, copy_quad->render_pass_id);
- EXPECT_EQ(mask_resource_id, copy_quad->mask_resource_id());
- EXPECT_EQ(mask_uv_rect.ToString(), copy_quad->mask_uv_rect.ToString());
- EXPECT_EQ(mask_texture_size.ToString(),
- copy_quad->mask_texture_size.ToString());
- EXPECT_EQ(filters_scale, copy_quad->filters_scale);
- EXPECT_EQ(filters_origin, copy_quad->filters_origin);
- EXPECT_EQ(tex_coord_rect.ToString(), copy_quad->tex_coord_rect.ToString());
-}
-
-TEST(DrawQuadTest, CopySolidColorDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- SkColor color = 0x49494949;
- bool force_anti_aliasing_off = false;
- CREATE_SHARED_STATE();
-
- CREATE_QUAD_NEW(SolidColorDrawQuad, visible_rect, color,
- force_anti_aliasing_off);
- EXPECT_EQ(DrawQuad::SOLID_COLOR, copy_quad->material);
- EXPECT_EQ(visible_rect, copy_quad->visible_rect);
- EXPECT_EQ(color, copy_quad->color);
- EXPECT_EQ(force_anti_aliasing_off, copy_quad->force_anti_aliasing_off);
-
- CREATE_QUAD_ALL(SolidColorDrawQuad, color, force_anti_aliasing_off);
- EXPECT_EQ(DrawQuad::SOLID_COLOR, copy_quad->material);
- EXPECT_EQ(color, copy_quad->color);
- EXPECT_EQ(force_anti_aliasing_off, copy_quad->force_anti_aliasing_off);
-}
-
-TEST(DrawQuadTest, CopyStreamVideoDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- bool needs_blending = true;
- viz::ResourceId resource_id = 64;
- gfx::Size resource_size_in_pixels = gfx::Size(40, 41);
- gfx::Transform matrix = gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
- CREATE_SHARED_STATE();
-
- CREATE_QUAD_NEW(StreamVideoDrawQuad, visible_rect, needs_blending,
- resource_id, resource_size_in_pixels, matrix);
- EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT, copy_quad->material);
- EXPECT_EQ(visible_rect, copy_quad->visible_rect);
- EXPECT_EQ(needs_blending, copy_quad->needs_blending);
- EXPECT_EQ(resource_id, copy_quad->resource_id());
- EXPECT_EQ(resource_size_in_pixels, copy_quad->resource_size_in_pixels());
- EXPECT_EQ(matrix, copy_quad->matrix);
-
- CREATE_QUAD_ALL(StreamVideoDrawQuad, resource_id, resource_size_in_pixels,
- matrix);
- EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT, copy_quad->material);
- EXPECT_EQ(resource_id, copy_quad->resource_id());
- EXPECT_EQ(resource_size_in_pixels, copy_quad->resource_size_in_pixels());
- EXPECT_EQ(matrix, copy_quad->matrix);
-}
-
-TEST(DrawQuadTest, CopySurfaceDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- viz::SurfaceId surface_id(
- kArbitraryFrameSinkId,
- viz::LocalSurfaceId(1234, base::UnguessableToken::Create()));
- CREATE_SHARED_STATE();
-
- CREATE_QUAD_NEW(SurfaceDrawQuad, visible_rect, surface_id,
- SurfaceDrawQuadType::PRIMARY, nullptr);
- EXPECT_EQ(DrawQuad::SURFACE_CONTENT, copy_quad->material);
- EXPECT_EQ(visible_rect, copy_quad->visible_rect);
- EXPECT_EQ(surface_id, copy_quad->surface_id);
-
- CREATE_QUAD_ALL(SurfaceDrawQuad, surface_id, SurfaceDrawQuadType::PRIMARY,
- nullptr);
- EXPECT_EQ(DrawQuad::SURFACE_CONTENT, copy_quad->material);
- EXPECT_EQ(surface_id, copy_quad->surface_id);
-}
-
-
-TEST(DrawQuadTest, CopyTextureDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- bool needs_blending = true;
- unsigned resource_id = 82;
- gfx::Size resource_size_in_pixels = gfx::Size(40, 41);
- bool premultiplied_alpha = true;
- gfx::PointF uv_top_left(0.5f, 224.f);
- gfx::PointF uv_bottom_right(51.5f, 260.f);
- const float vertex_opacity[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- bool y_flipped = true;
- bool nearest_neighbor = true;
- bool secure_output_only = true;
- CREATE_SHARED_STATE();
-
- CREATE_QUAD_NEW(TextureDrawQuad, visible_rect, needs_blending, resource_id,
- premultiplied_alpha, uv_top_left, uv_bottom_right,
- SK_ColorTRANSPARENT, vertex_opacity, y_flipped,
- nearest_neighbor, secure_output_only);
- EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copy_quad->material);
- EXPECT_EQ(visible_rect, copy_quad->visible_rect);
- EXPECT_EQ(needs_blending, copy_quad->needs_blending);
- EXPECT_EQ(resource_id, copy_quad->resource_id());
- EXPECT_EQ(premultiplied_alpha, copy_quad->premultiplied_alpha);
- EXPECT_EQ(uv_top_left, copy_quad->uv_top_left);
- EXPECT_EQ(uv_bottom_right, copy_quad->uv_bottom_right);
- EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copy_quad->vertex_opacity, 4);
- EXPECT_EQ(y_flipped, copy_quad->y_flipped);
- EXPECT_EQ(nearest_neighbor, copy_quad->nearest_neighbor);
- EXPECT_EQ(secure_output_only, copy_quad->secure_output_only);
-
- CREATE_QUAD_ALL(TextureDrawQuad, resource_id, resource_size_in_pixels,
- premultiplied_alpha, uv_top_left, uv_bottom_right,
- SK_ColorTRANSPARENT, vertex_opacity, y_flipped,
- nearest_neighbor, secure_output_only);
- EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copy_quad->material);
- EXPECT_EQ(resource_id, copy_quad->resource_id());
- EXPECT_EQ(resource_size_in_pixels, copy_quad->resource_size_in_pixels());
- EXPECT_EQ(premultiplied_alpha, copy_quad->premultiplied_alpha);
- EXPECT_EQ(uv_top_left, copy_quad->uv_top_left);
- EXPECT_EQ(uv_bottom_right, copy_quad->uv_bottom_right);
- EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copy_quad->vertex_opacity, 4);
- EXPECT_EQ(y_flipped, copy_quad->y_flipped);
- EXPECT_EQ(nearest_neighbor, copy_quad->nearest_neighbor);
- EXPECT_EQ(secure_output_only, copy_quad->secure_output_only);
-}
-
-TEST(DrawQuadTest, CopyTileDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- bool needs_blending = true;
- unsigned resource_id = 104;
- gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
- gfx::Size texture_size(85, 32);
- bool swizzle_contents = true;
- bool nearest_neighbor = true;
- CREATE_SHARED_STATE();
-
- CREATE_QUAD_NEW(TileDrawQuad, visible_rect, needs_blending, resource_id,
- tex_coord_rect, texture_size, swizzle_contents,
- nearest_neighbor);
- EXPECT_EQ(DrawQuad::TILED_CONTENT, copy_quad->material);
- EXPECT_EQ(visible_rect, copy_quad->visible_rect);
- EXPECT_EQ(needs_blending, copy_quad->needs_blending);
- EXPECT_EQ(resource_id, copy_quad->resource_id());
- EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
- EXPECT_EQ(texture_size, copy_quad->texture_size);
- EXPECT_EQ(swizzle_contents, copy_quad->swizzle_contents);
- EXPECT_EQ(nearest_neighbor, copy_quad->nearest_neighbor);
-
- CREATE_QUAD_ALL(TileDrawQuad, resource_id, tex_coord_rect, texture_size,
- swizzle_contents, nearest_neighbor);
- EXPECT_EQ(DrawQuad::TILED_CONTENT, copy_quad->material);
- EXPECT_EQ(resource_id, copy_quad->resource_id());
- EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
- EXPECT_EQ(texture_size, copy_quad->texture_size);
- EXPECT_EQ(swizzle_contents, copy_quad->swizzle_contents);
- EXPECT_EQ(nearest_neighbor, copy_quad->nearest_neighbor);
-}
-
-TEST(DrawQuadTest, CopyYUVVideoDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- bool needs_blending = true;
- gfx::RectF ya_tex_coord_rect(40, 50, 30, 20);
- gfx::RectF uv_tex_coord_rect(20, 25, 15, 10);
- gfx::Size ya_tex_size(32, 68);
- gfx::Size uv_tex_size(41, 51);
- viz::ResourceId y_plane_resource_id = 45;
- viz::ResourceId u_plane_resource_id = 532;
- viz::ResourceId v_plane_resource_id = 4;
- viz::ResourceId a_plane_resource_id = 63;
- float resource_offset = 0.5f;
- float resource_multiplier = 2.001f;
- uint32_t bits_per_channel = 5;
- bool require_overlay = true;
- YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::JPEG;
- gfx::ColorSpace video_color_space = gfx::ColorSpace::CreateJpeg();
- CREATE_SHARED_STATE();
-
- CREATE_QUAD_NEW(YUVVideoDrawQuad, visible_rect, needs_blending,
- ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size,
- uv_tex_size, y_plane_resource_id, u_plane_resource_id,
- v_plane_resource_id, a_plane_resource_id, color_space,
- video_color_space, resource_offset, resource_multiplier,
- bits_per_channel);
- EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copy_quad->material);
- EXPECT_EQ(visible_rect, copy_quad->visible_rect);
- EXPECT_EQ(needs_blending, copy_quad->needs_blending);
- EXPECT_EQ(ya_tex_coord_rect, copy_quad->ya_tex_coord_rect);
- EXPECT_EQ(uv_tex_coord_rect, copy_quad->uv_tex_coord_rect);
- EXPECT_EQ(ya_tex_size, copy_quad->ya_tex_size);
- EXPECT_EQ(uv_tex_size, copy_quad->uv_tex_size);
- EXPECT_EQ(y_plane_resource_id, copy_quad->y_plane_resource_id());
- EXPECT_EQ(u_plane_resource_id, copy_quad->u_plane_resource_id());
- EXPECT_EQ(v_plane_resource_id, copy_quad->v_plane_resource_id());
- EXPECT_EQ(a_plane_resource_id, copy_quad->a_plane_resource_id());
- EXPECT_EQ(color_space, copy_quad->color_space);
- EXPECT_EQ(resource_offset, copy_quad->resource_offset);
- EXPECT_EQ(resource_multiplier, copy_quad->resource_multiplier);
- EXPECT_EQ(bits_per_channel, copy_quad->bits_per_channel);
- EXPECT_FALSE(copy_quad->require_overlay);
-
- CREATE_QUAD_ALL(YUVVideoDrawQuad, ya_tex_coord_rect, uv_tex_coord_rect,
- ya_tex_size, uv_tex_size, y_plane_resource_id,
- u_plane_resource_id, v_plane_resource_id, a_plane_resource_id,
- color_space, video_color_space, resource_offset,
- resource_multiplier, bits_per_channel, require_overlay);
- EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copy_quad->material);
- EXPECT_EQ(ya_tex_coord_rect, copy_quad->ya_tex_coord_rect);
- EXPECT_EQ(uv_tex_coord_rect, copy_quad->uv_tex_coord_rect);
- EXPECT_EQ(ya_tex_size, copy_quad->ya_tex_size);
- EXPECT_EQ(uv_tex_size, copy_quad->uv_tex_size);
- EXPECT_EQ(y_plane_resource_id, copy_quad->y_plane_resource_id());
- EXPECT_EQ(u_plane_resource_id, copy_quad->u_plane_resource_id());
- EXPECT_EQ(v_plane_resource_id, copy_quad->v_plane_resource_id());
- EXPECT_EQ(a_plane_resource_id, copy_quad->a_plane_resource_id());
- EXPECT_EQ(color_space, copy_quad->color_space);
- EXPECT_EQ(resource_offset, copy_quad->resource_offset);
- EXPECT_EQ(resource_multiplier, copy_quad->resource_multiplier);
- EXPECT_EQ(bits_per_channel, copy_quad->bits_per_channel);
- EXPECT_EQ(require_overlay, copy_quad->require_overlay);
-}
-
-TEST(DrawQuadTest, CopyPictureDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- bool needs_blending = true;
- gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
- gfx::Size texture_size(85, 32);
- bool nearest_neighbor = true;
- viz::ResourceFormat texture_format = viz::RGBA_8888;
- gfx::Rect content_rect(30, 40, 20, 30);
- float contents_scale = 3.141592f;
- scoped_refptr<RasterSource> raster_source =
- FakeRasterSource::CreateEmpty(gfx::Size(100, 100));
- CREATE_SHARED_STATE();
-
- CREATE_QUAD_NEW(PictureDrawQuad, visible_rect, needs_blending, tex_coord_rect,
- texture_size, nearest_neighbor, texture_format, content_rect,
- contents_scale, raster_source);
- EXPECT_EQ(DrawQuad::PICTURE_CONTENT, copy_quad->material);
- EXPECT_EQ(visible_rect, copy_quad->visible_rect);
- EXPECT_EQ(needs_blending, copy_quad->needs_blending);
- EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
- EXPECT_EQ(texture_size, copy_quad->texture_size);
- EXPECT_EQ(nearest_neighbor, copy_quad->nearest_neighbor);
- EXPECT_EQ(texture_format, copy_quad->texture_format);
- EXPECT_EQ(content_rect, copy_quad->content_rect);
- EXPECT_EQ(contents_scale, copy_quad->contents_scale);
- EXPECT_EQ(raster_source, copy_quad->raster_source);
-
- CREATE_QUAD_ALL(PictureDrawQuad, tex_coord_rect, texture_size,
- nearest_neighbor, texture_format, content_rect,
- contents_scale, raster_source);
- EXPECT_EQ(DrawQuad::PICTURE_CONTENT, copy_quad->material);
- EXPECT_EQ(tex_coord_rect, copy_quad->tex_coord_rect);
- EXPECT_EQ(texture_size, copy_quad->texture_size);
- EXPECT_EQ(nearest_neighbor, copy_quad->nearest_neighbor);
- EXPECT_EQ(texture_format, copy_quad->texture_format);
- EXPECT_EQ(content_rect, copy_quad->content_rect);
- EXPECT_EQ(contents_scale, copy_quad->contents_scale);
- EXPECT_EQ(raster_source, copy_quad->raster_source);
-}
-
-class DrawQuadIteratorTest : public testing::Test {
- protected:
- int IterateAndCount(DrawQuad* quad) {
- num_resources_ = 0;
- for (viz::ResourceId& resource_id : quad->resources) {
- ++num_resources_;
- ++resource_id;
- }
- return num_resources_;
- }
-
- private:
- int num_resources_;
-};
-
-TEST_F(DrawQuadIteratorTest, DebugBorderDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- SkColor color = 0xfabb0011;
- int width = 99;
-
- CREATE_SHARED_STATE();
- CREATE_QUAD_NEW(DebugBorderDrawQuad, visible_rect, color, width);
- EXPECT_EQ(0, IterateAndCount(quad_new));
-}
-
-TEST_F(DrawQuadIteratorTest, RenderPassDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- int render_pass_id = 61;
- viz::ResourceId mask_resource_id = 78;
- gfx::RectF mask_uv_rect(0.f, 0.f, 33.f, 19.f);
- gfx::Size mask_texture_size(128, 134);
- gfx::Vector2dF filters_scale(2.f, 3.f);
- gfx::PointF filters_origin(0.f, 0.f);
- gfx::RectF tex_coord_rect(1.f, 1.f, 33.f, 19.f);
-
- int copied_render_pass_id = 235;
-
- CREATE_SHARED_STATE();
- CREATE_QUAD_NEW_RP(RenderPassDrawQuad, visible_rect, render_pass_id,
- mask_resource_id, mask_uv_rect, mask_texture_size,
- filters_scale, filters_origin, tex_coord_rect,
- copied_render_pass_id);
- EXPECT_EQ(mask_resource_id, quad_new->mask_resource_id());
- EXPECT_EQ(1, IterateAndCount(quad_new));
- EXPECT_EQ(mask_resource_id + 1, quad_new->mask_resource_id());
-
- viz::ResourceId new_mask_resource_id = 0;
- gfx::Rect quad_rect(30, 40, 50, 60);
- quad_new->SetNew(shared_state, quad_rect, visible_rect, render_pass_id,
- new_mask_resource_id, mask_uv_rect, mask_texture_size,
- filters_scale, filters_origin, tex_coord_rect);
- EXPECT_EQ(0, IterateAndCount(quad_new));
- EXPECT_EQ(0u, quad_new->mask_resource_id());
-}
-
-TEST_F(DrawQuadIteratorTest, SolidColorDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- SkColor color = 0x49494949;
- bool force_anti_aliasing_off = false;
-
- CREATE_SHARED_STATE();
- CREATE_QUAD_NEW(SolidColorDrawQuad, visible_rect, color,
- force_anti_aliasing_off);
- EXPECT_EQ(0, IterateAndCount(quad_new));
-}
-
-TEST_F(DrawQuadIteratorTest, StreamVideoDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- viz::ResourceId resource_id = 64;
- gfx::Size resource_size_in_pixels = gfx::Size(40, 41);
- gfx::Transform matrix = gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1);
-
- CREATE_SHARED_STATE();
- CREATE_QUAD_NEW(StreamVideoDrawQuad, visible_rect, needs_blending,
- resource_id, resource_size_in_pixels, matrix);
- EXPECT_EQ(resource_id, quad_new->resource_id());
- EXPECT_EQ(resource_size_in_pixels, quad_new->resource_size_in_pixels());
- EXPECT_EQ(1, IterateAndCount(quad_new));
- EXPECT_EQ(resource_id + 1, quad_new->resource_id());
-}
-
-TEST_F(DrawQuadIteratorTest, SurfaceDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- viz::SurfaceId surface_id(
- kArbitraryFrameSinkId,
- viz::LocalSurfaceId(4321, base::UnguessableToken::Create()));
-
- CREATE_SHARED_STATE();
- CREATE_QUAD_NEW(SurfaceDrawQuad, visible_rect, surface_id,
- SurfaceDrawQuadType::PRIMARY, nullptr);
- EXPECT_EQ(0, IterateAndCount(quad_new));
-}
-
-TEST_F(DrawQuadIteratorTest, TextureDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- unsigned resource_id = 82;
- bool premultiplied_alpha = true;
- gfx::PointF uv_top_left(0.5f, 224.f);
- gfx::PointF uv_bottom_right(51.5f, 260.f);
- const float vertex_opacity[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- bool y_flipped = true;
- bool nearest_neighbor = true;
- bool secure_output_only = true;
-
- CREATE_SHARED_STATE();
- CREATE_QUAD_NEW(TextureDrawQuad, visible_rect, needs_blending, resource_id,
- premultiplied_alpha, uv_top_left, uv_bottom_right,
- SK_ColorTRANSPARENT, vertex_opacity, y_flipped,
- nearest_neighbor, secure_output_only);
- EXPECT_EQ(resource_id, quad_new->resource_id());
- EXPECT_EQ(1, IterateAndCount(quad_new));
- EXPECT_EQ(resource_id + 1, quad_new->resource_id());
-}
-
-TEST_F(DrawQuadIteratorTest, TileDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- unsigned resource_id = 104;
- gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
- gfx::Size texture_size(85, 32);
- bool swizzle_contents = true;
- bool nearest_neighbor = true;
-
- CREATE_SHARED_STATE();
- CREATE_QUAD_NEW(TileDrawQuad, visible_rect, needs_blending, resource_id,
- tex_coord_rect, texture_size, swizzle_contents,
- nearest_neighbor);
- EXPECT_EQ(resource_id, quad_new->resource_id());
- EXPECT_EQ(1, IterateAndCount(quad_new));
- EXPECT_EQ(resource_id + 1, quad_new->resource_id());
-}
-
-TEST_F(DrawQuadIteratorTest, YUVVideoDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- gfx::RectF ya_tex_coord_rect(0.0f, 0.0f, 0.75f, 0.5f);
- gfx::RectF uv_tex_coord_rect(0.0f, 0.0f, 0.375f, 0.25f);
- gfx::Size ya_tex_size(32, 68);
- gfx::Size uv_tex_size(41, 51);
- viz::ResourceId y_plane_resource_id = 45;
- viz::ResourceId u_plane_resource_id = 532;
- viz::ResourceId v_plane_resource_id = 4;
- viz::ResourceId a_plane_resource_id = 63;
- YUVVideoDrawQuad::ColorSpace color_space = YUVVideoDrawQuad::JPEG;
- gfx::ColorSpace video_color_space = gfx::ColorSpace::CreateJpeg();
-
- CREATE_SHARED_STATE();
- CREATE_QUAD_NEW(YUVVideoDrawQuad, visible_rect, needs_blending,
- ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size,
- uv_tex_size, y_plane_resource_id, u_plane_resource_id,
- v_plane_resource_id, a_plane_resource_id, color_space,
- video_color_space, 0.0, 1.0, 5);
- EXPECT_EQ(DrawQuad::YUV_VIDEO_CONTENT, copy_quad->material);
- EXPECT_EQ(y_plane_resource_id, quad_new->y_plane_resource_id());
- EXPECT_EQ(u_plane_resource_id, quad_new->u_plane_resource_id());
- EXPECT_EQ(v_plane_resource_id, quad_new->v_plane_resource_id());
- EXPECT_EQ(a_plane_resource_id, quad_new->a_plane_resource_id());
- EXPECT_EQ(color_space, quad_new->color_space);
- EXPECT_EQ(4, IterateAndCount(quad_new));
- EXPECT_EQ(y_plane_resource_id + 1, quad_new->y_plane_resource_id());
- EXPECT_EQ(u_plane_resource_id + 1, quad_new->u_plane_resource_id());
- EXPECT_EQ(v_plane_resource_id + 1, quad_new->v_plane_resource_id());
- EXPECT_EQ(a_plane_resource_id + 1, quad_new->a_plane_resource_id());
-}
-
-// Disabled until picture draw quad is supported for ubercomp: crbug.com/231715
-TEST_F(DrawQuadIteratorTest, DISABLED_PictureDrawQuad) {
- gfx::Rect visible_rect(40, 50, 30, 20);
- gfx::RectF tex_coord_rect(31.f, 12.f, 54.f, 20.f);
- gfx::Size texture_size(85, 32);
- bool nearest_neighbor = true;
- viz::ResourceFormat texture_format = viz::RGBA_8888;
- gfx::Rect content_rect(30, 40, 20, 30);
- float contents_scale = 3.141592f;
- scoped_refptr<RasterSource> raster_source =
- FakeRasterSource::CreateEmpty(gfx::Size(100, 100));
-
- CREATE_SHARED_STATE();
- CREATE_QUAD_NEW(PictureDrawQuad, visible_rect, needs_blending, tex_coord_rect,
- texture_size, nearest_neighbor, texture_format, content_rect,
- contents_scale, raster_source);
- EXPECT_EQ(0, IterateAndCount(quad_new));
-}
-
-TEST(DrawQuadTest, LargestQuadType) {
- size_t largest = 0;
-
- for (int i = 0; i <= DrawQuad::MATERIAL_LAST; ++i) {
- switch (static_cast<DrawQuad::Material>(i)) {
- case DrawQuad::DEBUG_BORDER:
- largest = std::max(largest, sizeof(DebugBorderDrawQuad));
- break;
- case DrawQuad::PICTURE_CONTENT:
- largest = std::max(largest, sizeof(PictureDrawQuad));
- break;
- case DrawQuad::TEXTURE_CONTENT:
- largest = std::max(largest, sizeof(TextureDrawQuad));
- break;
- case DrawQuad::RENDER_PASS:
- largest = std::max(largest, sizeof(RenderPassDrawQuad));
- break;
- case DrawQuad::SOLID_COLOR:
- largest = std::max(largest, sizeof(SolidColorDrawQuad));
- break;
- case DrawQuad::SURFACE_CONTENT:
- largest = std::max(largest, sizeof(SurfaceDrawQuad));
- break;
- case DrawQuad::TILED_CONTENT:
- largest = std::max(largest, sizeof(TileDrawQuad));
- break;
- case DrawQuad::STREAM_VIDEO_CONTENT:
- largest = std::max(largest, sizeof(StreamVideoDrawQuad));
- break;
- case DrawQuad::YUV_VIDEO_CONTENT:
- largest = std::max(largest, sizeof(YUVVideoDrawQuad));
- break;
- case DrawQuad::INVALID:
- break;
- }
- }
- EXPECT_EQ(LargestDrawQuadSize(), largest);
-
- if (!HasFailure())
- return;
-
- // On failure, output the size of all quads for debugging.
- LOG(ERROR) << "largest " << largest;
- LOG(ERROR) << "kLargestDrawQuad " << LargestDrawQuadSize();
- for (int i = 0; i <= DrawQuad::MATERIAL_LAST; ++i) {
- switch (static_cast<DrawQuad::Material>(i)) {
- case DrawQuad::DEBUG_BORDER:
- LOG(ERROR) << "DebugBorderDrawQuad " << sizeof(DebugBorderDrawQuad);
- break;
- case DrawQuad::PICTURE_CONTENT:
- LOG(ERROR) << "PictureDrawQuad " << sizeof(PictureDrawQuad);
- break;
- case DrawQuad::TEXTURE_CONTENT:
- LOG(ERROR) << "TextureDrawQuad " << sizeof(TextureDrawQuad);
- break;
- case DrawQuad::RENDER_PASS:
- LOG(ERROR) << "RenderPassDrawQuad " << sizeof(RenderPassDrawQuad);
- break;
- case DrawQuad::SOLID_COLOR:
- LOG(ERROR) << "SolidColorDrawQuad " << sizeof(SolidColorDrawQuad);
- break;
- case DrawQuad::SURFACE_CONTENT:
- LOG(ERROR) << "SurfaceDrawQuad " << sizeof(SurfaceDrawQuad);
- break;
- case DrawQuad::TILED_CONTENT:
- LOG(ERROR) << "TileDrawQuad " << sizeof(TileDrawQuad);
- break;
- case DrawQuad::STREAM_VIDEO_CONTENT:
- LOG(ERROR) << "StreamVideoDrawQuad " << sizeof(StreamVideoDrawQuad);
- break;
- case DrawQuad::YUV_VIDEO_CONTENT:
- LOG(ERROR) << "YUVVideoDrawQuad " << sizeof(YUVVideoDrawQuad);
- break;
- case DrawQuad::INVALID:
- break;
- }
- }
-}
-
-} // namespace
-} // namespace cc
diff --git a/chromium/cc/quads/largest_draw_quad.cc b/chromium/cc/quads/largest_draw_quad.cc
deleted file mode 100644
index c62a5bd8e29..00000000000
--- a/chromium/cc/quads/largest_draw_quad.cc
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/largest_draw_quad.h"
-
-#include <stddef.h>
-
-#include <algorithm>
-
-#include "cc/quads/debug_border_draw_quad.h"
-#include "cc/quads/picture_draw_quad.h"
-#include "cc/quads/render_pass_draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/stream_video_draw_quad.h"
-#include "cc/quads/surface_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
-#include "cc/quads/tile_draw_quad.h"
-#include "cc/quads/yuv_video_draw_quad.h"
-
-namespace {
-
-template <typename...>
-struct MaxSize {};
-template <class T, class... Args>
-struct MaxSize<T, Args...> {
- static constexpr size_t value = sizeof(T) > MaxSize<Args...>::value
- ? sizeof(T)
- : MaxSize<Args...>::value;
-};
-template <>
-struct MaxSize<> {
- static constexpr size_t value = 0;
-};
-
-constexpr size_t kLargestDrawQuadSize = MaxSize<cc::DebugBorderDrawQuad,
- cc::PictureDrawQuad,
- cc::RenderPassDrawQuad,
- cc::SolidColorDrawQuad,
- cc::StreamVideoDrawQuad,
- cc::SurfaceDrawQuad,
- cc::TextureDrawQuad,
- cc::TileDrawQuad,
- cc::YUVVideoDrawQuad>::value;
-
-template <typename...>
-struct MaxAlign {};
-template <class T, class... Args>
-struct MaxAlign<T, Args...> {
- static constexpr size_t value = alignof(T) > MaxAlign<Args...>::value
- ? alignof(T)
- : MaxAlign<Args...>::value;
-};
-template <>
-struct MaxAlign<> {
- static constexpr size_t value = 0;
-};
-
-constexpr size_t kLargestDrawQuadAlignment =
- MaxAlign<cc::DebugBorderDrawQuad,
- cc::PictureDrawQuad,
- cc::RenderPassDrawQuad,
- cc::SolidColorDrawQuad,
- cc::StreamVideoDrawQuad,
- cc::SurfaceDrawQuad,
- cc::TextureDrawQuad,
- cc::TileDrawQuad,
- cc::YUVVideoDrawQuad>::value;
-
-} // namespace
-
-namespace cc {
-
-size_t LargestDrawQuadSize() {
- return kLargestDrawQuadSize;
-}
-
-size_t LargestDrawQuadAlignment() {
- return kLargestDrawQuadAlignment;
-}
-
-} // namespace cc
diff --git a/chromium/cc/quads/largest_draw_quad.h b/chromium/cc/quads/largest_draw_quad.h
deleted file mode 100644
index 9069a3325eb..00000000000
--- a/chromium/cc/quads/largest_draw_quad.h
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_QUADS_LARGEST_DRAW_QUAD_H_
-#define CC_QUADS_LARGEST_DRAW_QUAD_H_
-
-#include <stddef.h>
-
-#include "cc/cc_export.h"
-
-namespace cc {
-
-CC_EXPORT size_t LargestDrawQuadSize();
-CC_EXPORT size_t LargestDrawQuadAlignment();
-
-} // namespace cc
-
-#endif // CC_QUADS_LARGEST_DRAW_QUAD_H_
diff --git a/chromium/cc/quads/picture_draw_quad.cc b/chromium/cc/quads/picture_draw_quad.cc
deleted file mode 100644
index ec57c52ef05..00000000000
--- a/chromium/cc/quads/picture_draw_quad.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/picture_draw_quad.h"
-
-#include "base/trace_event/trace_event_argument.h"
-#include "base/values.h"
-#include "cc/base/math_util.h"
-#include "components/viz/common/resources/platform_color.h"
-
-namespace cc {
-
-PictureDrawQuad::PictureDrawQuad() {
-}
-
-PictureDrawQuad::PictureDrawQuad(const PictureDrawQuad& other) = default;
-
-PictureDrawQuad::~PictureDrawQuad() {
-}
-
-void PictureDrawQuad::SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- const gfx::RectF& tex_coord_rect,
- const gfx::Size& texture_size,
- bool nearest_neighbor,
- viz::ResourceFormat texture_format,
- const gfx::Rect& content_rect,
- float contents_scale,
- scoped_refptr<RasterSource> raster_source) {
- ContentDrawQuadBase::SetNew(
- shared_quad_state, DrawQuad::PICTURE_CONTENT, rect, visible_rect,
- needs_blending, tex_coord_rect, texture_size,
- !viz::PlatformColor::SameComponentOrder(texture_format),
- nearest_neighbor);
- this->content_rect = content_rect;
- this->contents_scale = contents_scale;
- this->raster_source = raster_source;
- this->texture_format = texture_format;
-}
-
-void PictureDrawQuad::SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- const gfx::RectF& tex_coord_rect,
- const gfx::Size& texture_size,
- bool nearest_neighbor,
- viz::ResourceFormat texture_format,
- const gfx::Rect& content_rect,
- float contents_scale,
- scoped_refptr<RasterSource> raster_source) {
- ContentDrawQuadBase::SetAll(
- shared_quad_state, DrawQuad::PICTURE_CONTENT, rect, visible_rect,
- needs_blending, tex_coord_rect, texture_size,
- !viz::PlatformColor::SameComponentOrder(texture_format),
- nearest_neighbor);
- this->content_rect = content_rect;
- this->contents_scale = contents_scale;
- this->raster_source = raster_source;
- this->texture_format = texture_format;
-}
-
-const PictureDrawQuad* PictureDrawQuad::MaterialCast(const DrawQuad* quad) {
- DCHECK(quad->material == DrawQuad::PICTURE_CONTENT);
- return static_cast<const PictureDrawQuad*>(quad);
-}
-
-void PictureDrawQuad::ExtendValue(base::trace_event::TracedValue* value) const {
- ContentDrawQuadBase::ExtendValue(value);
- MathUtil::AddToTracedValue("content_rect", content_rect, value);
- value->SetDouble("contents_scale", contents_scale);
- value->SetInteger("texture_format", texture_format);
- // TODO(piman): raster_source?
-}
-
-} // namespace cc
diff --git a/chromium/cc/quads/picture_draw_quad.h b/chromium/cc/quads/picture_draw_quad.h
deleted file mode 100644
index 02e760703a0..00000000000
--- a/chromium/cc/quads/picture_draw_quad.h
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_QUADS_PICTURE_DRAW_QUAD_H_
-#define CC_QUADS_PICTURE_DRAW_QUAD_H_
-
-#include <memory>
-
-#include "base/memory/ref_counted.h"
-#include "cc/cc_export.h"
-#include "cc/quads/content_draw_quad_base.h"
-#include "cc/raster/raster_source.h"
-#include "cc/resources/resource_provider.h"
-#include "ui/gfx/geometry/rect.h"
-#include "ui/gfx/geometry/rect_f.h"
-#include "ui/gfx/geometry/size.h"
-
-namespace cc {
-
-// Used for on-demand tile rasterization.
-class CC_EXPORT PictureDrawQuad : public ContentDrawQuadBase {
- public:
- PictureDrawQuad();
- PictureDrawQuad(const PictureDrawQuad& other);
- ~PictureDrawQuad() override;
-
- void SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- const gfx::RectF& tex_coord_rect,
- const gfx::Size& texture_size,
- bool nearest_neighbor,
- viz::ResourceFormat texture_format,
- const gfx::Rect& content_rect,
- float contents_scale,
- scoped_refptr<RasterSource> raster_source);
-
- void SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- const gfx::RectF& tex_coord_rect,
- const gfx::Size& texture_size,
- bool nearest_neighbor,
- viz::ResourceFormat texture_format,
- const gfx::Rect& content_rect,
- float contents_scale,
- scoped_refptr<RasterSource> raster_source);
-
- gfx::Rect content_rect;
- float contents_scale;
- scoped_refptr<RasterSource> raster_source;
- viz::ResourceFormat texture_format;
-
- static const PictureDrawQuad* MaterialCast(const DrawQuad* quad);
-
- private:
- void ExtendValue(base::trace_event::TracedValue* value) const override;
-};
-
-} // namespace cc
-
-#endif // CC_QUADS_PICTURE_DRAW_QUAD_H_
diff --git a/chromium/cc/quads/render_pass.cc b/chromium/cc/quads/render_pass.cc
deleted file mode 100644
index 4955f0b0729..00000000000
--- a/chromium/cc/quads/render_pass.cc
+++ /dev/null
@@ -1,308 +0,0 @@
-// Copyright 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/render_pass.h"
-
-#include <stddef.h>
-
-#include <algorithm>
-
-#include "base/memory/ptr_util.h"
-#include "base/numerics/safe_conversions.h"
-#include "base/trace_event/trace_event.h"
-#include "base/trace_event/trace_event_argument.h"
-#include "base/values.h"
-#include "cc/base/math_util.h"
-#include "cc/quads/debug_border_draw_quad.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/largest_draw_quad.h"
-#include "cc/quads/picture_draw_quad.h"
-#include "cc/quads/render_pass_draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/stream_video_draw_quad.h"
-#include "cc/quads/surface_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
-#include "cc/quads/tile_draw_quad.h"
-#include "cc/quads/yuv_video_draw_quad.h"
-#include "components/viz/common/quads/copy_output_request.h"
-#include "components/viz/common/quads/shared_quad_state.h"
-#include "components/viz/common/traced_value.h"
-
-namespace {
-const size_t kDefaultNumSharedQuadStatesToReserve = 32;
-const size_t kDefaultNumQuadsToReserve = 128;
-}
-
-namespace cc {
-
-QuadList::QuadList()
- : ListContainer<DrawQuad>(LargestDrawQuadAlignment(),
- LargestDrawQuadSize(),
- kDefaultNumSharedQuadStatesToReserve) {}
-
-QuadList::QuadList(size_t default_size_to_reserve)
- : ListContainer<DrawQuad>(LargestDrawQuadAlignment(),
- LargestDrawQuadSize(),
- default_size_to_reserve) {}
-
-void QuadList::ReplaceExistingQuadWithOpaqueTransparentSolidColor(Iterator at) {
- // In order to fill the backbuffer with transparent black, the replacement
- // solid color quad needs to set |needs_blending| to false, and
- // ShouldDrawWithBlending() returns false so it is drawn without blending.
- const gfx::Rect rect = at->rect;
- bool needs_blending = false;
- const viz::SharedQuadState* shared_quad_state = at->shared_quad_state;
-
- SolidColorDrawQuad* replacement =
- QuadList::ReplaceExistingElement<SolidColorDrawQuad>(at);
- replacement->SetAll(shared_quad_state, rect, rect /* visible_rect */,
- needs_blending, SK_ColorTRANSPARENT, true);
-}
-
-std::unique_ptr<RenderPass> RenderPass::Create() {
- return base::WrapUnique(new RenderPass());
-}
-
-std::unique_ptr<RenderPass> RenderPass::Create(size_t num_layers) {
- return base::WrapUnique(new RenderPass(num_layers));
-}
-
-std::unique_ptr<RenderPass> RenderPass::Create(
- size_t shared_quad_state_list_size,
- size_t quad_list_size) {
- return base::WrapUnique(
- new RenderPass(shared_quad_state_list_size, quad_list_size));
-}
-
-RenderPass::RenderPass()
- : quad_list(kDefaultNumQuadsToReserve),
- shared_quad_state_list(alignof(viz::SharedQuadState),
- sizeof(viz::SharedQuadState),
- kDefaultNumSharedQuadStatesToReserve) {}
-
-// Each layer usually produces one shared quad state, so the number of layers
-// is a good hint for what to reserve here.
-RenderPass::RenderPass(size_t num_layers)
- : has_transparent_background(true),
- cache_render_pass(false),
- has_damage_from_contributing_content(false),
- quad_list(kDefaultNumQuadsToReserve),
- shared_quad_state_list(alignof(viz::SharedQuadState),
- sizeof(viz::SharedQuadState),
- num_layers) {}
-
-RenderPass::RenderPass(size_t shared_quad_state_list_size,
- size_t quad_list_size)
- : has_transparent_background(true),
- cache_render_pass(false),
- has_damage_from_contributing_content(false),
- quad_list(quad_list_size),
- shared_quad_state_list(alignof(viz::SharedQuadState),
- sizeof(viz::SharedQuadState),
- shared_quad_state_list_size) {}
-
-RenderPass::~RenderPass() {
- TRACE_EVENT_OBJECT_DELETED_WITH_ID(
- TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"), "cc::RenderPass",
- reinterpret_cast<void*>(id));
-}
-
-std::unique_ptr<RenderPass> RenderPass::Copy(int new_id) const {
- std::unique_ptr<RenderPass> copy_pass(
- Create(shared_quad_state_list.size(), quad_list.size()));
- copy_pass->SetAll(new_id, output_rect, damage_rect, transform_to_root_target,
- filters, background_filters, color_space,
- has_transparent_background, cache_render_pass,
- has_damage_from_contributing_content);
- return copy_pass;
-}
-
-std::unique_ptr<RenderPass> RenderPass::DeepCopy() const {
- // Since we can't copy these, it's wrong to use DeepCopy in a situation where
- // you may have copy_requests present.
- DCHECK_EQ(copy_requests.size(), 0u);
-
- std::unique_ptr<RenderPass> copy_pass(
- Create(shared_quad_state_list.size(), quad_list.size()));
- copy_pass->SetAll(id, output_rect, damage_rect, transform_to_root_target,
- filters, background_filters, color_space,
- has_transparent_background, cache_render_pass,
- has_damage_from_contributing_content);
-
- if (shared_quad_state_list.empty()) {
- DCHECK(quad_list.empty());
- return copy_pass;
- }
-
- SharedQuadStateList::ConstIterator sqs_iter = shared_quad_state_list.begin();
- viz::SharedQuadState* copy_shared_quad_state =
- copy_pass->CreateAndAppendSharedQuadState();
- *copy_shared_quad_state = **sqs_iter;
- for (auto* quad : quad_list) {
- while (quad->shared_quad_state != *sqs_iter) {
- ++sqs_iter;
- DCHECK(sqs_iter != shared_quad_state_list.end());
- copy_shared_quad_state = copy_pass->CreateAndAppendSharedQuadState();
- *copy_shared_quad_state = **sqs_iter;
- }
- DCHECK(quad->shared_quad_state == *sqs_iter);
-
- if (quad->material == DrawQuad::RENDER_PASS) {
- const RenderPassDrawQuad* pass_quad =
- RenderPassDrawQuad::MaterialCast(quad);
- copy_pass->CopyFromAndAppendRenderPassDrawQuad(pass_quad,
- pass_quad->render_pass_id);
- } else {
- copy_pass->CopyFromAndAppendDrawQuad(quad);
- }
- }
- return copy_pass;
-}
-
-// static
-void RenderPass::CopyAll(const std::vector<std::unique_ptr<RenderPass>>& in,
- std::vector<std::unique_ptr<RenderPass>>* out) {
- for (const auto& source : in)
- out->push_back(source->DeepCopy());
-}
-
-void RenderPass::SetNew(uint64_t id,
- const gfx::Rect& output_rect,
- const gfx::Rect& damage_rect,
- const gfx::Transform& transform_to_root_target) {
- DCHECK(id);
- DCHECK(damage_rect.IsEmpty() || output_rect.Contains(damage_rect))
- << "damage_rect: " << damage_rect.ToString()
- << " output_rect: " << output_rect.ToString();
-
- this->id = id;
- this->output_rect = output_rect;
- this->damage_rect = damage_rect;
- this->transform_to_root_target = transform_to_root_target;
-
- DCHECK(quad_list.empty());
- DCHECK(shared_quad_state_list.empty());
-}
-
-void RenderPass::SetAll(uint64_t id,
- const gfx::Rect& output_rect,
- const gfx::Rect& damage_rect,
- const gfx::Transform& transform_to_root_target,
- const FilterOperations& filters,
- const FilterOperations& background_filters,
- const gfx::ColorSpace& color_space,
- bool has_transparent_background,
- bool cache_render_pass,
- bool has_damage_from_contributing_content) {
- DCHECK(id);
-
- this->id = id;
- this->output_rect = output_rect;
- this->damage_rect = damage_rect;
- this->transform_to_root_target = transform_to_root_target;
- this->filters = filters;
- this->background_filters = background_filters;
- this->color_space = color_space;
- this->has_transparent_background = has_transparent_background;
- this->cache_render_pass = cache_render_pass;
- this->has_damage_from_contributing_content =
- has_damage_from_contributing_content;
-
- DCHECK(quad_list.empty());
- DCHECK(shared_quad_state_list.empty());
-}
-
-void RenderPass::AsValueInto(base::trace_event::TracedValue* value) const {
- MathUtil::AddToTracedValue("output_rect", output_rect, value);
- MathUtil::AddToTracedValue("damage_rect", damage_rect, value);
-
- value->SetBoolean("has_transparent_background", has_transparent_background);
- value->SetBoolean("cache_render_pass", cache_render_pass);
- value->SetBoolean("has_damage_from_contributing_content",
- has_damage_from_contributing_content);
- value->SetInteger("copy_requests",
- base::saturated_cast<int>(copy_requests.size()));
-
- value->BeginArray("filters");
- filters.AsValueInto(value);
- value->EndArray();
-
- value->BeginArray("background_filters");
- background_filters.AsValueInto(value);
- value->EndArray();
-
- value->BeginArray("shared_quad_state_list");
- for (auto* shared_quad_state : shared_quad_state_list) {
- value->BeginDictionary();
- shared_quad_state->AsValueInto(value);
- value->EndDictionary();
- }
- value->EndArray();
-
- value->BeginArray("quad_list");
- for (auto* quad : quad_list) {
- value->BeginDictionary();
- quad->AsValueInto(value);
- value->EndDictionary();
- }
- value->EndArray();
-
- viz::TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
- TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"), value, "cc::RenderPass",
- reinterpret_cast<void*>(id));
-}
-
-viz::SharedQuadState* RenderPass::CreateAndAppendSharedQuadState() {
- return shared_quad_state_list.AllocateAndConstruct<viz::SharedQuadState>();
-}
-
-RenderPassDrawQuad* RenderPass::CopyFromAndAppendRenderPassDrawQuad(
- const RenderPassDrawQuad* quad,
- RenderPassId render_pass_id) {
- DCHECK(!shared_quad_state_list.empty());
- RenderPassDrawQuad* copy_quad =
- CopyFromAndAppendTypedDrawQuad<RenderPassDrawQuad>(quad);
- copy_quad->shared_quad_state = shared_quad_state_list.back();
- copy_quad->render_pass_id = render_pass_id;
- return copy_quad;
-}
-
-DrawQuad* RenderPass::CopyFromAndAppendDrawQuad(const DrawQuad* quad) {
- DCHECK(!shared_quad_state_list.empty());
- switch (quad->material) {
- case DrawQuad::DEBUG_BORDER:
- CopyFromAndAppendTypedDrawQuad<DebugBorderDrawQuad>(quad);
- break;
- case DrawQuad::PICTURE_CONTENT:
- CopyFromAndAppendTypedDrawQuad<PictureDrawQuad>(quad);
- break;
- case DrawQuad::TEXTURE_CONTENT:
- CopyFromAndAppendTypedDrawQuad<TextureDrawQuad>(quad);
- break;
- case DrawQuad::SOLID_COLOR:
- CopyFromAndAppendTypedDrawQuad<SolidColorDrawQuad>(quad);
- break;
- case DrawQuad::TILED_CONTENT:
- CopyFromAndAppendTypedDrawQuad<TileDrawQuad>(quad);
- break;
- case DrawQuad::STREAM_VIDEO_CONTENT:
- CopyFromAndAppendTypedDrawQuad<StreamVideoDrawQuad>(quad);
- break;
- case DrawQuad::SURFACE_CONTENT:
- CopyFromAndAppendTypedDrawQuad<SurfaceDrawQuad>(quad);
- break;
- case DrawQuad::YUV_VIDEO_CONTENT:
- CopyFromAndAppendTypedDrawQuad<YUVVideoDrawQuad>(quad);
- break;
- // RenderPass quads need to use specific CopyFrom function.
- case DrawQuad::RENDER_PASS:
- case DrawQuad::INVALID:
- LOG(FATAL) << "Invalid DrawQuad material " << quad->material;
- break;
- }
- quad_list.back()->shared_quad_state = shared_quad_state_list.back();
- return quad_list.back();
-}
-
-} // namespace cc
diff --git a/chromium/cc/quads/render_pass.h b/chromium/cc/quads/render_pass.h
deleted file mode 100644
index 35ff6f136a1..00000000000
--- a/chromium/cc/quads/render_pass.h
+++ /dev/null
@@ -1,172 +0,0 @@
-// Copyright 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_QUADS_RENDER_PASS_H_
-#define CC_QUADS_RENDER_PASS_H_
-
-#include <stddef.h>
-
-#include <utility>
-#include <vector>
-
-#include "base/callback.h"
-#include "base/hash.h"
-#include "base/macros.h"
-#include "cc/base/filter_operations.h"
-#include "cc/base/list_container.h"
-#include "cc/cc_export.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/largest_draw_quad.h"
-#include "ui/gfx/color_space.h"
-#include "ui/gfx/geometry/rect.h"
-#include "ui/gfx/geometry/rect_f.h"
-#include "ui/gfx/transform.h"
-
-namespace base {
-namespace trace_event {
-class TracedValue;
-}
-}
-
-namespace viz {
-class CopyOutputRequest;
-class SharedQuadState;
-}
-
-namespace cc {
-
-class DrawQuad;
-class RenderPassDrawQuad;
-
-// A list of DrawQuad objects, sorted internally in front-to-back order.
-class CC_EXPORT QuadList : public ListContainer<DrawQuad> {
- public:
- QuadList();
- explicit QuadList(size_t default_size_to_reserve);
-
- typedef QuadList::ReverseIterator BackToFrontIterator;
- typedef QuadList::ConstReverseIterator ConstBackToFrontIterator;
-
- inline BackToFrontIterator BackToFrontBegin() { return rbegin(); }
- inline BackToFrontIterator BackToFrontEnd() { return rend(); }
- inline ConstBackToFrontIterator BackToFrontBegin() const { return rbegin(); }
- inline ConstBackToFrontIterator BackToFrontEnd() const { return rend(); }
-
- // This function is used by overlay algorithm to fill the backbuffer with
- // transparent black.
- void ReplaceExistingQuadWithOpaqueTransparentSolidColor(Iterator at);
-};
-
-using SharedQuadStateList = ListContainer<viz::SharedQuadState>;
-
-using RenderPassId = uint64_t;
-
-class CC_EXPORT RenderPass {
- public:
- ~RenderPass();
-
- static std::unique_ptr<RenderPass> Create();
- static std::unique_ptr<RenderPass> Create(size_t num_layers);
- static std::unique_ptr<RenderPass> Create(size_t shared_quad_state_list_size,
- size_t quad_list_size);
-
- // A shallow copy of the render pass, which does not include its quads or copy
- // requests.
- std::unique_ptr<RenderPass> Copy(int new_id) const;
-
- // A deep copy of the render pass that includes quads.
- std::unique_ptr<RenderPass> DeepCopy() const;
-
- // A deep copy of the render passes in the list including the quads.
- static void CopyAll(const std::vector<std::unique_ptr<RenderPass>>& in,
- std::vector<std::unique_ptr<RenderPass>>* out);
-
- void SetNew(RenderPassId id,
- const gfx::Rect& output_rect,
- const gfx::Rect& damage_rect,
- const gfx::Transform& transform_to_root_target);
-
- void SetAll(RenderPassId id,
- const gfx::Rect& output_rect,
- const gfx::Rect& damage_rect,
- const gfx::Transform& transform_to_root_target,
- const FilterOperations& filters,
- const FilterOperations& background_filters,
- const gfx::ColorSpace& color_space,
- bool has_transparent_background,
- bool cache_render_pass,
- bool has_damage_from_contributing_content);
-
- void AsValueInto(base::trace_event::TracedValue* dict) const;
-
- viz::SharedQuadState* CreateAndAppendSharedQuadState();
-
- template <typename DrawQuadType>
- DrawQuadType* CreateAndAppendDrawQuad() {
- return quad_list.AllocateAndConstruct<DrawQuadType>();
- }
-
- RenderPassDrawQuad* CopyFromAndAppendRenderPassDrawQuad(
- const RenderPassDrawQuad* quad,
- RenderPassId render_pass_id);
- DrawQuad* CopyFromAndAppendDrawQuad(const DrawQuad* quad);
-
- // Uniquely identifies the render pass in the compositor's current frame.
- RenderPassId id = 0;
-
- // These are in the space of the render pass' physical pixels.
- gfx::Rect output_rect;
- gfx::Rect damage_rect;
-
- // Transforms from the origin of the |output_rect| to the origin of the root
- // render pass' |output_rect|.
- gfx::Transform transform_to_root_target;
-
- // Post-processing filters, applied to the pixels in the render pass' texture.
- FilterOperations filters;
-
- // Post-processing filters, applied to the pixels showing through the
- // background of the render pass, from behind it.
- FilterOperations background_filters;
-
- // The color space into which content will be rendered for this render pass.
- gfx::ColorSpace color_space;
-
- // If false, the pixels in the render pass' texture are all opaque.
- bool has_transparent_background = true;
-
- // If true we might reuse the texture if there is no damage.
- bool cache_render_pass = false;
- // Indicates whether there is accumulated damage from contributing render
- // surface or layer or surface quad. Not including property changes on itself.
- bool has_damage_from_contributing_content = false;
-
- // If non-empty, the renderer should produce a copy of the render pass'
- // contents as a bitmap, and give a copy of the bitmap to each callback in
- // this list. This property should not be serialized between compositors, as
- // it only makes sense in the root compositor.
- std::vector<std::unique_ptr<viz::CopyOutputRequest>> copy_requests;
-
- QuadList quad_list;
- SharedQuadStateList shared_quad_state_list;
-
- protected:
- explicit RenderPass(size_t num_layers);
- RenderPass();
- RenderPass(size_t shared_quad_state_list_size, size_t quad_list_size);
-
- private:
- template <typename DrawQuadType>
- DrawQuadType* CopyFromAndAppendTypedDrawQuad(const DrawQuad* quad) {
- return quad_list.AllocateAndCopyFrom(DrawQuadType::MaterialCast(quad));
- }
-
- DISALLOW_COPY_AND_ASSIGN(RenderPass);
-};
-
-using RenderPassList = std::vector<std::unique_ptr<RenderPass>>;
-
-} // namespace cc
-
-#endif // CC_QUADS_RENDER_PASS_H_
diff --git a/chromium/cc/quads/render_pass_draw_quad.cc b/chromium/cc/quads/render_pass_draw_quad.cc
deleted file mode 100644
index 9a657a6ec62..00000000000
--- a/chromium/cc/quads/render_pass_draw_quad.cc
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/render_pass_draw_quad.h"
-
-#include "base/trace_event/trace_event_argument.h"
-#include "base/values.h"
-#include "cc/base/math_util.h"
-#include "components/viz/common/traced_value.h"
-#include "third_party/skia/include/core/SkImageFilter.h"
-
-namespace cc {
-
-RenderPassDrawQuad::RenderPassDrawQuad() {
-}
-
-RenderPassDrawQuad::RenderPassDrawQuad(const RenderPassDrawQuad& other) =
- default;
-
-RenderPassDrawQuad::~RenderPassDrawQuad() {
-}
-
-void RenderPassDrawQuad::SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- RenderPassId render_pass_id,
- viz::ResourceId mask_resource_id,
- const gfx::RectF& mask_uv_rect,
- const gfx::Size& mask_texture_size,
- const gfx::Vector2dF& filters_scale,
- const gfx::PointF& filters_origin,
- const gfx::RectF& tex_coord_rect) {
- DCHECK(render_pass_id);
-
- bool needs_blending = true;
- SetAll(shared_quad_state, rect, visible_rect, needs_blending, render_pass_id,
- mask_resource_id, mask_uv_rect, mask_texture_size, filters_scale,
- filters_origin, tex_coord_rect);
-}
-
-void RenderPassDrawQuad::SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- RenderPassId render_pass_id,
- viz::ResourceId mask_resource_id,
- const gfx::RectF& mask_uv_rect,
- const gfx::Size& mask_texture_size,
- const gfx::Vector2dF& filters_scale,
- const gfx::PointF& filters_origin,
- const gfx::RectF& tex_coord_rect) {
- DCHECK(render_pass_id);
-
- DrawQuad::SetAll(shared_quad_state, DrawQuad::RENDER_PASS, rect, visible_rect,
- needs_blending);
- this->render_pass_id = render_pass_id;
- resources.ids[kMaskResourceIdIndex] = mask_resource_id;
- resources.count = mask_resource_id ? 1 : 0;
- this->mask_uv_rect = mask_uv_rect;
- this->mask_texture_size = mask_texture_size;
- this->filters_scale = filters_scale;
- this->filters_origin = filters_origin;
- this->tex_coord_rect = tex_coord_rect;
-}
-
-const RenderPassDrawQuad* RenderPassDrawQuad::MaterialCast(
- const DrawQuad* quad) {
- DCHECK_EQ(quad->material, DrawQuad::RENDER_PASS);
- return static_cast<const RenderPassDrawQuad*>(quad);
-}
-
-void RenderPassDrawQuad::ExtendValue(
- base::trace_event::TracedValue* value) const {
- viz::TracedValue::SetIDRef(reinterpret_cast<void*>(render_pass_id), value,
- "render_pass_id");
- value->SetInteger("mask_resource_id", resources.ids[kMaskResourceIdIndex]);
- MathUtil::AddToTracedValue("mask_texture_size", mask_texture_size, value);
- MathUtil::AddToTracedValue("mask_uv_rect", mask_uv_rect, value);
- MathUtil::AddToTracedValue("tex_coord_rect", tex_coord_rect, value);
-}
-
-} // namespace cc
diff --git a/chromium/cc/quads/render_pass_draw_quad.h b/chromium/cc/quads/render_pass_draw_quad.h
deleted file mode 100644
index 929bf7ec81c..00000000000
--- a/chromium/cc/quads/render_pass_draw_quad.h
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_QUADS_RENDER_PASS_DRAW_QUAD_H_
-#define CC_QUADS_RENDER_PASS_DRAW_QUAD_H_
-
-#include <stddef.h>
-
-#include <memory>
-
-#include "cc/base/filter_operations.h"
-#include "cc/cc_export.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/render_pass.h"
-
-#include "ui/gfx/geometry/point_f.h"
-#include "ui/gfx/geometry/rect_f.h"
-
-namespace cc {
-
-class CC_EXPORT RenderPassDrawQuad : public DrawQuad {
- public:
- static const size_t kMaskResourceIdIndex = 0;
-
- RenderPassDrawQuad();
- RenderPassDrawQuad(const RenderPassDrawQuad& other);
- ~RenderPassDrawQuad() override;
-
- void SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- RenderPassId render_pass_id,
- viz::ResourceId mask_resource_id,
- const gfx::RectF& mask_uv_rect,
- const gfx::Size& mask_texture_size,
- const gfx::Vector2dF& filters_scale,
- const gfx::PointF& filters_origin,
- const gfx::RectF& tex_coord_rect);
-
- void SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- RenderPassId render_pass_id,
- viz::ResourceId mask_resource_id,
- const gfx::RectF& mask_uv_rect,
- const gfx::Size& mask_texture_size,
- const gfx::Vector2dF& filters_scale,
- const gfx::PointF& filters_origin,
- const gfx::RectF& tex_coord_rect);
-
- RenderPassId render_pass_id;
- gfx::RectF mask_uv_rect;
- gfx::Size mask_texture_size;
-
- // The scale from layer space of the root layer of the render pass to
- // the render pass physical pixels. This scale is applied to the filter
- // parameters for pixel-moving filters. This scale should include
- // content-to-target-space scale, and device pixel ratio.
- gfx::Vector2dF filters_scale;
-
- // The origin for post-processing filters which will be used to offset
- // crop rects, lights, etc.
- gfx::PointF filters_origin;
-
- gfx::RectF tex_coord_rect;
-
- viz::ResourceId mask_resource_id() const {
- return resources.ids[kMaskResourceIdIndex];
- }
-
- static const RenderPassDrawQuad* MaterialCast(const DrawQuad*);
-
- private:
- void ExtendValue(base::trace_event::TracedValue* value) const override;
-};
-
-} // namespace cc
-
-#endif // CC_QUADS_RENDER_PASS_DRAW_QUAD_H_
diff --git a/chromium/cc/quads/render_pass_unittest.cc b/chromium/cc/quads/render_pass_unittest.cc
deleted file mode 100644
index a73eabfa500..00000000000
--- a/chromium/cc/quads/render_pass_unittest.cc
+++ /dev/null
@@ -1,305 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/render_pass.h"
-
-#include <stddef.h>
-
-#include "base/memory/ptr_util.h"
-#include "cc/base/math_util.h"
-#include "cc/quads/render_pass_draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/test/geometry_test_utils.h"
-#include "components/viz/common/quads/copy_output_request.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/skia/include/effects/SkBlurImageFilter.h"
-#include "ui/gfx/transform.h"
-
-namespace cc {
-namespace {
-
-struct RenderPassSize {
- // If you add a new field to this class, make sure to add it to the
- // Copy() tests.
- uint64_t id;
- gfx::Rect output_rect;
- gfx::Rect damage_rect;
- gfx::Transform transform_to_root_target;
- FilterOperations filters;
- FilterOperations background_filters;
- gfx::ColorSpace color_space;
- bool has_transparent_background;
- std::vector<std::unique_ptr<viz::CopyOutputRequest>> copy_callbacks;
- QuadList quad_list;
- SharedQuadStateList shared_quad_state_list;
-};
-
-static void CompareRenderPassLists(const RenderPassList& expected_list,
- const RenderPassList& actual_list) {
- EXPECT_EQ(expected_list.size(), actual_list.size());
- for (size_t i = 0; i < actual_list.size(); ++i) {
- RenderPass* expected = expected_list[i].get();
- RenderPass* actual = actual_list[i].get();
-
- EXPECT_EQ(expected->id, actual->id);
- EXPECT_EQ(expected->output_rect, actual->output_rect);
- EXPECT_EQ(expected->transform_to_root_target,
- actual->transform_to_root_target);
- EXPECT_EQ(expected->damage_rect, actual->damage_rect);
- EXPECT_EQ(expected->filters, actual->filters);
- EXPECT_EQ(expected->background_filters, expected->background_filters);
- EXPECT_EQ(expected->has_transparent_background,
- actual->has_transparent_background);
-
- EXPECT_EQ(expected->shared_quad_state_list.size(),
- actual->shared_quad_state_list.size());
- EXPECT_EQ(expected->quad_list.size(), actual->quad_list.size());
-
- for (auto exp_iter = expected->quad_list.cbegin(),
- act_iter = actual->quad_list.cbegin();
- exp_iter != expected->quad_list.cend();
- ++exp_iter, ++act_iter) {
- EXPECT_EQ(exp_iter->rect.ToString(), act_iter->rect.ToString());
- EXPECT_EQ(exp_iter->shared_quad_state->quad_layer_rect.ToString(),
- act_iter->shared_quad_state->quad_layer_rect.ToString());
- }
- }
-}
-
-TEST(RenderPassTest, CopyShouldBeIdenticalExceptIdAndQuads) {
- RenderPassId render_pass_id = 3u;
- gfx::Rect output_rect(45, 22, 120, 13);
- gfx::Transform transform_to_root =
- gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0);
- gfx::Rect damage_rect(56, 123, 19, 43);
- FilterOperations filters;
- filters.Append(FilterOperation::CreateOpacityFilter(0.5));
- FilterOperations background_filters;
- background_filters.Append(FilterOperation::CreateInvertFilter(1.0));
- gfx::ColorSpace color_space = gfx::ColorSpace::CreateSRGB();
- bool has_transparent_background = true;
- bool cache_render_pass = false;
- bool has_damage_from_contributing_content = false;
-
- std::unique_ptr<RenderPass> pass = RenderPass::Create();
- pass->SetAll(render_pass_id, output_rect, damage_rect, transform_to_root,
- filters, background_filters, color_space,
- has_transparent_background, cache_render_pass,
- has_damage_from_contributing_content);
- pass->copy_requests.push_back(viz::CopyOutputRequest::CreateEmptyRequest());
-
- // Stick a quad in the pass, this should not get copied.
- viz::SharedQuadState* shared_state = pass->CreateAndAppendSharedQuadState();
- shared_state->SetAll(gfx::Transform(), gfx::Rect(), gfx::Rect(), gfx::Rect(),
- false, 1, SkBlendMode::kSrcOver, 0);
-
- SolidColorDrawQuad* color_quad =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->SetNew(pass->shared_quad_state_list.back(), gfx::Rect(),
- gfx::Rect(), SkColor(), false);
-
- RenderPassId new_render_pass_id = 63u;
-
- std::unique_ptr<RenderPass> copy = pass->Copy(new_render_pass_id);
- EXPECT_EQ(new_render_pass_id, copy->id);
- EXPECT_EQ(pass->output_rect, copy->output_rect);
- EXPECT_EQ(pass->transform_to_root_target, copy->transform_to_root_target);
- EXPECT_EQ(pass->damage_rect, copy->damage_rect);
- EXPECT_EQ(pass->filters, copy->filters);
- EXPECT_EQ(pass->background_filters, copy->background_filters);
- EXPECT_EQ(pass->has_transparent_background, copy->has_transparent_background);
- EXPECT_EQ(0u, copy->quad_list.size());
-
- // The copy request should not be copied/duplicated.
- EXPECT_EQ(1u, pass->copy_requests.size());
- EXPECT_EQ(0u, copy->copy_requests.size());
-
- EXPECT_EQ(sizeof(RenderPassSize), sizeof(RenderPass));
-}
-
-TEST(RenderPassTest, CopyAllShouldBeIdentical) {
- RenderPassList pass_list;
-
- int id = 3;
- gfx::Rect output_rect(45, 22, 120, 13);
- gfx::Transform transform_to_root =
- gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0);
- gfx::Rect damage_rect(56, 123, 19, 43);
- FilterOperations filters;
- filters.Append(FilterOperation::CreateOpacityFilter(0.5));
- FilterOperations background_filters;
- background_filters.Append(FilterOperation::CreateInvertFilter(1.0));
- gfx::ColorSpace color_space = gfx::ColorSpace::CreateXYZD50();
- bool has_transparent_background = true;
- bool cache_render_pass = false;
- bool has_damage_from_contributing_content = false;
-
- std::unique_ptr<RenderPass> pass = RenderPass::Create();
- pass->SetAll(id, output_rect, damage_rect, transform_to_root, filters,
- background_filters, color_space, has_transparent_background,
- cache_render_pass, has_damage_from_contributing_content);
-
- // Two quads using one shared state.
- viz::SharedQuadState* shared_state1 = pass->CreateAndAppendSharedQuadState();
- shared_state1->SetAll(gfx::Transform(), gfx::Rect(0, 0, 1, 1), gfx::Rect(),
- gfx::Rect(), false, 1, SkBlendMode::kSrcOver, 0);
-
- SolidColorDrawQuad* color_quad1 =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad1->SetNew(pass->shared_quad_state_list.back(),
- gfx::Rect(1, 1, 1, 1), gfx::Rect(1, 1, 1, 1), SkColor(),
- false);
-
- SolidColorDrawQuad* color_quad2 =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad2->SetNew(pass->shared_quad_state_list.back(),
- gfx::Rect(2, 2, 2, 2), gfx::Rect(2, 2, 2, 2), SkColor(),
- false);
-
- // And two quads using another shared state.
- viz::SharedQuadState* shared_state2 = pass->CreateAndAppendSharedQuadState();
- shared_state2->SetAll(gfx::Transform(), gfx::Rect(0, 0, 2, 2), gfx::Rect(),
- gfx::Rect(), false, 1, SkBlendMode::kSrcOver, 0);
-
- SolidColorDrawQuad* color_quad3 =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad3->SetNew(pass->shared_quad_state_list.back(),
- gfx::Rect(3, 3, 3, 3), gfx::Rect(3, 3, 3, 3), SkColor(),
- false);
-
- SolidColorDrawQuad* color_quad4 =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad4->SetNew(pass->shared_quad_state_list.back(),
- gfx::Rect(4, 4, 4, 4), gfx::Rect(4, 4, 4, 4), SkColor(),
- false);
-
- // A second render pass with a quad.
- int contrib_id = 4;
- gfx::Rect contrib_output_rect(10, 15, 12, 17);
- gfx::Transform contrib_transform_to_root =
- gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0);
- gfx::Rect contrib_damage_rect(11, 16, 10, 15);
- FilterOperations contrib_filters;
- contrib_filters.Append(FilterOperation::CreateSepiaFilter(0.5));
- FilterOperations contrib_background_filters;
- contrib_background_filters.Append(FilterOperation::CreateSaturateFilter(1));
- gfx::ColorSpace contrib_color_space = gfx::ColorSpace::CreateSCRGBLinear();
- bool contrib_has_transparent_background = true;
- bool contrib_cache_render_pass = false;
- bool contrib_has_damage_from_contributing_content = false;
-
- std::unique_ptr<RenderPass> contrib = RenderPass::Create();
- contrib->SetAll(contrib_id, contrib_output_rect, contrib_damage_rect,
- contrib_transform_to_root, contrib_filters,
- contrib_background_filters, contrib_color_space,
- contrib_has_transparent_background, contrib_cache_render_pass,
- contrib_has_damage_from_contributing_content);
-
- viz::SharedQuadState* contrib_shared_state =
- contrib->CreateAndAppendSharedQuadState();
- contrib_shared_state->SetAll(gfx::Transform(), gfx::Rect(0, 0, 2, 2),
- gfx::Rect(), gfx::Rect(), false, 1,
- SkBlendMode::kSrcOver, 0);
-
- SolidColorDrawQuad* contrib_quad =
- contrib->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- contrib_quad->SetNew(contrib->shared_quad_state_list.back(),
- gfx::Rect(3, 3, 3, 3), gfx::Rect(3, 3, 3, 3), SkColor(),
- false);
-
- // And a RenderPassDrawQuad for the contributing pass.
- std::unique_ptr<RenderPassDrawQuad> pass_quad =
- base::WrapUnique(new RenderPassDrawQuad);
- pass_quad->SetNew(pass->shared_quad_state_list.back(), contrib_output_rect,
- contrib_output_rect, contrib_id, 0, gfx::RectF(),
- gfx::Size(), gfx::Vector2dF(), gfx::PointF(), gfx::RectF());
-
- pass_list.push_back(std::move(pass));
- pass_list.push_back(std::move(contrib));
-
- // Make a copy with CopyAll().
- RenderPassList copy_list;
- RenderPass::CopyAll(pass_list, &copy_list);
-
- CompareRenderPassLists(pass_list, copy_list);
-}
-
-TEST(RenderPassTest, CopyAllWithCulledQuads) {
- RenderPassList pass_list;
-
- int id = 3;
- gfx::Rect output_rect(45, 22, 120, 13);
- gfx::Transform transform_to_root =
- gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0);
- gfx::Rect damage_rect(56, 123, 19, 43);
- FilterOperations filters;
- filters.Append(FilterOperation::CreateOpacityFilter(0.5));
- FilterOperations background_filters;
- background_filters.Append(FilterOperation::CreateInvertFilter(1.0));
- gfx::ColorSpace color_space = gfx::ColorSpace::CreateSCRGBLinear();
- bool has_transparent_background = true;
- bool cache_render_pass = false;
- bool has_damage_from_contributing_content = false;
-
- std::unique_ptr<RenderPass> pass = RenderPass::Create();
- pass->SetAll(id, output_rect, damage_rect, transform_to_root, filters,
- background_filters, color_space, has_transparent_background,
- cache_render_pass, has_damage_from_contributing_content);
-
- // A shared state with a quad.
- viz::SharedQuadState* shared_state1 = pass->CreateAndAppendSharedQuadState();
- shared_state1->SetAll(gfx::Transform(), gfx::Rect(0, 0, 1, 1), gfx::Rect(),
- gfx::Rect(), false, 1, SkBlendMode::kSrcOver, 0);
-
- SolidColorDrawQuad* color_quad1 =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad1->SetNew(pass->shared_quad_state_list.back(),
- gfx::Rect(1, 1, 1, 1), gfx::Rect(1, 1, 1, 1), SkColor(),
- false);
-
- // A shared state with no quads, they were culled.
- viz::SharedQuadState* shared_state2 = pass->CreateAndAppendSharedQuadState();
- shared_state2->SetAll(gfx::Transform(), gfx::Rect(0, 0, 2, 2), gfx::Rect(),
- gfx::Rect(), false, 1, SkBlendMode::kSrcOver, 0);
-
- // A second shared state with no quads.
- viz::SharedQuadState* shared_state3 = pass->CreateAndAppendSharedQuadState();
- shared_state3->SetAll(gfx::Transform(), gfx::Rect(0, 0, 2, 2), gfx::Rect(),
- gfx::Rect(), false, 1, SkBlendMode::kSrcOver, 0);
-
- // A last shared state with a quad again.
- viz::SharedQuadState* shared_state4 = pass->CreateAndAppendSharedQuadState();
- shared_state4->SetAll(gfx::Transform(), gfx::Rect(0, 0, 2, 2), gfx::Rect(),
- gfx::Rect(), false, 1, SkBlendMode::kSrcOver, 0);
-
- SolidColorDrawQuad* color_quad2 =
- pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad2->SetNew(pass->shared_quad_state_list.back(),
- gfx::Rect(3, 3, 3, 3), gfx::Rect(3, 3, 3, 3), SkColor(),
- false);
-
- pass_list.push_back(std::move(pass));
-
- // Make a copy with CopyAll().
- RenderPassList copy_list;
- RenderPass::CopyAll(pass_list, &copy_list);
-
- CompareRenderPassLists(pass_list, copy_list);
-}
-
-TEST(RenderPassTest, ReplacedQuadsShouldntMove) {
- std::unique_ptr<viz::SharedQuadState> quad_state =
- std::make_unique<viz::SharedQuadState>();
- QuadList quad_list;
- SolidColorDrawQuad* quad =
- quad_list.AllocateAndConstruct<SolidColorDrawQuad>();
- gfx::Rect quad_rect(1, 2, 3, 4);
- quad->SetNew(quad_state.get(), quad_rect, quad_rect, SkColor(), false);
- quad_list.ReplaceExistingQuadWithOpaqueTransparentSolidColor(
- quad_list.begin());
- EXPECT_EQ(quad_list.begin()->rect, quad_rect);
-}
-
-} // namespace
-} // namespace cc
diff --git a/chromium/cc/quads/solid_color_draw_quad.cc b/chromium/cc/quads/solid_color_draw_quad.cc
deleted file mode 100644
index 03a82afa834..00000000000
--- a/chromium/cc/quads/solid_color_draw_quad.cc
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/solid_color_draw_quad.h"
-
-#include "base/logging.h"
-#include "base/trace_event/trace_event_argument.h"
-#include "base/values.h"
-
-namespace cc {
-
-SolidColorDrawQuad::SolidColorDrawQuad()
- : color(0), force_anti_aliasing_off(false) {}
-
-void SolidColorDrawQuad::SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- SkColor color,
- bool force_anti_aliasing_off) {
- bool needs_blending = SkColorGetA(color) != 255;
- DrawQuad::SetAll(shared_quad_state, DrawQuad::SOLID_COLOR, rect, visible_rect,
- needs_blending);
- this->color = color;
- this->force_anti_aliasing_off = force_anti_aliasing_off;
-}
-
-void SolidColorDrawQuad::SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- SkColor color,
- bool force_anti_aliasing_off) {
- DrawQuad::SetAll(shared_quad_state, DrawQuad::SOLID_COLOR, rect, visible_rect,
- needs_blending);
- this->color = color;
- this->force_anti_aliasing_off = force_anti_aliasing_off;
-}
-
-const SolidColorDrawQuad* SolidColorDrawQuad::MaterialCast(
- const DrawQuad* quad) {
- DCHECK(quad->material == DrawQuad::SOLID_COLOR);
- return static_cast<const SolidColorDrawQuad*>(quad);
-}
-
-void SolidColorDrawQuad::ExtendValue(
- base::trace_event::TracedValue* value) const {
- value->SetInteger("color", color);
- value->SetBoolean("force_anti_aliasing_off", force_anti_aliasing_off);
-}
-
-} // namespace cc
diff --git a/chromium/cc/quads/solid_color_draw_quad.h b/chromium/cc/quads/solid_color_draw_quad.h
deleted file mode 100644
index 75f7e97c45a..00000000000
--- a/chromium/cc/quads/solid_color_draw_quad.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_QUADS_SOLID_COLOR_DRAW_QUAD_H_
-#define CC_QUADS_SOLID_COLOR_DRAW_QUAD_H_
-
-#include <memory>
-
-#include "cc/cc_export.h"
-#include "cc/quads/draw_quad.h"
-#include "third_party/skia/include/core/SkColor.h"
-
-namespace cc {
-
-class CC_EXPORT SolidColorDrawQuad : public DrawQuad {
- public:
- SolidColorDrawQuad();
-
- void SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- SkColor color,
- bool force_anti_aliasing_off);
-
- void SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- SkColor color,
- bool force_anti_aliasing_off);
-
- SkColor color;
- bool force_anti_aliasing_off;
-
- static const SolidColorDrawQuad* MaterialCast(const DrawQuad*);
-
- private:
- void ExtendValue(base::trace_event::TracedValue* value) const override;
-};
-
-} // namespace cc
-
-#endif // CC_QUADS_SOLID_COLOR_DRAW_QUAD_H_
diff --git a/chromium/cc/quads/stream_video_draw_quad.cc b/chromium/cc/quads/stream_video_draw_quad.cc
deleted file mode 100644
index 08fc1f55d35..00000000000
--- a/chromium/cc/quads/stream_video_draw_quad.cc
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/stream_video_draw_quad.h"
-
-#include "base/logging.h"
-#include "base/trace_event/trace_event_argument.h"
-#include "base/values.h"
-#include "cc/base/math_util.h"
-
-namespace cc {
-
-StreamVideoDrawQuad::StreamVideoDrawQuad() {
-}
-
-void StreamVideoDrawQuad::SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- unsigned resource_id,
- gfx::Size resource_size_in_pixels,
- const gfx::Transform& matrix) {
- DrawQuad::SetAll(shared_quad_state, DrawQuad::STREAM_VIDEO_CONTENT, rect,
- visible_rect, needs_blending);
- resources.ids[kResourceIdIndex] = resource_id;
- overlay_resources.size_in_pixels[kResourceIdIndex] = resource_size_in_pixels;
- resources.count = 1;
- this->matrix = matrix;
-}
-
-void StreamVideoDrawQuad::SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- unsigned resource_id,
- gfx::Size resource_size_in_pixels,
- const gfx::Transform& matrix) {
- DrawQuad::SetAll(shared_quad_state, DrawQuad::STREAM_VIDEO_CONTENT, rect,
- visible_rect, needs_blending);
- resources.ids[kResourceIdIndex] = resource_id;
- overlay_resources.size_in_pixels[kResourceIdIndex] = resource_size_in_pixels;
- resources.count = 1;
- this->matrix = matrix;
-}
-
-const StreamVideoDrawQuad* StreamVideoDrawQuad::MaterialCast(
- const DrawQuad* quad) {
- DCHECK(quad->material == DrawQuad::STREAM_VIDEO_CONTENT);
- return static_cast<const StreamVideoDrawQuad*>(quad);
-}
-
-void StreamVideoDrawQuad::ExtendValue(
- base::trace_event::TracedValue* value) const {
- value->SetInteger("resource_id", resources.ids[kResourceIdIndex]);
- MathUtil::AddToTracedValue("matrix", matrix, value);
-}
-
-StreamVideoDrawQuad::OverlayResources::OverlayResources() {
-}
-
-} // namespace cc
diff --git a/chromium/cc/quads/stream_video_draw_quad.h b/chromium/cc/quads/stream_video_draw_quad.h
deleted file mode 100644
index 44a2013f949..00000000000
--- a/chromium/cc/quads/stream_video_draw_quad.h
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_QUADS_STREAM_VIDEO_DRAW_QUAD_H_
-#define CC_QUADS_STREAM_VIDEO_DRAW_QUAD_H_
-
-#include <stddef.h>
-
-#include <memory>
-
-#include "cc/cc_export.h"
-#include "cc/quads/draw_quad.h"
-#include "ui/gfx/transform.h"
-
-namespace cc {
-
-class CC_EXPORT StreamVideoDrawQuad : public DrawQuad {
- public:
- static const size_t kResourceIdIndex = 0;
-
- StreamVideoDrawQuad();
-
- void SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- unsigned resource_id,
- gfx::Size resource_size_in_pixels,
- const gfx::Transform& matrix);
-
- void SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- unsigned resource_id,
- gfx::Size resource_size_in_pixels,
- const gfx::Transform& matrix);
-
- gfx::Transform matrix;
-
- struct OverlayResources {
- OverlayResources();
- gfx::Size size_in_pixels[Resources::kMaxResourceIdCount];
- };
- OverlayResources overlay_resources;
-
- static const StreamVideoDrawQuad* MaterialCast(const DrawQuad*);
-
- viz::ResourceId resource_id() const {
- return resources.ids[kResourceIdIndex];
- }
- const gfx::Size& resource_size_in_pixels() const {
- return overlay_resources.size_in_pixels[kResourceIdIndex];
- }
-
- private:
- void ExtendValue(base::trace_event::TracedValue* value) const override;
-};
-
-} // namespace cc
-
-#endif // CC_QUADS_STREAM_VIDEO_DRAW_QUAD_H_
diff --git a/chromium/cc/quads/surface_draw_quad.cc b/chromium/cc/quads/surface_draw_quad.cc
deleted file mode 100644
index 03ddfbf4466..00000000000
--- a/chromium/cc/quads/surface_draw_quad.cc
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/surface_draw_quad.h"
-
-#include "base/logging.h"
-#include "base/trace_event/trace_event_argument.h"
-#include "base/values.h"
-
-namespace cc {
-
-SurfaceDrawQuad::SurfaceDrawQuad() {
-}
-
-void SurfaceDrawQuad::SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- const viz::SurfaceId& surface_id,
- SurfaceDrawQuadType surface_draw_quad_type,
- SurfaceDrawQuad* fallback_quad) {
- bool needs_blending = true;
- DrawQuad::SetAll(shared_quad_state, DrawQuad::SURFACE_CONTENT, rect,
- visible_rect, needs_blending);
- this->surface_id = surface_id;
- this->surface_draw_quad_type = surface_draw_quad_type;
- this->fallback_quad = fallback_quad;
-}
-
-void SurfaceDrawQuad::SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- const viz::SurfaceId& surface_id,
- SurfaceDrawQuadType surface_draw_quad_type,
- SurfaceDrawQuad* fallback_quad) {
- DrawQuad::SetAll(shared_quad_state, DrawQuad::SURFACE_CONTENT, rect,
- visible_rect, needs_blending);
- this->surface_id = surface_id;
- this->surface_draw_quad_type = surface_draw_quad_type;
- this->fallback_quad = fallback_quad;
-}
-
-const SurfaceDrawQuad* SurfaceDrawQuad::MaterialCast(const DrawQuad* quad) {
- DCHECK_EQ(quad->material, DrawQuad::SURFACE_CONTENT);
- return static_cast<const SurfaceDrawQuad*>(quad);
-}
-
-void SurfaceDrawQuad::ExtendValue(base::trace_event::TracedValue* value) const {
- value->SetString("surface_id", surface_id.ToString());
-}
-
-
-} // namespace cc
diff --git a/chromium/cc/quads/surface_draw_quad.h b/chromium/cc/quads/surface_draw_quad.h
deleted file mode 100644
index bcab58e115e..00000000000
--- a/chromium/cc/quads/surface_draw_quad.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_QUADS_SURFACE_DRAW_QUAD_H_
-#define CC_QUADS_SURFACE_DRAW_QUAD_H_
-
-#include <memory>
-
-#include "cc/cc_export.h"
-#include "cc/quads/draw_quad.h"
-#include "components/viz/common/surfaces/surface_id.h"
-
-namespace cc {
-
-enum class SurfaceDrawQuadType { PRIMARY, FALLBACK, LAST = FALLBACK };
-
-class CC_EXPORT SurfaceDrawQuad : public DrawQuad {
- public:
- SurfaceDrawQuad();
-
- void SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- const viz::SurfaceId& surface_id,
- SurfaceDrawQuadType surface_draw_quad_type,
- SurfaceDrawQuad* fallback_quad);
-
- void SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- const viz::SurfaceId& surface_id,
- SurfaceDrawQuadType surface_draw_quad_type,
- SurfaceDrawQuad* fallback_quad);
-
- viz::SurfaceId surface_id;
- SurfaceDrawQuadType surface_draw_quad_type;
- const SurfaceDrawQuad* fallback_quad = nullptr;
-
- static const SurfaceDrawQuad* MaterialCast(const DrawQuad* quad);
-
- private:
- void ExtendValue(base::trace_event::TracedValue* value) const override;
-};
-
-} // namespace cc
-
-#endif // CC_QUADS_SURFACE_DRAW_QUAD_H_
diff --git a/chromium/cc/quads/texture_draw_quad.cc b/chromium/cc/quads/texture_draw_quad.cc
deleted file mode 100644
index 2f1bfad1a52..00000000000
--- a/chromium/cc/quads/texture_draw_quad.cc
+++ /dev/null
@@ -1,121 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/texture_draw_quad.h"
-
-#include <stddef.h>
-
-#include "base/logging.h"
-#include "base/trace_event/trace_event_argument.h"
-#include "base/values.h"
-#include "cc/base/math_util.h"
-#include "ui/gfx/geometry/vector2d_f.h"
-
-namespace cc {
-
-TextureDrawQuad::TextureDrawQuad()
- : premultiplied_alpha(false),
- background_color(SK_ColorTRANSPARENT),
- y_flipped(false),
- nearest_neighbor(false) {
- this->vertex_opacity[0] = 0.f;
- this->vertex_opacity[1] = 0.f;
- this->vertex_opacity[2] = 0.f;
- this->vertex_opacity[3] = 0.f;
-}
-
-TextureDrawQuad::TextureDrawQuad(const TextureDrawQuad& other) = default;
-
-void TextureDrawQuad::SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- unsigned resource_id,
- bool premultiplied_alpha,
- const gfx::PointF& uv_top_left,
- const gfx::PointF& uv_bottom_right,
- SkColor background_color,
- const float vertex_opacity[4],
- bool y_flipped,
- bool nearest_neighbor,
- bool secure_output_only) {
- needs_blending = needs_blending || vertex_opacity[0] != 1.0f ||
- vertex_opacity[1] != 1.0f || vertex_opacity[2] != 1.0f ||
- vertex_opacity[3] != 1.0f;
- DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect,
- visible_rect, needs_blending);
- resources.ids[kResourceIdIndex] = resource_id;
- resources.count = 1;
- this->premultiplied_alpha = premultiplied_alpha;
- this->uv_top_left = uv_top_left;
- this->uv_bottom_right = uv_bottom_right;
- this->background_color = background_color;
- this->vertex_opacity[0] = vertex_opacity[0];
- this->vertex_opacity[1] = vertex_opacity[1];
- this->vertex_opacity[2] = vertex_opacity[2];
- this->vertex_opacity[3] = vertex_opacity[3];
- this->y_flipped = y_flipped;
- this->nearest_neighbor = nearest_neighbor;
- this->secure_output_only = secure_output_only;
-}
-
-void TextureDrawQuad::SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- unsigned resource_id,
- gfx::Size resource_size_in_pixels,
- bool premultiplied_alpha,
- const gfx::PointF& uv_top_left,
- const gfx::PointF& uv_bottom_right,
- SkColor background_color,
- const float vertex_opacity[4],
- bool y_flipped,
- bool nearest_neighbor,
- bool secure_output_only) {
- DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect,
- visible_rect, needs_blending);
- resources.ids[kResourceIdIndex] = resource_id;
- overlay_resources.size_in_pixels[kResourceIdIndex] = resource_size_in_pixels;
- resources.count = 1;
- this->premultiplied_alpha = premultiplied_alpha;
- this->uv_top_left = uv_top_left;
- this->uv_bottom_right = uv_bottom_right;
- this->background_color = background_color;
- this->vertex_opacity[0] = vertex_opacity[0];
- this->vertex_opacity[1] = vertex_opacity[1];
- this->vertex_opacity[2] = vertex_opacity[2];
- this->vertex_opacity[3] = vertex_opacity[3];
- this->y_flipped = y_flipped;
- this->nearest_neighbor = nearest_neighbor;
- this->secure_output_only = secure_output_only;
-}
-
-const TextureDrawQuad* TextureDrawQuad::MaterialCast(const DrawQuad* quad) {
- DCHECK(quad->material == DrawQuad::TEXTURE_CONTENT);
- return static_cast<const TextureDrawQuad*>(quad);
-}
-
-void TextureDrawQuad::ExtendValue(base::trace_event::TracedValue* value) const {
- value->SetInteger("resource_id", resources.ids[kResourceIdIndex]);
- value->SetBoolean("premultiplied_alpha", premultiplied_alpha);
-
- MathUtil::AddToTracedValue("uv_top_left", uv_top_left, value);
- MathUtil::AddToTracedValue("uv_bottom_right", uv_bottom_right, value);
-
- value->SetInteger("background_color", background_color);
-
- value->BeginArray("vertex_opacity");
- for (size_t i = 0; i < 4; ++i)
- value->AppendDouble(vertex_opacity[i]);
- value->EndArray();
-
- value->SetBoolean("y_flipped", y_flipped);
- value->SetBoolean("nearest_neighbor", nearest_neighbor);
-}
-
-TextureDrawQuad::OverlayResources::OverlayResources() {
-}
-
-} // namespace cc
diff --git a/chromium/cc/quads/texture_draw_quad.h b/chromium/cc/quads/texture_draw_quad.h
deleted file mode 100644
index c2f4b6ec319..00000000000
--- a/chromium/cc/quads/texture_draw_quad.h
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_QUADS_TEXTURE_DRAW_QUAD_H_
-#define CC_QUADS_TEXTURE_DRAW_QUAD_H_
-
-#include <stddef.h>
-
-#include <memory>
-
-#include "cc/cc_export.h"
-#include "cc/quads/draw_quad.h"
-#include "third_party/skia/include/core/SkColor.h"
-#include "ui/gfx/geometry/rect_f.h"
-
-namespace cc {
-
-class CC_EXPORT TextureDrawQuad : public DrawQuad {
- public:
- static const size_t kResourceIdIndex = 0;
-
- TextureDrawQuad();
- TextureDrawQuad(const TextureDrawQuad& other);
-
- void SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- unsigned resource_id,
- bool premultiplied_alpha,
- const gfx::PointF& uv_top_left,
- const gfx::PointF& uv_bottom_right,
- SkColor background_color,
- const float vertex_opacity[4],
- bool y_flipped,
- bool nearest_neighbor,
- bool secure_output_only);
-
- void SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- unsigned resource_id,
- gfx::Size resource_size_in_pixels,
- bool premultiplied_alpha,
- const gfx::PointF& uv_top_left,
- const gfx::PointF& uv_bottom_right,
- SkColor background_color,
- const float vertex_opacity[4],
- bool y_flipped,
- bool nearest_neighbor,
- bool secure_output_only);
-
- bool premultiplied_alpha;
- gfx::PointF uv_top_left;
- gfx::PointF uv_bottom_right;
- SkColor background_color;
- float vertex_opacity[4];
- bool y_flipped;
- bool nearest_neighbor;
- bool secure_output_only = false;
-
- struct OverlayResources {
- OverlayResources();
-
- gfx::Size size_in_pixels[Resources::kMaxResourceIdCount];
- };
- OverlayResources overlay_resources;
-
- viz::ResourceId resource_id() const {
- return resources.ids[kResourceIdIndex];
- }
- const gfx::Size& resource_size_in_pixels() const {
- return overlay_resources.size_in_pixels[kResourceIdIndex];
- }
- void set_resource_size_in_pixels(const gfx::Size& size_in_pixels) {
- overlay_resources.size_in_pixels[kResourceIdIndex] = size_in_pixels;
- }
-
- static const TextureDrawQuad* MaterialCast(const DrawQuad*);
-
- private:
- void ExtendValue(base::trace_event::TracedValue* value) const override;
-};
-
-} // namespace cc
-
-#endif // CC_QUADS_TEXTURE_DRAW_QUAD_H_
diff --git a/chromium/cc/quads/tile_draw_quad.cc b/chromium/cc/quads/tile_draw_quad.cc
deleted file mode 100644
index 1ac34fbbc8a..00000000000
--- a/chromium/cc/quads/tile_draw_quad.cc
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/tile_draw_quad.h"
-
-#include "base/logging.h"
-#include "base/trace_event/trace_event_argument.h"
-#include "base/values.h"
-
-namespace cc {
-
-TileDrawQuad::TileDrawQuad() {
-}
-
-TileDrawQuad::~TileDrawQuad() {
-}
-
-void TileDrawQuad::SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- unsigned resource_id,
- const gfx::RectF& tex_coord_rect,
- const gfx::Size& texture_size,
- bool swizzle_contents,
- bool nearest_neighbor) {
- ContentDrawQuadBase::SetNew(shared_quad_state, DrawQuad::TILED_CONTENT, rect,
- visible_rect, needs_blending, tex_coord_rect,
- texture_size, swizzle_contents, nearest_neighbor);
- resources.ids[kResourceIdIndex] = resource_id;
- resources.count = 1;
-}
-
-void TileDrawQuad::SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- unsigned resource_id,
- const gfx::RectF& tex_coord_rect,
- const gfx::Size& texture_size,
- bool swizzle_contents,
- bool nearest_neighbor) {
- ContentDrawQuadBase::SetAll(shared_quad_state, DrawQuad::TILED_CONTENT, rect,
- visible_rect, needs_blending, tex_coord_rect,
- texture_size, swizzle_contents, nearest_neighbor);
- resources.ids[kResourceIdIndex] = resource_id;
- resources.count = 1;
-}
-
-const TileDrawQuad* TileDrawQuad::MaterialCast(const DrawQuad* quad) {
- DCHECK(quad->material == DrawQuad::TILED_CONTENT);
- return static_cast<const TileDrawQuad*>(quad);
-}
-
-void TileDrawQuad::ExtendValue(base::trace_event::TracedValue* value) const {
- ContentDrawQuadBase::ExtendValue(value);
- value->SetInteger("resource_id", resources.ids[kResourceIdIndex]);
-}
-
-} // namespace cc
diff --git a/chromium/cc/quads/tile_draw_quad.h b/chromium/cc/quads/tile_draw_quad.h
deleted file mode 100644
index 1c490f34ef6..00000000000
--- a/chromium/cc/quads/tile_draw_quad.h
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_QUADS_TILE_DRAW_QUAD_H_
-#define CC_QUADS_TILE_DRAW_QUAD_H_
-
-#include <stddef.h>
-
-#include "cc/quads/content_draw_quad_base.h"
-
-namespace cc {
-
-class CC_EXPORT TileDrawQuad : public ContentDrawQuadBase {
- public:
- static const size_t kResourceIdIndex = 0;
-
- TileDrawQuad();
- ~TileDrawQuad() override;
-
- void SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- unsigned resource_id,
- // |tex_coord_rect| contains non-normalized coordinates.
- // TODO(reveman): Make the use of normalized vs non-normalized
- // coordinates consistent across all quad types: crbug.com/487370
- const gfx::RectF& tex_coord_rect,
- const gfx::Size& texture_size,
- bool swizzle_contents,
- bool nearest_neighbor);
-
- void SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- unsigned resource_id,
- // |tex_coord_rect| contains non-normalized coordinates.
- // TODO(reveman): Make the use of normalized vs non-normalized
- // coordinates consistent across all quad types: crbug.com/487370
- const gfx::RectF& tex_coord_rect,
- const gfx::Size& texture_size,
- bool swizzle_contents,
- bool nearest_neighbor);
-
- static const TileDrawQuad* MaterialCast(const DrawQuad*);
-
- viz::ResourceId resource_id() const {
- return resources.ids[kResourceIdIndex];
- }
-
- private:
- void ExtendValue(base::trace_event::TracedValue* value) const override;
-};
-
-} // namespace cc
-
-#endif // CC_QUADS_TILE_DRAW_QUAD_H_
diff --git a/chromium/cc/quads/yuv_video_draw_quad.cc b/chromium/cc/quads/yuv_video_draw_quad.cc
deleted file mode 100644
index d666030b591..00000000000
--- a/chromium/cc/quads/yuv_video_draw_quad.cc
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/quads/yuv_video_draw_quad.h"
-
-#include "base/logging.h"
-#include "base/trace_event/trace_event_argument.h"
-#include "base/values.h"
-#include "cc/base/math_util.h"
-
-namespace cc {
-
-YUVVideoDrawQuad::YUVVideoDrawQuad() {
-}
-
-YUVVideoDrawQuad::YUVVideoDrawQuad(const YUVVideoDrawQuad& other) = default;
-
-YUVVideoDrawQuad::~YUVVideoDrawQuad() {}
-
-void YUVVideoDrawQuad::SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- const gfx::RectF& ya_tex_coord_rect,
- const gfx::RectF& uv_tex_coord_rect,
- const gfx::Size& ya_tex_size,
- const gfx::Size& uv_tex_size,
- unsigned y_plane_resource_id,
- unsigned u_plane_resource_id,
- unsigned v_plane_resource_id,
- unsigned a_plane_resource_id,
- ColorSpace color_space,
- const gfx::ColorSpace& video_color_space,
- float offset,
- float multiplier,
- uint32_t bits_per_channel) {
- DrawQuad::SetAll(shared_quad_state, DrawQuad::YUV_VIDEO_CONTENT, rect,
- visible_rect, needs_blending);
- this->ya_tex_coord_rect = ya_tex_coord_rect;
- this->uv_tex_coord_rect = uv_tex_coord_rect;
- this->ya_tex_size = ya_tex_size;
- this->uv_tex_size = uv_tex_size;
- resources.ids[kYPlaneResourceIdIndex] = y_plane_resource_id;
- resources.ids[kUPlaneResourceIdIndex] = u_plane_resource_id;
- resources.ids[kVPlaneResourceIdIndex] = v_plane_resource_id;
- resources.ids[kAPlaneResourceIdIndex] = a_plane_resource_id;
- resources.count = a_plane_resource_id ? 4 : 3;
- this->color_space = color_space;
- this->video_color_space = video_color_space;
- this->resource_offset = offset;
- this->resource_multiplier = multiplier;
- this->bits_per_channel = bits_per_channel;
-}
-
-void YUVVideoDrawQuad::SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- const gfx::RectF& ya_tex_coord_rect,
- const gfx::RectF& uv_tex_coord_rect,
- const gfx::Size& ya_tex_size,
- const gfx::Size& uv_tex_size,
- unsigned y_plane_resource_id,
- unsigned u_plane_resource_id,
- unsigned v_plane_resource_id,
- unsigned a_plane_resource_id,
- ColorSpace color_space,
- const gfx::ColorSpace& video_color_space,
- float offset,
- float multiplier,
- uint32_t bits_per_channel,
- bool require_overlay) {
- DrawQuad::SetAll(shared_quad_state, DrawQuad::YUV_VIDEO_CONTENT, rect,
- visible_rect, needs_blending);
- this->ya_tex_coord_rect = ya_tex_coord_rect;
- this->uv_tex_coord_rect = uv_tex_coord_rect;
- this->ya_tex_size = ya_tex_size;
- this->uv_tex_size = uv_tex_size;
- resources.ids[kYPlaneResourceIdIndex] = y_plane_resource_id;
- resources.ids[kUPlaneResourceIdIndex] = u_plane_resource_id;
- resources.ids[kVPlaneResourceIdIndex] = v_plane_resource_id;
- resources.ids[kAPlaneResourceIdIndex] = a_plane_resource_id;
- resources.count = resources.ids[kAPlaneResourceIdIndex] ? 4 : 3;
- this->color_space = color_space;
- this->video_color_space = video_color_space;
- this->resource_offset = offset;
- this->resource_multiplier = multiplier;
- this->bits_per_channel = bits_per_channel;
- this->require_overlay = require_overlay;
-}
-
-const YUVVideoDrawQuad* YUVVideoDrawQuad::MaterialCast(
- const DrawQuad* quad) {
- DCHECK(quad->material == DrawQuad::YUV_VIDEO_CONTENT);
- return static_cast<const YUVVideoDrawQuad*>(quad);
-}
-
-void YUVVideoDrawQuad::ExtendValue(
- base::trace_event::TracedValue* value) const {
- MathUtil::AddToTracedValue("ya_tex_coord_rect", ya_tex_coord_rect, value);
- MathUtil::AddToTracedValue("uv_tex_coord_rect", uv_tex_coord_rect, value);
- MathUtil::AddToTracedValue("ya_tex_size", ya_tex_size, value);
- MathUtil::AddToTracedValue("uv_tex_size", uv_tex_size, value);
- value->SetInteger("y_plane_resource_id",
- resources.ids[kYPlaneResourceIdIndex]);
- value->SetInteger("u_plane_resource_id",
- resources.ids[kUPlaneResourceIdIndex]);
- value->SetInteger("v_plane_resource_id",
- resources.ids[kVPlaneResourceIdIndex]);
- value->SetInteger("a_plane_resource_id",
- resources.ids[kAPlaneResourceIdIndex]);
- value->SetBoolean("require_overlay", require_overlay);
-}
-
-} // namespace cc
diff --git a/chromium/cc/quads/yuv_video_draw_quad.h b/chromium/cc/quads/yuv_video_draw_quad.h
deleted file mode 100644
index 2545b87801f..00000000000
--- a/chromium/cc/quads/yuv_video_draw_quad.h
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_QUADS_YUV_VIDEO_DRAW_QUAD_H_
-#define CC_QUADS_YUV_VIDEO_DRAW_QUAD_H_
-
-#include <stddef.h>
-
-#include <memory>
-
-#include "cc/cc_export.h"
-#include "cc/quads/draw_quad.h"
-#include "ui/gfx/color_space.h"
-#include "ui/gfx/geometry/rect_f.h"
-#include "ui/gfx/geometry/size.h"
-
-namespace cc {
-
-class CC_EXPORT YUVVideoDrawQuad : public DrawQuad {
- public:
- static const size_t kYPlaneResourceIdIndex = 0;
- static const size_t kUPlaneResourceIdIndex = 1;
- static const size_t kVPlaneResourceIdIndex = 2;
- static const size_t kAPlaneResourceIdIndex = 3;
-
- enum : uint32_t { kMinBitsPerChannel = 8, kMaxBitsPerChannel = 24 };
-
- enum ColorSpace {
- REC_601, // SDTV standard with restricted "studio swing" color range.
- REC_709, // HDTV standard with restricted "studio swing" color range.
- JPEG, // Full color range [0, 255] JPEG color space.
- COLOR_SPACE_LAST = JPEG
- };
-
- ~YUVVideoDrawQuad() override;
-
- YUVVideoDrawQuad();
- YUVVideoDrawQuad(const YUVVideoDrawQuad& other);
-
- void SetNew(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- // |*_tex_coord_rect| contains non-normalized coordinates.
- // TODO(reveman): Make the use of normalized vs non-normalized
- // coordinates consistent across all quad types: crbug.com/487370
- const gfx::RectF& ya_tex_coord_rect,
- const gfx::RectF& uv_tex_coord_rect,
- const gfx::Size& ya_tex_size,
- const gfx::Size& uv_tex_size,
- unsigned y_plane_resource_id,
- unsigned u_plane_resource_id,
- unsigned v_plane_resource_id,
- unsigned a_plane_resource_id,
- ColorSpace color_space,
- const gfx::ColorSpace& video_color_space,
- float offset,
- float multiplier,
- uint32_t bits_per_channel);
-
- void SetAll(const viz::SharedQuadState* shared_quad_state,
- const gfx::Rect& rect,
- const gfx::Rect& visible_rect,
- bool needs_blending,
- // |*_tex_coord_rect| contains non-normalized coordinates.
- // TODO(reveman): Make the use of normalized vs non-normalized
- // coordinates consistent across all quad types: crbug.com/487370
- const gfx::RectF& ya_tex_coord_rect,
- const gfx::RectF& uv_tex_coord_rect,
- const gfx::Size& ya_tex_size,
- const gfx::Size& uv_tex_size,
- unsigned y_plane_resource_id,
- unsigned u_plane_resource_id,
- unsigned v_plane_resource_id,
- unsigned a_plane_resource_id,
- ColorSpace color_space,
- const gfx::ColorSpace& video_color_space,
- float offset,
- float multiplier,
- uint32_t bits_per_channel,
- bool require_overlay);
-
- gfx::RectF ya_tex_coord_rect;
- gfx::RectF uv_tex_coord_rect;
- gfx::Size ya_tex_size;
- gfx::Size uv_tex_size;
- ColorSpace color_space;
- float resource_offset = 0.0f;
- float resource_multiplier = 1.0f;
- uint32_t bits_per_channel = 8;
- // TODO(hubbe): Move to ResourceProvider::ScopedSamplerGL.
- gfx::ColorSpace video_color_space;
- bool require_overlay = false;
-
- static const YUVVideoDrawQuad* MaterialCast(const DrawQuad*);
-
- viz::ResourceId y_plane_resource_id() const {
- return resources.ids[kYPlaneResourceIdIndex];
- }
- viz::ResourceId u_plane_resource_id() const {
- return resources.ids[kUPlaneResourceIdIndex];
- }
- viz::ResourceId v_plane_resource_id() const {
- return resources.ids[kVPlaneResourceIdIndex];
- }
- viz::ResourceId a_plane_resource_id() const {
- return resources.ids[kAPlaneResourceIdIndex];
- }
-
- private:
- void ExtendValue(base::trace_event::TracedValue* value) const override;
-};
-
-} // namespace cc
-
-#endif // CC_QUADS_YUV_VIDEO_DRAW_QUAD_H_
diff --git a/chromium/cc/raster/gpu_raster_buffer_provider.cc b/chromium/cc/raster/gpu_raster_buffer_provider.cc
index b2392306730..7bf4d5838bb 100644
--- a/chromium/cc/raster/gpu_raster_buffer_provider.cc
+++ b/chromium/cc/raster/gpu_raster_buffer_provider.cc
@@ -66,8 +66,8 @@ static void RasterizeSourceOOP(
gpu::gles2::GLES2Interface* gl = context_provider->ContextGL();
GLuint texture_id = resource_lock->ConsumeTexture(gl);
- auto setup_list = make_scoped_refptr(
- new DisplayItemList(DisplayItemList::kTopLevelDisplayItemList));
+ auto setup_list = base::MakeRefCounted<DisplayItemList>(
+ DisplayItemList::kTopLevelDisplayItemList);
setup_list->StartPaint();
setup_list->push<DrawRecordOp>(SetupForRaster(raster_source, raster_full_rect,
playback_rect, transform));
@@ -81,9 +81,9 @@ static void RasterizeSourceOOP(
resource_lock->PixelConfig());
gl->RasterCHROMIUM(setup_list.get(), playback_rect.x(), playback_rect.y(),
playback_rect.width(), playback_rect.height());
- gl->RasterCHROMIUM(raster_source->display_list(), playback_rect.x(),
- playback_rect.y(), playback_rect.width(),
- playback_rect.height());
+ gl->RasterCHROMIUM(raster_source->GetDisplayItemList().get(),
+ playback_rect.x(), playback_rect.y(),
+ playback_rect.width(), playback_rect.height());
gl->EndRasterCHROMIUM();
gl->DeleteTextures(1, &texture_id);
diff --git a/chromium/cc/raster/playback_image_provider.cc b/chromium/cc/raster/playback_image_provider.cc
index fb0c21fa91b..f2a6682ae18 100644
--- a/chromium/cc/raster/playback_image_provider.cc
+++ b/chromium/cc/raster/playback_image_provider.cc
@@ -9,12 +9,6 @@
namespace cc {
namespace {
-SkIRect RoundOutRect(const SkRect& rect) {
- SkIRect result;
- rect.roundOut(&result);
- return result;
-}
-
void UnrefImageFromCache(DrawImage draw_image,
ImageDecodeCache* cache,
DecodedDrawImage decoded_draw_image) {
@@ -24,18 +18,18 @@ void UnrefImageFromCache(DrawImage draw_image,
} // namespace
PlaybackImageProvider::PlaybackImageProvider(
- bool skip_all_images,
- PaintImageIdFlatSet images_to_skip,
ImageDecodeCache* cache,
- const gfx::ColorSpace& target_color_space)
- : skip_all_images_(skip_all_images),
- images_to_skip_(std::move(images_to_skip)),
- cache_(cache),
- target_color_space_(target_color_space) {
+ const gfx::ColorSpace& target_color_space,
+ base::Optional<Settings> settings)
+ : cache_(cache),
+ target_color_space_(target_color_space),
+ settings_(std::move(settings)) {
DCHECK(cache_);
}
-PlaybackImageProvider::~PlaybackImageProvider() = default;
+PlaybackImageProvider::~PlaybackImageProvider() {
+ DCHECK(!in_raster_);
+}
PlaybackImageProvider::PlaybackImageProvider(PlaybackImageProvider&& other) =
default;
@@ -43,17 +37,36 @@ PlaybackImageProvider::PlaybackImageProvider(PlaybackImageProvider&& other) =
PlaybackImageProvider& PlaybackImageProvider::operator=(
PlaybackImageProvider&& other) = default;
+void PlaybackImageProvider::BeginRaster() {
+ DCHECK(decoded_at_raster_.empty());
+ DCHECK(!in_raster_);
+ in_raster_ = true;
+
+ if (!settings_.has_value())
+ return;
+
+ for (auto& draw_image : settings_->at_raster_images)
+ decoded_at_raster_.push_back(GetDecodedDrawImage(draw_image));
+}
+
+void PlaybackImageProvider::EndRaster() {
+ DCHECK(in_raster_);
+ decoded_at_raster_.clear();
+ in_raster_ = false;
+}
+
ImageProvider::ScopedDecodedDrawImage
-PlaybackImageProvider::GetDecodedDrawImage(const PaintImage& paint_image,
- const SkRect& src_rect,
- SkFilterQuality filter_quality,
- const SkMatrix& matrix) {
- // Return an empty decoded images if we are skipping all images during this
+PlaybackImageProvider::GetDecodedDrawImage(const DrawImage& draw_image) {
+ DCHECK(in_raster_);
+
+ // Return an empty decoded image if we are skipping all images during this
// raster.
- if (skip_all_images_)
+ if (!settings_.has_value())
return ScopedDecodedDrawImage();
- if (images_to_skip_.count(paint_image.stable_id()) != 0) {
+ const PaintImage& paint_image = draw_image.paint_image();
+
+ if (settings_->images_to_skip.count(paint_image.stable_id()) != 0) {
DCHECK(paint_image.GetSkImage()->isLazyGenerated());
return ScopedDecodedDrawImage();
}
@@ -61,15 +74,25 @@ PlaybackImageProvider::GetDecodedDrawImage(const PaintImage& paint_image,
if (!paint_image.GetSkImage()->isLazyGenerated()) {
return ScopedDecodedDrawImage(
DecodedDrawImage(paint_image.GetSkImage(), SkSize::Make(0, 0),
- SkSize::Make(1.f, 1.f), filter_quality));
+ SkSize::Make(1.f, 1.f), draw_image.filter_quality()));
}
- DrawImage draw_image = DrawImage(paint_image, RoundOutRect(src_rect),
- filter_quality, matrix, target_color_space_);
- auto decoded_draw_image = cache_->GetDecodedImageForDraw(draw_image);
+ const auto& it =
+ settings_->image_to_current_frame_index.find(paint_image.stable_id());
+ size_t frame_index = it == settings_->image_to_current_frame_index.end()
+ ? paint_image.frame_index()
+ : it->second;
+
+ DrawImage adjusted_image(draw_image, 1.f, frame_index, target_color_space_);
+ auto decoded_draw_image = cache_->GetDecodedImageForDraw(adjusted_image);
+
return ScopedDecodedDrawImage(
decoded_draw_image,
- base::BindOnce(&UnrefImageFromCache, std::move(draw_image), cache_));
+ base::BindOnce(&UnrefImageFromCache, std::move(adjusted_image), cache_));
}
+PlaybackImageProvider::Settings::Settings() = default;
+PlaybackImageProvider::Settings::Settings(const Settings& other) = default;
+PlaybackImageProvider::Settings::~Settings() = default;
+
} // namespace cc
diff --git a/chromium/cc/raster/playback_image_provider.h b/chromium/cc/raster/playback_image_provider.h
index 3d6c2b5f282..bae8c25bfd3 100644
--- a/chromium/cc/raster/playback_image_provider.h
+++ b/chromium/cc/raster/playback_image_provider.h
@@ -5,6 +5,7 @@
#ifndef CC_RASTER_PLAYBACK_IMAGE_PROVIDER_H_
#define CC_RASTER_PLAYBACK_IMAGE_PROVIDER_H_
+#include "base/containers/flat_map.h"
#include "cc/cc_export.h"
#include "cc/paint/image_id.h"
#include "cc/paint/image_provider.h"
@@ -14,33 +15,50 @@ namespace cc {
class ImageDecodeCache;
// PlaybackImageProvider is used to replace lazy generated PaintImages with
-// decoded images for raster from the ImageDecodeCache. The following settings
-// can be used to modify rasterization of these images:
-// 1) skip_all_images: Ensures that no images are decoded or rasterized.
-// 2) images_to_skip: Used to selectively skip images during raster. This should
-// only be used for lazy generated images.
+// decoded images for raster from the ImageDecodeCache.
class CC_EXPORT PlaybackImageProvider : public ImageProvider {
public:
- PlaybackImageProvider(bool skip_all_images,
- PaintImageIdFlatSet images_to_skip,
- ImageDecodeCache* cache,
- const gfx::ColorSpace& taget_color_space);
+ struct CC_EXPORT Settings {
+ Settings();
+ Settings(const Settings& other);
+ ~Settings();
+
+ // The set of image ids to skip during raster.
+ PaintImageIdFlatSet images_to_skip;
+
+ // The set of images which must be decoded by the provider before beginning
+ // raster. The images are decoded and locked by the provider in BeginRaster
+ // and unlocked in EndRaster.
+ std::vector<DrawImage> at_raster_images;
+
+ // The frame index to use for the given image id. If no index is provided,
+ // the frame index provided in the PaintImage will be used.
+ base::flat_map<PaintImage::Id, size_t> image_to_current_frame_index;
+ };
+
+ // If no settings are provided, all images are skipped during rasterization.
+ PlaybackImageProvider(ImageDecodeCache* cache,
+ const gfx::ColorSpace& target_color_space,
+ base::Optional<Settings> settings);
~PlaybackImageProvider() override;
+ void BeginRaster() override;
+ void EndRaster() override;
+
PlaybackImageProvider(PlaybackImageProvider&& other);
PlaybackImageProvider& operator=(PlaybackImageProvider&& other);
// ImageProvider implementation.
- ScopedDecodedDrawImage GetDecodedDrawImage(const PaintImage& paint_image,
- const SkRect& src_rect,
- SkFilterQuality filter_quality,
- const SkMatrix& matrix) override;
+ ScopedDecodedDrawImage GetDecodedDrawImage(
+ const DrawImage& draw_image) override;
private:
- bool skip_all_images_;
- PaintImageIdFlatSet images_to_skip_;
ImageDecodeCache* cache_;
gfx::ColorSpace target_color_space_;
+ base::Optional<Settings> settings_;
+
+ bool in_raster_ = false;
+ std::vector<ImageProvider::ScopedDecodedDrawImage> decoded_at_raster_;
DISALLOW_COPY_AND_ASSIGN(PlaybackImageProvider);
};
diff --git a/chromium/cc/raster/playback_image_provider_unittest.cc b/chromium/cc/raster/playback_image_provider_unittest.cc
index 008f3428f3a..dde64a7b5b5 100644
--- a/chromium/cc/raster/playback_image_provider_unittest.cc
+++ b/chromium/cc/raster/playback_image_provider_unittest.cc
@@ -30,6 +30,7 @@ class MockDecodeCache : public StubDecodeCache {
DecodedDrawImage GetDecodedImageForDraw(
const DrawImage& draw_image) override {
+ last_image_ = draw_image;
images_decoded_++;
refed_image_count_++;
return CreateDecode();
@@ -44,62 +45,131 @@ class MockDecodeCache : public StubDecodeCache {
int refed_image_count() const { return refed_image_count_; }
int images_decoded() const { return images_decoded_; }
+ const DrawImage& last_image() { return last_image_; }
private:
int refed_image_count_ = 0;
int images_decoded_ = 0;
+ DrawImage last_image_;
};
TEST(PlaybackImageProviderTest, SkipsAllImages) {
MockDecodeCache cache;
- PlaybackImageProvider provider(true, {}, &cache, gfx::ColorSpace());
+ PlaybackImageProvider provider(&cache, gfx::ColorSpace(), base::nullopt);
+ provider.BeginRaster();
- SkRect rect = SkRect::MakeWH(10, 10);
+ SkIRect rect = SkIRect::MakeWH(10, 10);
SkMatrix matrix = SkMatrix::I();
- EXPECT_FALSE(
- provider.GetDecodedDrawImage(PaintImageBuilder()
- .set_id(PaintImage::kNonLazyStableId)
- .set_image(CreateRasterImage())
- .TakePaintImage(),
- rect, kMedium_SkFilterQuality, matrix));
+ EXPECT_FALSE(provider.GetDecodedDrawImage(
+ DrawImage(PaintImageBuilder::WithDefault()
+ .set_id(PaintImage::kNonLazyStableId)
+ .set_image(CreateRasterImage())
+ .TakePaintImage(),
+ rect, kMedium_SkFilterQuality, matrix)));
EXPECT_EQ(cache.images_decoded(), 0);
EXPECT_FALSE(provider.GetDecodedDrawImage(
- CreateDiscardablePaintImage(gfx::Size(10, 10)), rect,
- kMedium_SkFilterQuality, matrix));
+ CreateDiscardableDrawImage(gfx::Size(10, 10), nullptr, SkRect::Make(rect),
+ kMedium_SkFilterQuality, matrix)));
EXPECT_EQ(cache.images_decoded(), 0);
+ provider.EndRaster();
}
TEST(PlaybackImageProviderTest, SkipsSomeImages) {
MockDecodeCache cache;
PaintImage skip_image = CreateDiscardablePaintImage(gfx::Size(10, 10));
- PlaybackImageProvider provider(false, {skip_image.stable_id()}, &cache,
- gfx::ColorSpace());
- SkRect rect = SkRect::MakeWH(10, 10);
+ base::Optional<PlaybackImageProvider::Settings> settings;
+ settings.emplace();
+ settings->images_to_skip = {skip_image.stable_id()};
+
+ PlaybackImageProvider provider(&cache, gfx::ColorSpace(), settings);
+ provider.BeginRaster();
+
+ SkIRect rect = SkIRect::MakeWH(10, 10);
SkMatrix matrix = SkMatrix::I();
- EXPECT_FALSE(provider.GetDecodedDrawImage(skip_image, rect,
- kMedium_SkFilterQuality, matrix));
+ EXPECT_FALSE(provider.GetDecodedDrawImage(
+ DrawImage(skip_image, rect, kMedium_SkFilterQuality, matrix)));
EXPECT_EQ(cache.images_decoded(), 0);
+ provider.EndRaster();
}
TEST(PlaybackImageProviderTest, RefAndUnrefDecode) {
MockDecodeCache cache;
- PlaybackImageProvider provider(false, {}, &cache, gfx::ColorSpace());
+
+ base::Optional<PlaybackImageProvider::Settings> settings;
+ settings.emplace();
+ PlaybackImageProvider provider(&cache, gfx::ColorSpace(), settings);
+ provider.BeginRaster();
{
SkRect rect = SkRect::MakeWH(10, 10);
SkMatrix matrix = SkMatrix::I();
- auto decode = provider.GetDecodedDrawImage(
- CreateDiscardablePaintImage(gfx::Size(10, 10)), rect,
- kMedium_SkFilterQuality, matrix);
+ auto decode = provider.GetDecodedDrawImage(CreateDiscardableDrawImage(
+ gfx::Size(10, 10), nullptr, rect, kMedium_SkFilterQuality, matrix));
EXPECT_TRUE(decode);
EXPECT_EQ(cache.refed_image_count(), 1);
}
// Destroying the decode unrefs the image from the cache.
EXPECT_EQ(cache.refed_image_count(), 0);
+
+ provider.EndRaster();
+}
+
+TEST(PlaybackImageProviderTest, AtRasterImages) {
+ MockDecodeCache cache;
+
+ SkRect rect = SkRect::MakeWH(10, 10);
+ gfx::Size size(10, 10);
+ SkMatrix matrix = SkMatrix::I();
+ auto draw_image1 = CreateDiscardableDrawImage(
+ size, nullptr, rect, kMedium_SkFilterQuality, matrix);
+ auto draw_image2 = CreateDiscardableDrawImage(
+ size, nullptr, rect, kMedium_SkFilterQuality, matrix);
+
+ base::Optional<PlaybackImageProvider::Settings> settings;
+ settings.emplace();
+ settings->at_raster_images = {draw_image1, draw_image2};
+
+ PlaybackImageProvider provider(&cache, gfx::ColorSpace(), settings);
+
+ EXPECT_EQ(cache.refed_image_count(), 0);
+ provider.BeginRaster();
+ EXPECT_EQ(cache.refed_image_count(), 2);
+ EXPECT_EQ(cache.images_decoded(), 2);
+
+ provider.EndRaster();
+ EXPECT_EQ(cache.refed_image_count(), 0);
+ EXPECT_EQ(cache.images_decoded(), 2);
+}
+
+TEST(PlaybackImageProviderTest, SwapsGivenFrames) {
+ MockDecodeCache cache;
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))};
+ PaintImage image = CreateAnimatedImage(gfx::Size(10, 10), frames);
+
+ base::flat_map<PaintImage::Id, size_t> image_to_frame;
+ image_to_frame[image.stable_id()] = 1u;
+ base::Optional<PlaybackImageProvider::Settings> settings;
+ settings.emplace();
+ settings->image_to_current_frame_index = image_to_frame;
+
+ PlaybackImageProvider provider(&cache, gfx::ColorSpace(), settings);
+ provider.BeginRaster();
+
+ SkIRect rect = SkIRect::MakeWH(10, 10);
+ SkMatrix matrix = SkMatrix::I();
+ DrawImage draw_image(image, rect, kMedium_SkFilterQuality, matrix);
+ provider.GetDecodedDrawImage(draw_image);
+ ASSERT_TRUE(cache.last_image().paint_image());
+ ASSERT_EQ(cache.last_image().paint_image(), image);
+ ASSERT_EQ(cache.last_image().frame_index(), 1u);
+
+ provider.EndRaster();
}
} // namespace
diff --git a/chromium/cc/raster/raster_buffer_provider.cc b/chromium/cc/raster/raster_buffer_provider.cc
index 1eb0fd0346c..081aaf53627 100644
--- a/chromium/cc/raster/raster_buffer_provider.cc
+++ b/chromium/cc/raster/raster_buffer_provider.cc
@@ -37,6 +37,7 @@ bool IsSupportedPlaybackToMemoryFormat(viz::ResourceFormat format) {
case viz::RED_8:
case viz::LUMINANCE_F16:
case viz::RGBA_F16:
+ case viz::R16_EXT:
return false;
}
NOTREACHED();
@@ -130,6 +131,7 @@ void RasterBufferProvider::PlaybackToMemory(
case viz::RGB_565:
case viz::RED_8:
case viz::LUMINANCE_F16:
+ case viz::R16_EXT:
NOTREACHED();
return;
}
@@ -153,6 +155,7 @@ bool RasterBufferProvider::ResourceFormatRequiresSwizzle(
case viz::RED_8:
case viz::LUMINANCE_F16:
case viz::RGBA_F16:
+ case viz::R16_EXT:
return false;
}
NOTREACHED();
diff --git a/chromium/cc/raster/raster_buffer_provider_perftest.cc b/chromium/cc/raster/raster_buffer_provider_perftest.cc
index 2e1d247e7be..1bdd7144f45 100644
--- a/chromium/cc/raster/raster_buffer_provider_perftest.cc
+++ b/chromium/cc/raster/raster_buffer_provider_perftest.cc
@@ -30,6 +30,7 @@
#include "components/viz/common/resources/platform_color.h"
#include "components/viz/test/test_gpu_memory_buffer_manager.h"
#include "gpu/command_buffer/common/sync_token.h"
+#include "gpu/config/gpu_feature_info.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/perf/perf_test.h"
#include "third_party/khronos/GLES2/gl2.h"
@@ -82,13 +83,16 @@ class PerfContextProvider : public viz::ContextProvider {
public:
PerfContextProvider()
: context_gl_(new PerfGLES2Interface),
- cache_controller_(&support_, nullptr) {}
+ cache_controller_(&support_, nullptr) {
+ capabilities_.sync_query = true;
+ }
bool BindToCurrentThread() override { return true; }
- gpu::Capabilities ContextCapabilities() override {
- gpu::Capabilities capabilities;
- capabilities.sync_query = true;
- return capabilities;
+ const gpu::Capabilities& ContextCapabilities() const override {
+ return capabilities_;
+ }
+ const gpu::GpuFeatureInfo& GetGpuFeatureInfo() const override {
+ return gpu_feature_info_;
}
gpu::gles2::GLES2Interface* ContextGL() override { return context_gl_.get(); }
gpu::ContextSupport* ContextSupport() override { return &support_; }
@@ -121,6 +125,8 @@ class PerfContextProvider : public viz::ContextProvider {
TestContextSupport support_;
viz::ContextCacheController cache_controller_;
base::Lock context_lock_;
+ gpu::Capabilities capabilities_;
+ gpu::GpuFeatureInfo gpu_feature_info_;
};
enum RasterBufferProviderType {
@@ -221,8 +227,8 @@ class RasterBufferProviderPerfTestBase {
RasterBufferProviderPerfTestBase()
: compositor_context_provider_(
- make_scoped_refptr(new PerfContextProvider)),
- worker_context_provider_(make_scoped_refptr(new PerfContextProvider)),
+ base::MakeRefCounted<PerfContextProvider>()),
+ worker_context_provider_(base::MakeRefCounted<PerfContextProvider>()),
task_runner_(new base::TestSimpleTaskRunner),
task_graph_runner_(new SynchronousTaskGraphRunner),
timer_(kWarmupRuns,
@@ -244,7 +250,7 @@ class RasterBufferProviderPerfTestBase {
for (unsigned i = 0; i < num_raster_tasks; ++i) {
auto resource =
std::make_unique<ScopedResource>(resource_provider_.get());
- resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ resource->Allocate(size, ResourceProvider::TEXTURE_HINT_DEFAULT,
viz::RGBA_8888, gfx::ColorSpace());
// No tile ids are given to support partial updates.
@@ -484,16 +490,14 @@ class RasterBufferProviderPerfTest
private:
void Create3dResourceProvider() {
- resource_provider_ =
- FakeResourceProvider::Create<LayerTreeResourceProvider>(
- compositor_context_provider_.get(), nullptr,
- &gpu_memory_buffer_manager_);
+ resource_provider_ = FakeResourceProvider::CreateLayerTreeResourceProvider(
+ compositor_context_provider_.get(), nullptr,
+ &gpu_memory_buffer_manager_);
}
void CreateSoftwareResourceProvider() {
- resource_provider_ =
- FakeResourceProvider::Create<LayerTreeResourceProvider>(
- nullptr, &shared_bitmap_manager_, nullptr);
+ resource_provider_ = FakeResourceProvider::CreateLayerTreeResourceProvider(
+ nullptr, &shared_bitmap_manager_, nullptr);
}
std::string TestModifierString() const {
@@ -557,9 +561,8 @@ class RasterBufferProviderCommonPerfTest
public:
// Overridden from testing::Test:
void SetUp() override {
- resource_provider_ =
- FakeResourceProvider::Create<LayerTreeResourceProvider>(
- compositor_context_provider_.get(), nullptr);
+ resource_provider_ = FakeResourceProvider::CreateLayerTreeResourceProvider(
+ compositor_context_provider_.get(), nullptr);
}
void RunBuildTileTaskGraphTest(const std::string& test_name,
diff --git a/chromium/cc/raster/raster_buffer_provider_unittest.cc b/chromium/cc/raster/raster_buffer_provider_unittest.cc
index 194a1a8015d..b79ef73532f 100644
--- a/chromium/cc/raster/raster_buffer_provider_unittest.cc
+++ b/chromium/cc/raster/raster_buffer_provider_unittest.cc
@@ -20,6 +20,7 @@
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "cc/base/unique_notifier.h"
+#include "cc/paint/draw_image.h"
#include "cc/raster/bitmap_raster_buffer_provider.h"
#include "cc/raster/gpu_raster_buffer_provider.h"
#include "cc/raster/one_copy_raster_buffer_provider.h"
@@ -238,7 +239,7 @@ class RasterBufferProviderTest
void AppendTask(unsigned id, const gfx::Size& size) {
auto resource = std::make_unique<ScopedResource>(resource_provider_.get());
- resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ resource->Allocate(size, ResourceProvider::TEXTURE_HINT_DEFAULT,
viz::RGBA_8888, gfx::ColorSpace());
// The raster buffer has no tile ids associated with it for partial update,
@@ -257,7 +258,7 @@ class RasterBufferProviderTest
const gfx::Size size(1, 1);
auto resource = std::make_unique<ScopedResource>(resource_provider_.get());
- resource->Allocate(size, ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ resource->Allocate(size, ResourceProvider::TEXTURE_HINT_DEFAULT,
viz::RGBA_8888, gfx::ColorSpace());
std::unique_ptr<RasterBuffer> raster_buffer =
@@ -297,16 +298,14 @@ class RasterBufferProviderTest
worker_context_provider_ = TestContextProvider::CreateWorker();
TestWebGraphicsContext3D* context3d = context_provider_->TestContext3d();
context3d->set_support_sync_query(true);
- resource_provider_ =
- FakeResourceProvider::Create<LayerTreeResourceProvider>(
- context_provider_.get(), &shared_bitmap_manager_,
- &gpu_memory_buffer_manager_);
+ resource_provider_ = FakeResourceProvider::CreateLayerTreeResourceProvider(
+ context_provider_.get(), &shared_bitmap_manager_,
+ &gpu_memory_buffer_manager_);
}
void CreateSoftwareResourceProvider() {
- resource_provider_ =
- FakeResourceProvider::Create<LayerTreeResourceProvider>(
- nullptr, &shared_bitmap_manager_, &gpu_memory_buffer_manager_);
+ resource_provider_ = FakeResourceProvider::CreateLayerTreeResourceProvider(
+ nullptr, &shared_bitmap_manager_, &gpu_memory_buffer_manager_);
}
void OnTimeout() {
diff --git a/chromium/cc/raster/raster_source.cc b/chromium/cc/raster/raster_source.cc
index aedd659befa..50fdfffa109 100644
--- a/chromium/cc/raster/raster_source.cc
+++ b/chromium/cc/raster/raster_source.cc
@@ -11,6 +11,7 @@
#include "cc/base/region.h"
#include "cc/debug/debug_colors.h"
#include "cc/paint/display_item_list.h"
+#include "cc/paint/image_provider.h"
#include "cc/paint/skia_paint_canvas.h"
#include "components/viz/common/traced_value.h"
#include "skia/ext/analysis_canvas.h"
@@ -74,9 +75,7 @@ void RasterSource::PlaybackToCanvas(SkCanvas* input_canvas,
raster_canvas = color_transform_canvas.get();
}
- if (!settings.playback_to_shared_canvas)
- ClearCanvasForPlayback(raster_canvas);
-
+ ClearCanvasForPlayback(raster_canvas);
RasterCommon(raster_canvas, settings.image_provider);
}
@@ -151,10 +150,16 @@ void RasterSource::ClearCanvasForPlayback(SkCanvas* canvas) const {
void RasterSource::RasterCommon(SkCanvas* raster_canvas,
ImageProvider* image_provider,
SkPicture::AbortCallback* callback) const {
+ if (image_provider)
+ image_provider->BeginRaster();
+
DCHECK(display_list_.get());
int repeat_count = std::max(1, slow_down_raster_scale_factor_for_debug_);
for (int i = 0; i < repeat_count; ++i)
display_list_->Raster(raster_canvas, image_provider, callback);
+
+ if (image_provider)
+ image_provider->EndRaster();
}
sk_sp<SkPicture> RasterSource::GetFlattenedPicture() {
@@ -238,9 +243,7 @@ void RasterSource::DidBeginTracing() {
display_list_->EmitTraceSnapshot();
}
-RasterSource::PlaybackSettings::PlaybackSettings()
- : playback_to_shared_canvas(false),
- use_lcd_text(true) {}
+RasterSource::PlaybackSettings::PlaybackSettings() = default;
RasterSource::PlaybackSettings::PlaybackSettings(const PlaybackSettings&) =
default;
diff --git a/chromium/cc/raster/raster_source.h b/chromium/cc/raster/raster_source.h
index 8ee49207bf0..cc94bfce1cb 100644
--- a/chromium/cc/raster/raster_source.h
+++ b/chromium/cc/raster/raster_source.h
@@ -36,12 +36,8 @@ class CC_EXPORT RasterSource : public base::RefCountedThreadSafe<RasterSource> {
PlaybackSettings(PlaybackSettings&&);
~PlaybackSettings();
- // If set to true, this indicates that the canvas has already been
- // rasterized into. This means that the canvas cannot be cleared safely.
- bool playback_to_shared_canvas : 1;
-
// If set to true, we should use LCD text.
- bool use_lcd_text : 1;
+ bool use_lcd_text = true;
// The ImageProvider used to replace images during playback.
ImageProvider* image_provider = nullptr;
@@ -113,7 +109,9 @@ class CC_EXPORT RasterSource : public base::RefCountedThreadSafe<RasterSource> {
virtual sk_sp<SkPicture> GetFlattenedPicture();
virtual size_t GetMemoryUsage() const;
- const DisplayItemList* display_list() const { return display_list_.get(); }
+ const scoped_refptr<DisplayItemList>& GetDisplayItemList() const {
+ return display_list_;
+ }
SkColor background_color() const { return background_color_; }
diff --git a/chromium/cc/raster/raster_source_unittest.cc b/chromium/cc/raster/raster_source_unittest.cc
index 1ee83afa8cb..b89083e9a84 100644
--- a/chromium/cc/raster/raster_source_unittest.cc
+++ b/chromium/cc/raster/raster_source_unittest.cc
@@ -215,7 +215,8 @@ TEST(RasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) {
std::vector<const DrawImage*> images;
raster->GetDiscardableImagesInRect(gfx::Rect(0, 0, 256, 256), &images);
EXPECT_EQ(1u, images.size());
- DrawImage image(*images[0], 1.f, target_color_space);
+ DrawImage image(*images[0], 1.f, PaintImage::kDefaultFrameIndex,
+ target_color_space);
EXPECT_EQ(discardable_image[0][0], images[0]->paint_image());
EXPECT_EQ(target_color_space, image.target_color_space());
}
@@ -225,7 +226,8 @@ TEST(RasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) {
std::vector<const DrawImage*> images;
raster->GetDiscardableImagesInRect(gfx::Rect(260, 260, 256, 256), &images);
EXPECT_EQ(1u, images.size());
- DrawImage image(*images[0], 1.f, target_color_space);
+ DrawImage image(*images[0], 1.f, PaintImage::kDefaultFrameIndex,
+ target_color_space);
EXPECT_EQ(discardable_image[1][1], images[0]->paint_image());
EXPECT_EQ(target_color_space, image.target_color_space());
}
@@ -546,67 +548,9 @@ TEST(RasterSourceTest, GetPictureMemoryUsageIncludesClientReportedMemory) {
EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes);
}
-TEST(RasterSourceTest, ImageHijackCanvasRespectsSharedCanvasTransform) {
- gfx::Size size(100, 100);
-
- // Create a recording source that is filled with red and every corner is
- // green (4x4 rects in the corner are green to account for blending when
- // scaling). Note that we paint an image first, so that we can force image
- // hijack canvas to be used.
- std::unique_ptr<FakeRecordingSource> recording_source =
- FakeRecordingSource::CreateFilledRecordingSource(size);
-
- // 1. Paint the image.
- recording_source->add_draw_image(CreateDiscardablePaintImage(gfx::Size(5, 5)),
- gfx::Point(0, 0));
-
- // 2. Cover everything in red.
- PaintFlags flags;
- flags.setColor(SK_ColorRED);
- recording_source->add_draw_rect_with_flags(gfx::Rect(size), flags);
-
- // 3. Draw 4x4 green rects into every corner.
- flags.setColor(SK_ColorGREEN);
- recording_source->add_draw_rect_with_flags(gfx::Rect(0, 0, 4, 4), flags);
- recording_source->add_draw_rect_with_flags(
- gfx::Rect(size.width() - 4, 0, 4, 4), flags);
- recording_source->add_draw_rect_with_flags(
- gfx::Rect(0, size.height() - 4, 4, 4), flags);
- recording_source->add_draw_rect_with_flags(
- gfx::Rect(size.width() - 4, size.height() - 4, 4, 4), flags);
-
- recording_source->Rerecord();
-
- scoped_refptr<RasterSource> raster_source =
- recording_source->CreateRasterSource();
- SoftwareImageDecodeCache controller(
- kN32_SkColorType,
- LayerTreeSettings().decoded_image_working_set_budget_bytes);
- PlaybackImageProvider image_provider(false, PaintImageIdFlatSet(),
- &controller, gfx::ColorSpace());
-
- SkBitmap bitmap;
- bitmap.allocN32Pixels(size.width() * 0.5f, size.height() * 0.25f);
- SkCanvas canvas(bitmap);
- canvas.scale(0.5f, 0.25f);
-
- RasterSource::PlaybackSettings settings;
- settings.playback_to_shared_canvas = true;
- settings.image_provider = &image_provider;
- raster_source->PlaybackToCanvas(&canvas, ColorSpaceForTesting(),
- gfx::Rect(size), gfx::Rect(size),
- gfx::AxisTransform2d(), settings);
-
- EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 0));
- EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 0));
- EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 24));
- EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 24));
- for (int x = 0; x < 49; ++x)
- EXPECT_EQ(SK_ColorRED, bitmap.getColor(x, 12));
- for (int y = 0; y < 24; ++y)
- EXPECT_EQ(SK_ColorRED, bitmap.getColor(24, y));
-}
-
+// In debug there is a bunch of clearing to debug colors that makes mocking
+// very noisy and hard to test against.
+#ifdef NDEBUG
TEST(RasterSourceTest, RasterTransformWithoutRecordingScale) {
gfx::Size size(100, 100);
float recording_scale = 2.f;
@@ -619,8 +563,6 @@ TEST(RasterSourceTest, RasterTransformWithoutRecordingScale) {
StrictMock<MockCanvas> mock_canvas;
Sequence s;
- RasterSource::PlaybackSettings settings;
- settings.playback_to_shared_canvas = true;
SkMatrix m;
m.setScale(1.f / recording_scale, 1.f / recording_scale);
@@ -629,12 +571,19 @@ TEST(RasterSourceTest, RasterTransformWithoutRecordingScale) {
// The call to raster_canvas->scale() should have values with the recording
// scale removed.
EXPECT_CALL(mock_canvas, didConcat(m)).InSequence(s);
+
+ // Save/restore/clear around the paint ops being played back.
+ EXPECT_CALL(mock_canvas, willSave()).InSequence(s);
+ EXPECT_CALL(mock_canvas, OnDrawPaintWithColor(_)).InSequence(s);
+ EXPECT_CALL(mock_canvas, willRestore()).InSequence(s);
+
EXPECT_CALL(mock_canvas, willRestore()).InSequence(s);
- raster_source->PlaybackToCanvas(&mock_canvas, ColorSpaceForTesting(),
- gfx::Rect(size), gfx::Rect(size),
- gfx::AxisTransform2d(), settings);
+ raster_source->PlaybackToCanvas(
+ &mock_canvas, ColorSpaceForTesting(), gfx::Rect(size), gfx::Rect(size),
+ gfx::AxisTransform2d(), RasterSource::PlaybackSettings());
}
+#endif
} // namespace
} // namespace cc
diff --git a/chromium/cc/raster/staging_buffer_pool.h b/chromium/cc/raster/staging_buffer_pool.h
index 3ab66f9bd38..158613f2858 100644
--- a/chromium/cc/raster/staging_buffer_pool.h
+++ b/chromium/cc/raster/staging_buffer_pool.h
@@ -7,10 +7,10 @@
#include <stdint.h>
-#include <deque>
#include <memory>
#include <set>
+#include "base/containers/circular_deque.h"
#include "base/macros.h"
#include "base/memory/memory_coordinator_client.h"
#include "base/memory/weak_ptr.h"
@@ -101,7 +101,8 @@ class CC_EXPORT StagingBufferPool
// |lock_| must be acquired when accessing the following members.
using StagingBufferSet = std::set<const StagingBuffer*>;
StagingBufferSet buffers_;
- using StagingBufferDeque = std::deque<std::unique_ptr<StagingBuffer>>;
+ using StagingBufferDeque =
+ base::circular_deque<std::unique_ptr<StagingBuffer>>;
StagingBufferDeque free_buffers_;
StagingBufferDeque busy_buffers_;
const int max_staging_buffer_usage_in_bytes_;
diff --git a/chromium/cc/raster/task_graph_runner_perftest.cc b/chromium/cc/raster/task_graph_runner_perftest.cc
index 62b1d629e0b..456abad59f9 100644
--- a/chromium/cc/raster/task_graph_runner_perftest.cc
+++ b/chromium/cc/raster/task_graph_runner_perftest.cc
@@ -224,7 +224,7 @@ class TaskGraphRunnerPerfTest : public testing::Test {
void CreateTasks(int num_tasks, PerfTaskImpl::Vector* tasks) {
for (int i = 0; i < num_tasks; ++i)
- tasks->push_back(make_scoped_refptr(new PerfTaskImpl));
+ tasks->push_back(base::MakeRefCounted<PerfTaskImpl>());
}
void CancelTasks(const PerfTaskImpl::Vector& tasks) {
diff --git a/chromium/cc/resources/DEPS b/chromium/cc/resources/DEPS
deleted file mode 100644
index 7502d902c92..00000000000
--- a/chromium/cc/resources/DEPS
+++ /dev/null
@@ -1,3 +0,0 @@
-include_rules = [
- "+mojo/public/cpp/bindings/struct_traits.h",
-]
diff --git a/chromium/cc/resources/display_resource_provider.cc b/chromium/cc/resources/display_resource_provider.cc
index 2e9e70b4da7..125cc4c3785 100644
--- a/chromium/cc/resources/display_resource_provider.cc
+++ b/chromium/cc/resources/display_resource_provider.cc
@@ -6,6 +6,7 @@
#include "base/trace_event/trace_event.h"
#include "components/viz/common/resources/resource_format_utils.h"
+#include "components/viz/common/resources/shared_bitmap_manager.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
@@ -17,19 +18,17 @@ DisplayResourceProvider::DisplayResourceProvider(
viz::ContextProvider* compositor_context_provider,
viz::SharedBitmapManager* shared_bitmap_manager,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
- BlockingTaskRunner* blocking_main_thread_task_runner,
- bool delegated_sync_points_required,
- bool enable_color_correct_rasterization,
const viz::ResourceSettings& resource_settings)
: ResourceProvider(compositor_context_provider,
shared_bitmap_manager,
gpu_memory_buffer_manager,
- blocking_main_thread_task_runner,
- delegated_sync_points_required,
- enable_color_correct_rasterization,
+ false,
resource_settings) {}
-DisplayResourceProvider::~DisplayResourceProvider() {}
+DisplayResourceProvider::~DisplayResourceProvider() {
+ while (!children_.empty())
+ DestroyChildInternal(children_.begin(), FOR_SHUTDOWN);
+}
#if defined(OS_ANDROID)
void DisplayResourceProvider::SendPromotionHints(
@@ -89,6 +88,13 @@ void DisplayResourceProvider::SetBatchReturnResources(bool batch) {
}
}
+DisplayResourceProvider::Child::Child()
+ : marked_for_deletion(false), needs_sync_tokens(true) {}
+
+DisplayResourceProvider::Child::Child(const Child& other) = default;
+
+DisplayResourceProvider::Child::~Child() {}
+
int DisplayResourceProvider::CreateChild(
const ReturnCallback& return_callback) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
@@ -114,6 +120,141 @@ void DisplayResourceProvider::DestroyChild(int child_id) {
DestroyChildInternal(it, NORMAL);
}
+void DisplayResourceProvider::DestroyChildInternal(ChildMap::iterator it,
+ DeleteStyle style) {
+ DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+
+ Child& child = it->second;
+ DCHECK(style == FOR_SHUTDOWN || !child.marked_for_deletion);
+
+ ResourceIdArray resources_for_child;
+
+ for (ResourceIdMap::iterator child_it = child.child_to_parent_map.begin();
+ child_it != child.child_to_parent_map.end(); ++child_it) {
+ viz::ResourceId id = child_it->second;
+ resources_for_child.push_back(id);
+ }
+
+ child.marked_for_deletion = true;
+
+ DeleteAndReturnUnusedResourcesToChild(it, style, resources_for_child);
+}
+
+void DisplayResourceProvider::DeleteAndReturnUnusedResourcesToChild(
+ ChildMap::iterator child_it,
+ DeleteStyle style,
+ const ResourceIdArray& unused) {
+ DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+ DCHECK(child_it != children_.end());
+ Child* child_info = &child_it->second;
+
+ if (unused.empty() && !child_info->marked_for_deletion)
+ return;
+
+ std::vector<viz::ReturnedResource> to_return;
+ to_return.reserve(unused.size());
+ std::vector<viz::ReturnedResource*> need_synchronization_resources;
+ std::vector<GLbyte*> unverified_sync_tokens;
+
+ GLES2Interface* gl = ContextGL();
+
+ for (viz::ResourceId local_id : unused) {
+ ResourceMap::iterator it = resources_.find(local_id);
+ CHECK(it != resources_.end());
+ Resource& resource = it->second;
+
+ DCHECK(!resource.locked_for_write);
+
+ viz::ResourceId child_id = resource.id_in_child;
+ DCHECK(child_info->child_to_parent_map.count(child_id));
+
+ bool is_lost = resource.lost ||
+ (IsGpuResourceType(resource.type) && lost_context_provider_);
+ if (resource.exported_count > 0 || resource.lock_for_read_count > 0) {
+ if (style != FOR_SHUTDOWN) {
+ // Defer this resource deletion.
+ resource.marked_for_deletion = true;
+ continue;
+ }
+ // We can't postpone the deletion, so we'll have to lose it.
+ is_lost = true;
+ } else if (!ReadLockFenceHasPassed(&resource)) {
+ // TODO(dcastagna): see if it's possible to use this logic for
+ // the branch above too, where the resource is locked or still exported.
+ if (style != FOR_SHUTDOWN && !child_info->marked_for_deletion) {
+ // Defer this resource deletion.
+ resource.marked_for_deletion = true;
+ continue;
+ }
+ // We can't postpone the deletion, so we'll have to lose it.
+ is_lost = true;
+ }
+
+ if (IsGpuResourceType(resource.type) &&
+ resource.filter != resource.original_filter) {
+ DCHECK(resource.target);
+ DCHECK(resource.gl_id);
+ DCHECK(gl);
+ gl->BindTexture(resource.target, resource.gl_id);
+ gl->TexParameteri(resource.target, GL_TEXTURE_MIN_FILTER,
+ resource.original_filter);
+ gl->TexParameteri(resource.target, GL_TEXTURE_MAG_FILTER,
+ resource.original_filter);
+ resource.SetLocallyUsed();
+ }
+
+ viz::ReturnedResource returned;
+ returned.id = child_id;
+ returned.sync_token = resource.mailbox().sync_token();
+ returned.count = resource.imported_count;
+ returned.lost = is_lost;
+ to_return.push_back(returned);
+
+ if (IsGpuResourceType(resource.type) && child_info->needs_sync_tokens) {
+ if (resource.needs_sync_token()) {
+ need_synchronization_resources.push_back(&to_return.back());
+ } else if (returned.sync_token.HasData() &&
+ !returned.sync_token.verified_flush()) {
+ // Before returning any sync tokens, they must be verified.
+ unverified_sync_tokens.push_back(returned.sync_token.GetData());
+ }
+ }
+
+ child_info->child_to_parent_map.erase(child_id);
+ resource.imported_count = 0;
+ DeleteResourceInternal(it, style);
+ }
+
+ gpu::SyncToken new_sync_token;
+ if (!need_synchronization_resources.empty()) {
+ DCHECK(child_info->needs_sync_tokens);
+ DCHECK(gl);
+ const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM();
+ gl->OrderingBarrierCHROMIUM();
+ gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData());
+ unverified_sync_tokens.push_back(new_sync_token.GetData());
+ }
+
+ if (!unverified_sync_tokens.empty()) {
+ DCHECK(child_info->needs_sync_tokens);
+ DCHECK(gl);
+ gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(),
+ unverified_sync_tokens.size());
+ }
+
+ // Set sync token after verification.
+ for (viz::ReturnedResource* returned : need_synchronization_resources)
+ returned->sync_token = new_sync_token;
+
+ if (!to_return.empty())
+ child_info->return_callback.Run(to_return);
+
+ if (child_info->marked_for_deletion &&
+ child_info->child_to_parent_map.empty()) {
+ children_.erase(child_it);
+ }
+}
+
void DisplayResourceProvider::ReceiveFromChild(
int child,
const std::vector<viz::TransferableResource>& resources) {
@@ -139,8 +280,7 @@ void DisplayResourceProvider::ReceiveFromChild(
"cc", "DisplayResourceProvider::ReceiveFromChild dropping invalid");
std::vector<viz::ReturnedResource> to_return;
to_return.push_back(it->ToReturnedResource());
- child_info.return_callback.Run(to_return,
- blocking_main_thread_task_runner_);
+ child_info.return_callback.Run(to_return);
continue;
}
@@ -152,10 +292,10 @@ void DisplayResourceProvider::ReceiveFromChild(
Resource::DELEGATED, GL_LINEAR));
} else {
resource = InsertResource(
- local_id, Resource(0, it->size, Resource::DELEGATED,
- it->mailbox_holder.texture_target, it->filter,
- TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE,
- it->format));
+ local_id,
+ Resource(0, it->size, Resource::DELEGATED,
+ it->mailbox_holder.texture_target, it->filter,
+ TEXTURE_HINT_DEFAULT, RESOURCE_TYPE_GL_TEXTURE, it->format));
resource->buffer_format = it->buffer_format;
resource->SetMailbox(viz::TextureMailbox(
it->mailbox_holder.mailbox, it->mailbox_holder.sync_token,
@@ -220,6 +360,77 @@ DisplayResourceProvider::ScopedReadLockGL::ScopedReadLockGL(
color_space_ = resource->color_space;
}
+const ResourceProvider::Resource* DisplayResourceProvider::LockForRead(
+ viz::ResourceId id) {
+ Resource* resource = GetResource(id);
+ DCHECK(!resource->locked_for_write)
+ << "locked for write: " << resource->locked_for_write;
+ DCHECK_EQ(resource->exported_count, 0);
+ // Uninitialized! Call SetPixels or LockForWrite first.
+ DCHECK(resource->allocated);
+
+ // Mailbox sync_tokens must be processed by a call to WaitSyncToken() prior to
+ // calling LockForRead().
+ DCHECK_NE(Resource::NEEDS_WAIT, resource->synchronization_state());
+
+ if (IsGpuResourceType(resource->type) && !resource->gl_id) {
+ DCHECK(resource->origin != Resource::INTERNAL);
+ DCHECK(resource->mailbox().IsTexture());
+
+ GLES2Interface* gl = ContextGL();
+ DCHECK(gl);
+ resource->gl_id = gl->CreateAndConsumeTextureCHROMIUM(
+ resource->mailbox().target(), resource->mailbox().name());
+ resource->SetLocallyUsed();
+ }
+
+ if (!resource->pixels && resource->has_shared_bitmap_id &&
+ shared_bitmap_manager_) {
+ std::unique_ptr<viz::SharedBitmap> bitmap =
+ shared_bitmap_manager_->GetSharedBitmapFromId(
+ resource->size, resource->shared_bitmap_id);
+ if (bitmap) {
+ resource->shared_bitmap = bitmap.release();
+ resource->pixels = resource->shared_bitmap->pixels();
+ }
+ }
+
+ resource->lock_for_read_count++;
+ if (resource->read_lock_fences_enabled) {
+ if (current_read_lock_fence_.get())
+ current_read_lock_fence_->Set();
+ resource->read_lock_fence = current_read_lock_fence_;
+ }
+
+ return resource;
+}
+
+void DisplayResourceProvider::UnlockForRead(viz::ResourceId id) {
+ DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+ ResourceMap::iterator it = resources_.find(id);
+ CHECK(it != resources_.end());
+
+ Resource* resource = &it->second;
+ DCHECK_GT(resource->lock_for_read_count, 0);
+ DCHECK_EQ(resource->exported_count, 0);
+ resource->lock_for_read_count--;
+ if (resource->marked_for_deletion && !resource->lock_for_read_count) {
+ if (!resource->child_id) {
+ // The resource belongs to this ResourceProvider, so it can be destroyed.
+ DeleteResourceInternal(it, NORMAL);
+ } else {
+ if (batch_return_resources_) {
+ batched_returning_resources_[resource->child_id].push_back(id);
+ } else {
+ ChildMap::iterator child_it = children_.find(resource->child_id);
+ ResourceIdArray unused;
+ unused.push_back(id);
+ DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, unused);
+ }
+ }
+ }
+}
+
DisplayResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() {
resource_provider_->UnlockForRead(resource_id_);
}
diff --git a/chromium/cc/resources/display_resource_provider.h b/chromium/cc/resources/display_resource_provider.h
index 3358663f610..3a0d20a2024 100644
--- a/chromium/cc/resources/display_resource_provider.h
+++ b/chromium/cc/resources/display_resource_provider.h
@@ -14,7 +14,6 @@ class SharedBitmapManager;
} // namespace viz
namespace cc {
-class BlockingTaskRunner;
// This class is not thread-safe and can only be called from the thread it was
// created on.
@@ -24,9 +23,6 @@ class CC_EXPORT DisplayResourceProvider : public ResourceProvider {
viz::ContextProvider* compositor_context_provider,
viz::SharedBitmapManager* shared_bitmap_manager,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
- BlockingTaskRunner* blocking_main_thread_task_runner,
- bool delegated_sync_points_required,
- bool enable_color_correct_rasterization,
const viz::ResourceSettings& resource_settings);
~DisplayResourceProvider() override;
@@ -143,6 +139,11 @@ class CC_EXPORT DisplayResourceProvider : public ResourceProvider {
DISALLOW_COPY_AND_ASSIGN(ScopedBatchReturnResources);
};
+ // Sets the current read fence. If a resource is locked for read
+ // and has read fences enabled, the resource will not allow writes
+ // until this fence has passed.
+ void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; }
+
// Creates accounting for a child. Returns a child ID.
int CreateChild(const ReturnCallback& return_callback);
@@ -179,8 +180,30 @@ class CC_EXPORT DisplayResourceProvider : public ResourceProvider {
private:
friend class ScopedBatchReturnResources;
+ const Resource* LockForRead(viz::ResourceId id);
+ void UnlockForRead(viz::ResourceId id);
+
+ struct Child {
+ Child();
+ Child(const Child& other);
+ ~Child();
+
+ ResourceIdMap child_to_parent_map;
+ ReturnCallback return_callback;
+ bool marked_for_deletion;
+ bool needs_sync_tokens;
+ };
+ using ChildMap = std::unordered_map<int, Child>;
+
+ void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it,
+ DeleteStyle style,
+ const ResourceIdArray& unused);
+ void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style);
+
void SetBatchReturnResources(bool aggregate);
+ scoped_refptr<Fence> current_read_lock_fence_;
+ ChildMap children_;
base::flat_map<viz::ResourceId, sk_sp<SkImage>> resource_sk_image_;
DISALLOW_COPY_AND_ASSIGN(DisplayResourceProvider);
diff --git a/chromium/cc/resources/layer_tree_resource_provider.cc b/chromium/cc/resources/layer_tree_resource_provider.cc
index c37f56abad1..118c7f9edd4 100644
--- a/chromium/cc/resources/layer_tree_resource_provider.cc
+++ b/chromium/cc/resources/layer_tree_resource_provider.cc
@@ -4,6 +4,7 @@
#include "cc/resources/layer_tree_resource_provider.h"
+#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "components/viz/common/resources/resource_format_utils.h"
#include "gpu/command_buffer/client/context_support.h"
@@ -18,20 +19,80 @@ LayerTreeResourceProvider::LayerTreeResourceProvider(
viz::ContextProvider* compositor_context_provider,
viz::SharedBitmapManager* shared_bitmap_manager,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
- BlockingTaskRunner* blocking_main_thread_task_runner,
bool delegated_sync_points_required,
- bool enable_color_correct_rasterization,
const viz::ResourceSettings& resource_settings)
: ResourceProvider(compositor_context_provider,
shared_bitmap_manager,
gpu_memory_buffer_manager,
- blocking_main_thread_task_runner,
delegated_sync_points_required,
- enable_color_correct_rasterization,
resource_settings) {}
LayerTreeResourceProvider::~LayerTreeResourceProvider() {}
+viz::ResourceId LayerTreeResourceProvider::CreateResourceFromTextureMailbox(
+ const viz::TextureMailbox& mailbox,
+ std::unique_ptr<viz::SingleReleaseCallback> release_callback,
+ bool read_lock_fences_enabled,
+ gfx::BufferFormat buffer_format) {
+ DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+ // Just store the information. Mailbox will be consumed in
+ // DisplayResourceProvider::LockForRead().
+ viz::ResourceId id = next_id_++;
+ DCHECK(mailbox.IsValid());
+ Resource* resource = nullptr;
+ if (mailbox.IsTexture()) {
+ resource = InsertResource(
+ id, Resource(0, mailbox.size_in_pixels(), Resource::EXTERNAL,
+ mailbox.target(),
+ mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR,
+ TEXTURE_HINT_DEFAULT, RESOURCE_TYPE_GL_TEXTURE,
+ viz::RGBA_8888));
+ } else {
+ DCHECK(mailbox.IsSharedMemory());
+ viz::SharedBitmap* shared_bitmap = mailbox.shared_bitmap();
+ uint8_t* pixels = shared_bitmap->pixels();
+ DCHECK(pixels);
+ resource = InsertResource(
+ id, Resource(pixels, shared_bitmap, mailbox.size_in_pixels(),
+ Resource::EXTERNAL, GL_LINEAR));
+ }
+ resource->allocated = true;
+ resource->SetMailbox(mailbox);
+ resource->color_space = mailbox.color_space();
+ resource->release_callback =
+ base::Bind(&viz::SingleReleaseCallback::Run,
+ base::Owned(release_callback.release()));
+ resource->read_lock_fences_enabled = read_lock_fences_enabled;
+ resource->buffer_format = buffer_format;
+ resource->is_overlay_candidate = mailbox.is_overlay_candidate();
+#if defined(OS_ANDROID)
+ resource->is_backed_by_surface_texture =
+ mailbox.is_backed_by_surface_texture();
+ resource->wants_promotion_hint = mailbox.wants_promotion_hint();
+ if (resource->wants_promotion_hint)
+ wants_promotion_hints_set_.insert(id);
+#endif
+ resource->color_space = mailbox.color_space();
+
+ return id;
+}
+
+viz::ResourceId LayerTreeResourceProvider::CreateResourceFromTextureMailbox(
+ const viz::TextureMailbox& mailbox,
+ std::unique_ptr<viz::SingleReleaseCallback> release_callback,
+ bool read_lock_fences_enabled) {
+ return CreateResourceFromTextureMailbox(mailbox, std::move(release_callback),
+ read_lock_fences_enabled,
+ gfx::BufferFormat::RGBA_8888);
+}
+
+viz::ResourceId LayerTreeResourceProvider::CreateResourceFromTextureMailbox(
+ const viz::TextureMailbox& mailbox,
+ std::unique_ptr<viz::SingleReleaseCallback> release_callback) {
+ return CreateResourceFromTextureMailbox(mailbox, std::move(release_callback),
+ false);
+}
+
gpu::SyncToken LayerTreeResourceProvider::GetSyncTokenForResources(
const ResourceIdArray& resource_ids) {
gpu::SyncToken latest_sync_token;
diff --git a/chromium/cc/resources/layer_tree_resource_provider.h b/chromium/cc/resources/layer_tree_resource_provider.h
index 95c1f397ddc..38259535333 100644
--- a/chromium/cc/resources/layer_tree_resource_provider.h
+++ b/chromium/cc/resources/layer_tree_resource_provider.h
@@ -12,7 +12,6 @@ class SharedBitmapManager;
} // namespace viz
namespace cc {
-class BlockingTaskRunner;
// This class is not thread-safe and can only be called from the thread it was
// created on (in practice, the impl thread).
@@ -22,12 +21,26 @@ class CC_EXPORT LayerTreeResourceProvider : public ResourceProvider {
viz::ContextProvider* compositor_context_provider,
viz::SharedBitmapManager* shared_bitmap_manager,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
- BlockingTaskRunner* blocking_main_thread_task_runner,
bool delegated_sync_points_required,
- bool enable_color_correct_rasterization,
const viz::ResourceSettings& resource_settings);
~LayerTreeResourceProvider() override;
+ // Wraps an external texture mailbox into a GL resource.
+ viz::ResourceId CreateResourceFromTextureMailbox(
+ const viz::TextureMailbox& mailbox,
+ std::unique_ptr<viz::SingleReleaseCallback> release_callback);
+
+ viz::ResourceId CreateResourceFromTextureMailbox(
+ const viz::TextureMailbox& mailbox,
+ std::unique_ptr<viz::SingleReleaseCallback> release_callback,
+ bool read_lock_fences_enabled);
+
+ viz::ResourceId CreateResourceFromTextureMailbox(
+ const viz::TextureMailbox& mailbox,
+ std::unique_ptr<viz::SingleReleaseCallback> release_callback,
+ bool read_lock_fences_enabled,
+ gfx::BufferFormat buffer_format);
+
// Gets the most recent sync token from the indicated resources.
gpu::SyncToken GetSyncTokenForResources(const ResourceIdArray& resource_ids);
@@ -56,8 +69,6 @@ class CC_EXPORT LayerTreeResourceProvider : public ResourceProvider {
viz::ResourceId resource_id);
~ScopedWriteLockGpuMemoryBuffer();
gfx::GpuMemoryBuffer* GetGpuMemoryBuffer();
- // Will return the invalid color space unless
- // |enable_color_correct_rasterization| is true.
const gfx::ColorSpace& color_space_for_raster() const {
return color_space_;
}
diff --git a/chromium/cc/resources/release_callback_impl.h b/chromium/cc/resources/release_callback_impl.h
deleted file mode 100644
index c5dffb57ab0..00000000000
--- a/chromium/cc/resources/release_callback_impl.h
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_RESOURCES_RELEASE_CALLBACK_IMPL_H_
-#define CC_RESOURCES_RELEASE_CALLBACK_IMPL_H_
-
-#include "base/callback.h"
-
-namespace gpu {
-struct SyncToken;
-}
-
-namespace cc {
-class BlockingTaskRunner;
-
-typedef base::Callback<void(const gpu::SyncToken& sync_token,
- bool is_lost,
- BlockingTaskRunner* main_thread_task_runner)>
- ReleaseCallbackImpl;
-
-} // namespace cc
-
-#endif // CC_RESOURCES_RELEASE_CALLBACK_IMPL_H_
diff --git a/chromium/cc/resources/resource_pool.h b/chromium/cc/resources/resource_pool.h
index e3393756555..d2c7788bcc3 100644
--- a/chromium/cc/resources/resource_pool.h
+++ b/chromium/cc/resources/resource_pool.h
@@ -8,10 +8,10 @@
#include <stddef.h>
#include <stdint.h>
-#include <deque>
#include <map>
#include <memory>
+#include "base/containers/circular_deque.h"
#include "base/macros.h"
#include "base/memory/memory_coordinator_client.h"
#include "base/memory/ptr_util.h"
@@ -187,7 +187,7 @@ class CC_EXPORT ResourcePool : public base::trace_event::MemoryDumpProvider,
size_t total_resource_count_ = 0;
// Holds most recently used resources at the front of the queue.
- using ResourceDeque = std::deque<std::unique_ptr<PoolResource>>;
+ using ResourceDeque = base::circular_deque<std::unique_ptr<PoolResource>>;
ResourceDeque unused_resources_;
ResourceDeque busy_resources_;
diff --git a/chromium/cc/resources/resource_pool_unittest.cc b/chromium/cc/resources/resource_pool_unittest.cc
index 14ddf372e74..6ebfb097e01 100644
--- a/chromium/cc/resources/resource_pool_unittest.cc
+++ b/chromium/cc/resources/resource_pool_unittest.cc
@@ -29,7 +29,7 @@ class ResourcePoolTest : public testing::Test {
task_runner_ = base::ThreadTaskRunnerHandle::Get();
resource_pool_ =
ResourcePool::Create(resource_provider_.get(), task_runner_.get(),
- ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ ResourceProvider::TEXTURE_HINT_DEFAULT,
ResourcePool::kDefaultExpirationDelay, false);
}
@@ -162,7 +162,7 @@ TEST_F(ResourcePoolTest, BusyResourcesEventuallyFreed) {
// to run.
resource_pool_ =
ResourcePool::Create(resource_provider_.get(), task_runner_.get(),
- ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ ResourceProvider::TEXTURE_HINT_DEFAULT,
base::TimeDelta::FromMilliseconds(10), false);
// Limits high enough to not be hit by this test.
@@ -203,7 +203,7 @@ TEST_F(ResourcePoolTest, UnusedResourcesEventuallyFreed) {
// to run.
resource_pool_ =
ResourcePool::Create(resource_provider_.get(), task_runner_.get(),
- ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ ResourceProvider::TEXTURE_HINT_DEFAULT,
base::TimeDelta::FromMilliseconds(100), false);
// Limits high enough to not be hit by this test.
@@ -407,29 +407,6 @@ TEST_F(ResourcePoolTest, MemoryStateSuspended) {
EXPECT_EQ(0u, resource_pool_->GetBusyResourceCountForTesting());
}
-TEST_F(ResourcePoolTest, TextureHintRespected) {
- gfx::Size size(100, 100);
- viz::ResourceFormat format = viz::RGBA_8888;
- gfx::ColorSpace color_space;
-
- resource_pool_ =
- ResourcePool::Create(resource_provider_.get(), task_runner_.get(),
- ResourceProvider::TEXTURE_HINT_IMMUTABLE,
- base::TimeDelta::FromMilliseconds(100), false);
- Resource* resource =
- resource_pool_->AcquireResource(size, format, color_space);
- EXPECT_TRUE(resource_provider_->IsImmutable(resource->id()));
- resource_pool_->ReleaseResource(resource);
-
- resource_pool_ =
- ResourcePool::Create(resource_provider_.get(), task_runner_.get(),
- ResourceProvider::TEXTURE_HINT_DEFAULT,
- base::TimeDelta::FromMilliseconds(100), false);
- resource = resource_pool_->AcquireResource(size, format, color_space);
- EXPECT_FALSE(resource_provider_->IsImmutable(resource->id()));
- resource_pool_->ReleaseResource(resource);
-}
-
TEST_F(ResourcePoolTest, ExactRequestsRespected) {
viz::ResourceFormat format = viz::RGBA_8888;
gfx::ColorSpace color_space = gfx::ColorSpace::CreateSRGB();
diff --git a/chromium/cc/resources/resource_provider.cc b/chromium/cc/resources/resource_provider.cc
index c1c28b5f2be..38b98f33663 100644
--- a/chromium/cc/resources/resource_provider.cc
+++ b/chromium/cc/resources/resource_provider.cc
@@ -12,6 +12,7 @@
#include <unordered_map>
#include "base/atomic_sequence_num.h"
+#include "base/bits.h"
#include "base/macros.h"
#include "base/metrics/histogram.h"
#include "base/numerics/safe_math.h"
@@ -106,6 +107,7 @@ GLenum TextureToStorageFormat(viz::ResourceFormat format) {
case viz::ETC1:
case viz::RED_8:
case viz::LUMINANCE_F16:
+ case viz::R16_EXT:
NOTREACHED();
break;
}
@@ -127,6 +129,7 @@ bool IsFormatSupportedForStorage(viz::ResourceFormat format, bool use_bgra) {
case viz::ETC1:
case viz::RED_8:
case viz::LUMINANCE_F16:
+ case viz::R16_EXT:
return false;
}
return false;
@@ -189,6 +192,7 @@ ResourceProvider::Resource::Resource(GLuint texture_id,
target(target),
original_filter(filter),
filter(filter),
+ min_filter(filter),
image_id(0),
hint(hint),
type(type),
@@ -225,8 +229,9 @@ ResourceProvider::Resource::Resource(uint8_t* pixels,
target(0),
original_filter(filter),
filter(filter),
+ min_filter(filter),
image_id(0),
- hint(TEXTURE_HINT_IMMUTABLE),
+ hint(TEXTURE_HINT_DEFAULT),
type(RESOURCE_TYPE_BITMAP),
buffer_format(gfx::BufferFormat::RGBA_8888),
format(viz::RGBA_8888),
@@ -262,8 +267,9 @@ ResourceProvider::Resource::Resource(const viz::SharedBitmapId& bitmap_id,
target(0),
original_filter(filter),
filter(filter),
+ min_filter(filter),
image_id(0),
- hint(TEXTURE_HINT_IMMUTABLE),
+ hint(TEXTURE_HINT_DEFAULT),
type(RESOURCE_TYPE_BITMAP),
buffer_format(gfx::BufferFormat::RGBA_8888),
format(viz::RGBA_8888),
@@ -317,22 +323,24 @@ void ResourceProvider::Resource::WaitSyncToken(gpu::gles2::GLES2Interface* gl) {
SetSynchronized();
}
-ResourceProvider::Child::Child()
- : marked_for_deletion(false), needs_sync_tokens(true) {}
-
-ResourceProvider::Child::Child(const Child& other) = default;
-
-ResourceProvider::Child::~Child() {}
+void ResourceProvider::Resource::SetGenerateMipmap() {
+ DCHECK(IsGpuResourceType(type));
+ DCHECK_EQ(target, static_cast<GLenum>(GL_TEXTURE_2D));
+ DCHECK(hint & TEXTURE_HINT_MIPMAP);
+ DCHECK(!gpu_memory_buffer);
+ mipmap_state = GENERATE;
+}
ResourceProvider::Settings::Settings(
viz::ContextProvider* compositor_context_provider,
bool delegated_sync_points_required,
- bool enable_color_correct_rasterization,
const viz::ResourceSettings& resource_settings)
: default_resource_type(resource_settings.use_gpu_memory_buffer_resources
? RESOURCE_TYPE_GPU_MEMORY_BUFFER
: RESOURCE_TYPE_GL_TEXTURE),
- enable_color_correct_rasterization(enable_color_correct_rasterization),
+ yuv_highbit_resource_format(resource_settings.high_bit_for_testing
+ ? viz::R16_EXT
+ : viz::LUMINANCE_8),
delegated_sync_points_required(delegated_sync_points_required) {
if (!compositor_context_provider) {
default_resource_type = RESOURCE_TYPE_BITMAP;
@@ -348,15 +356,17 @@ ResourceProvider::Settings::Settings(
use_texture_storage_ext = caps.texture_storage;
use_texture_format_bgra = caps.texture_format_bgra8888;
use_texture_usage_hint = caps.texture_usage;
+ use_texture_npot = caps.texture_npot;
use_sync_query = caps.sync_query;
if (caps.disable_one_component_textures) {
yuv_resource_format = yuv_highbit_resource_format = viz::RGBA_8888;
} else {
yuv_resource_format = caps.texture_rg ? viz::RED_8 : viz::LUMINANCE_8;
- yuv_highbit_resource_format = caps.texture_half_float_linear
- ? viz::LUMINANCE_F16
- : yuv_resource_format;
+ if (resource_settings.use_r16_texture && caps.texture_norm16)
+ yuv_highbit_resource_format = viz::R16_EXT;
+ else if (caps.texture_half_float_linear)
+ yuv_highbit_resource_format = viz::LUMINANCE_F16;
}
GLES2Interface* gl = compositor_context_provider->ContextGL();
@@ -372,18 +382,14 @@ ResourceProvider::ResourceProvider(
viz::ContextProvider* compositor_context_provider,
viz::SharedBitmapManager* shared_bitmap_manager,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
- BlockingTaskRunner* blocking_main_thread_task_runner,
bool delegated_sync_points_required,
- bool enable_color_correct_rasterization,
const viz::ResourceSettings& resource_settings)
: settings_(compositor_context_provider,
delegated_sync_points_required,
- enable_color_correct_rasterization,
resource_settings),
compositor_context_provider_(compositor_context_provider),
shared_bitmap_manager_(shared_bitmap_manager),
gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
- blocking_main_thread_task_runner_(blocking_main_thread_task_runner),
next_id_(1),
next_child_(1),
lost_context_provider_(false),
@@ -414,8 +420,6 @@ ResourceProvider::~ResourceProvider() {
base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
this);
- while (!children_.empty())
- DestroyChildInternal(children_.begin(), FOR_SHUTDOWN);
while (!resources_.empty())
DeleteResourceInternal(resources_.begin(), FOR_SHUTDOWN);
@@ -458,6 +462,8 @@ bool ResourceProvider::IsTextureFormatSupported(
return caps.texture_format_etc1;
case viz::RED_8:
return caps.texture_rg;
+ case viz::R16_EXT:
+ return caps.texture_norm16;
case viz::LUMINANCE_F16:
case viz::RGBA_F16:
return caps.texture_half_float_linear;
@@ -491,6 +497,7 @@ bool ResourceProvider::IsRenderBufferFormatSupported(
case viz::RED_8:
case viz::ETC1:
case viz::LUMINANCE_F16:
+ case viz::R16_EXT:
// We don't currently render into these formats. If we need to render into
// these eventually, we should expand this logic.
return false;
@@ -623,69 +630,6 @@ viz::ResourceId ResourceProvider::CreateBitmapResource(
return id;
}
-viz::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
- const viz::TextureMailbox& mailbox,
- std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl,
- bool read_lock_fences_enabled,
- gfx::BufferFormat buffer_format) {
- DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
- // Just store the information. Mailbox will be consumed in LockForRead().
- viz::ResourceId id = next_id_++;
- DCHECK(mailbox.IsValid());
- Resource* resource = nullptr;
- if (mailbox.IsTexture()) {
- resource = InsertResource(
- id, Resource(0, mailbox.size_in_pixels(), Resource::EXTERNAL,
- mailbox.target(),
- mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR,
- TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE,
- viz::RGBA_8888));
- } else {
- DCHECK(mailbox.IsSharedMemory());
- viz::SharedBitmap* shared_bitmap = mailbox.shared_bitmap();
- uint8_t* pixels = shared_bitmap->pixels();
- DCHECK(pixels);
- resource = InsertResource(
- id, Resource(pixels, shared_bitmap, mailbox.size_in_pixels(),
- Resource::EXTERNAL, GL_LINEAR));
- }
- resource->allocated = true;
- resource->SetMailbox(mailbox);
- resource->color_space = mailbox.color_space();
- resource->release_callback_impl =
- base::Bind(&SingleReleaseCallbackImpl::Run,
- base::Owned(release_callback_impl.release()));
- resource->read_lock_fences_enabled = read_lock_fences_enabled;
- resource->buffer_format = buffer_format;
- resource->is_overlay_candidate = mailbox.is_overlay_candidate();
-#if defined(OS_ANDROID)
- resource->is_backed_by_surface_texture =
- mailbox.is_backed_by_surface_texture();
- resource->wants_promotion_hint = mailbox.wants_promotion_hint();
- if (resource->wants_promotion_hint)
- wants_promotion_hints_set_.insert(id);
-#endif
- resource->color_space = mailbox.color_space();
-
- return id;
-}
-
-viz::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
- const viz::TextureMailbox& mailbox,
- std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl,
- bool read_lock_fences_enabled) {
- return CreateResourceFromTextureMailbox(
- mailbox, std::move(release_callback_impl), read_lock_fences_enabled,
- gfx::BufferFormat::RGBA_8888);
-}
-
-viz::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
- const viz::TextureMailbox& mailbox,
- std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl) {
- return CreateResourceFromTextureMailbox(
- mailbox, std::move(release_callback_impl), false);
-}
-
void ResourceProvider::DeleteResource(viz::ResourceId id) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
ResourceMap::iterator it = resources_.find(id);
@@ -759,8 +703,7 @@ void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it,
resource->shared_bitmap = nullptr;
resource->pixels = nullptr;
}
- resource->release_callback_impl.Run(sync_token, lost_resource,
- blocking_main_thread_task_runner_);
+ resource->release_callback.Run(sync_token, lost_resource);
}
if (resource->gl_id) {
@@ -802,16 +745,6 @@ GLenum ResourceProvider::GetResourceTextureTarget(viz::ResourceId id) {
return GetResource(id)->target;
}
-bool ResourceProvider::IsImmutable(viz::ResourceId id) {
- if (IsGpuResourceType(settings_.default_resource_type)) {
- return GetTextureHint(id) == TEXTURE_HINT_IMMUTABLE;
- } else {
- // Software resources are immutable; they cannot change format or be
- // resized.
- return true;
- }
-}
-
ResourceProvider::TextureHint ResourceProvider::GetTextureHint(
viz::ResourceId id) {
return GetResource(id)->hint;
@@ -819,8 +752,6 @@ ResourceProvider::TextureHint ResourceProvider::GetTextureHint(
gfx::ColorSpace ResourceProvider::GetResourceColorSpaceForRaster(
const Resource* resource) const {
- if (!settings_.enable_color_correct_rasterization)
- return gfx::ColorSpace();
return resource->color_space;
}
@@ -890,83 +821,13 @@ ResourceProvider::Resource* ResourceProvider::GetResource(viz::ResourceId id) {
return &it->second;
}
-const ResourceProvider::Resource* ResourceProvider::LockForRead(
- viz::ResourceId id) {
- Resource* resource = GetResource(id);
- DCHECK(!resource->locked_for_write)
- << "locked for write: " << resource->locked_for_write;
- DCHECK_EQ(resource->exported_count, 0);
- // Uninitialized! Call SetPixels or LockForWrite first.
- DCHECK(resource->allocated);
-
- // Mailbox sync_tokens must be processed by a call to WaitSyncToken() prior to
- // calling LockForRead().
- DCHECK_NE(Resource::NEEDS_WAIT, resource->synchronization_state());
-
- if (IsGpuResourceType(resource->type) && !resource->gl_id) {
- DCHECK(resource->origin != Resource::INTERNAL);
- DCHECK(resource->mailbox().IsTexture());
-
- GLES2Interface* gl = ContextGL();
- DCHECK(gl);
- resource->gl_id = gl->CreateAndConsumeTextureCHROMIUM(
- resource->mailbox().target(), resource->mailbox().name());
- resource->SetLocallyUsed();
- }
-
- if (!resource->pixels && resource->has_shared_bitmap_id &&
- shared_bitmap_manager_) {
- std::unique_ptr<viz::SharedBitmap> bitmap =
- shared_bitmap_manager_->GetSharedBitmapFromId(
- resource->size, resource->shared_bitmap_id);
- if (bitmap) {
- resource->shared_bitmap = bitmap.release();
- resource->pixels = resource->shared_bitmap->pixels();
- }
- }
-
- resource->lock_for_read_count++;
- if (resource->read_lock_fences_enabled) {
- if (current_read_lock_fence_.get())
- current_read_lock_fence_->Set();
- resource->read_lock_fence = current_read_lock_fence_;
- }
-
- return resource;
-}
-
-void ResourceProvider::UnlockForRead(viz::ResourceId id) {
- DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
- ResourceMap::iterator it = resources_.find(id);
- CHECK(it != resources_.end());
-
- Resource* resource = &it->second;
- DCHECK_GT(resource->lock_for_read_count, 0);
- DCHECK_EQ(resource->exported_count, 0);
- resource->lock_for_read_count--;
- if (resource->marked_for_deletion && !resource->lock_for_read_count) {
- if (!resource->child_id) {
- // The resource belongs to this ResourceProvider, so it can be destroyed.
- DeleteResourceInternal(it, NORMAL);
- } else {
- if (batch_return_resources_) {
- batched_returning_resources_[resource->child_id].push_back(id);
- } else {
- ChildMap::iterator child_it = children_.find(resource->child_id);
- ResourceIdArray unused;
- unused.push_back(id);
- DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, unused);
- }
- }
- }
-}
-
ResourceProvider::Resource* ResourceProvider::LockForWrite(viz::ResourceId id) {
DCHECK(CanLockForWrite(id));
Resource* resource = GetResource(id);
resource->WaitSyncToken(ContextGL());
resource->SetLocallyUsed();
resource->locked_for_write = true;
+ resource->mipmap_state = Resource::INVALID;
return resource;
}
@@ -1060,6 +921,8 @@ ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() {
resource->UpdateSyncToken(sync_token_);
if (synchronized_)
resource->SetSynchronized();
+ if (generate_mipmap_)
+ resource->SetGenerateMipmap();
resource_provider_->UnlockForWrite(resource);
}
@@ -1144,10 +1007,14 @@ void ResourceProvider::ScopedWriteLockGL::AllocateTexture(
gl->BindTexture(target_, texture_id);
const ResourceProvider::Settings& settings = resource_provider_->settings_;
if (settings.use_texture_storage_ext &&
- IsFormatSupportedForStorage(format_, settings.use_texture_format_bgra) &&
- (hint_ & ResourceProvider::TEXTURE_HINT_IMMUTABLE)) {
+ IsFormatSupportedForStorage(format_, settings.use_texture_format_bgra)) {
GLenum storage_format = TextureToStorageFormat(format_);
- gl->TexStorage2DEXT(target_, 1, storage_format, size_.width(),
+ GLint levels = 1;
+ if (settings.use_texture_npot &&
+ (hint_ & ResourceProvider::TEXTURE_HINT_MIPMAP)) {
+ levels += base::bits::Log2Floor(std::max(size_.width(), size_.height()));
+ }
+ gl->TexStorage2DEXT(target_, levels, storage_format, size_.width(),
size_.height());
} else {
gl->TexImage2D(target_, 0, GLInternalFormat(format_), size_.width(),
@@ -1211,6 +1078,7 @@ ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() {
resource->SetSynchronized();
resource_provider_->UnlockForWrite(resource);
}
+
ResourceProvider::SynchronousFence::SynchronousFence(
gpu::gles2::GLES2Interface* gl)
: gl_(gl), has_synchronized_(true) {}
@@ -1238,142 +1106,6 @@ void ResourceProvider::SynchronousFence::Synchronize() {
gl_->Finish();
}
-void ResourceProvider::DestroyChildInternal(ChildMap::iterator it,
- DeleteStyle style) {
- DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
-
- Child& child = it->second;
- DCHECK(style == FOR_SHUTDOWN || !child.marked_for_deletion);
-
- ResourceIdArray resources_for_child;
-
- for (ResourceIdMap::iterator child_it = child.child_to_parent_map.begin();
- child_it != child.child_to_parent_map.end(); ++child_it) {
- viz::ResourceId id = child_it->second;
- resources_for_child.push_back(id);
- }
-
- child.marked_for_deletion = true;
-
- DeleteAndReturnUnusedResourcesToChild(it, style, resources_for_child);
-}
-
-void ResourceProvider::DeleteAndReturnUnusedResourcesToChild(
- ChildMap::iterator child_it,
- DeleteStyle style,
- const ResourceIdArray& unused) {
- DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
- DCHECK(child_it != children_.end());
- Child* child_info = &child_it->second;
-
- if (unused.empty() && !child_info->marked_for_deletion)
- return;
-
- std::vector<viz::ReturnedResource> to_return;
- to_return.reserve(unused.size());
- std::vector<viz::ReturnedResource*> need_synchronization_resources;
- std::vector<GLbyte*> unverified_sync_tokens;
-
- GLES2Interface* gl = ContextGL();
-
- for (viz::ResourceId local_id : unused) {
- ResourceMap::iterator it = resources_.find(local_id);
- CHECK(it != resources_.end());
- Resource& resource = it->second;
-
- DCHECK(!resource.locked_for_write);
-
- viz::ResourceId child_id = resource.id_in_child;
- DCHECK(child_info->child_to_parent_map.count(child_id));
-
- bool is_lost = resource.lost ||
- (IsGpuResourceType(resource.type) && lost_context_provider_);
- if (resource.exported_count > 0 || resource.lock_for_read_count > 0) {
- if (style != FOR_SHUTDOWN) {
- // Defer this resource deletion.
- resource.marked_for_deletion = true;
- continue;
- }
- // We can't postpone the deletion, so we'll have to lose it.
- is_lost = true;
- } else if (!ReadLockFenceHasPassed(&resource)) {
- // TODO(dcastagna): see if it's possible to use this logic for
- // the branch above too, where the resource is locked or still exported.
- if (style != FOR_SHUTDOWN && !child_info->marked_for_deletion) {
- // Defer this resource deletion.
- resource.marked_for_deletion = true;
- continue;
- }
- // We can't postpone the deletion, so we'll have to lose it.
- is_lost = true;
- }
-
- if (IsGpuResourceType(resource.type) &&
- resource.filter != resource.original_filter) {
- DCHECK(resource.target);
- DCHECK(resource.gl_id);
- DCHECK(gl);
- gl->BindTexture(resource.target, resource.gl_id);
- gl->TexParameteri(resource.target, GL_TEXTURE_MIN_FILTER,
- resource.original_filter);
- gl->TexParameteri(resource.target, GL_TEXTURE_MAG_FILTER,
- resource.original_filter);
- resource.SetLocallyUsed();
- }
-
- viz::ReturnedResource returned;
- returned.id = child_id;
- returned.sync_token = resource.mailbox().sync_token();
- returned.count = resource.imported_count;
- returned.lost = is_lost;
- to_return.push_back(returned);
-
- if (IsGpuResourceType(resource.type) && child_info->needs_sync_tokens) {
- if (resource.needs_sync_token()) {
- need_synchronization_resources.push_back(&to_return.back());
- } else if (returned.sync_token.HasData() &&
- !returned.sync_token.verified_flush()) {
- // Before returning any sync tokens, they must be verified.
- unverified_sync_tokens.push_back(returned.sync_token.GetData());
- }
- }
-
- child_info->child_to_parent_map.erase(child_id);
- resource.imported_count = 0;
- DeleteResourceInternal(it, style);
- }
-
- gpu::SyncToken new_sync_token;
- if (!need_synchronization_resources.empty()) {
- DCHECK(child_info->needs_sync_tokens);
- DCHECK(gl);
- const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM();
- gl->OrderingBarrierCHROMIUM();
- gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData());
- unverified_sync_tokens.push_back(new_sync_token.GetData());
- }
-
- if (!unverified_sync_tokens.empty()) {
- DCHECK(child_info->needs_sync_tokens);
- DCHECK(gl);
- gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(),
- unverified_sync_tokens.size());
- }
-
- // Set sync token after verification.
- for (viz::ReturnedResource* returned : need_synchronization_resources)
- returned->sync_token = new_sync_token;
-
- if (!to_return.empty())
- child_info->return_callback.Run(to_return,
- blocking_main_thread_task_runner_);
-
- if (child_info->marked_for_deletion &&
- child_info->child_to_parent_map.empty()) {
- children_.erase(child_it);
- }
-}
-
GLenum ResourceProvider::BindForSampling(viz::ResourceId resource_id,
GLenum unit,
GLenum filter) {
@@ -1388,8 +1120,26 @@ GLenum ResourceProvider::BindForSampling(viz::ResourceId resource_id,
ScopedSetActiveTexture scoped_active_tex(gl, unit);
GLenum target = resource->target;
gl->BindTexture(target, resource->gl_id);
+ GLenum min_filter = filter;
+ if (filter == GL_LINEAR) {
+ switch (resource->mipmap_state) {
+ case Resource::INVALID:
+ break;
+ case Resource::GENERATE:
+ DCHECK(settings_.use_texture_npot);
+ gl->GenerateMipmap(target);
+ resource->mipmap_state = Resource::VALID;
+ // fall-through
+ case Resource::VALID:
+ min_filter = GL_LINEAR_MIPMAP_LINEAR;
+ break;
+ }
+ }
+ if (min_filter != resource->min_filter) {
+ gl->TexParameteri(target, GL_TEXTURE_MIN_FILTER, min_filter);
+ resource->min_filter = min_filter;
+ }
if (filter != resource->filter) {
- gl->TexParameteri(target, GL_TEXTURE_MIN_FILTER, filter);
gl->TexParameteri(target, GL_TEXTURE_MAG_FILTER, filter);
resource->filter = filter;
}
diff --git a/chromium/cc/resources/resource_provider.h b/chromium/cc/resources/resource_provider.h
index 1b0b67b00a4..7a0927b8f0a 100644
--- a/chromium/cc/resources/resource_provider.h
+++ b/chromium/cc/resources/resource_provider.h
@@ -8,7 +8,6 @@
#include <stddef.h>
#include <stdint.h>
-#include <deque>
#include <memory>
#include <set>
#include <string>
@@ -25,16 +24,16 @@
#include "base/trace_event/memory_allocator_dump.h"
#include "base/trace_event/memory_dump_provider.h"
#include "cc/cc_export.h"
-#include "cc/resources/release_callback_impl.h"
#include "cc/resources/return_callback.h"
-#include "cc/resources/single_release_callback_impl.h"
#include "components/viz/common/display/renderer_settings.h"
#include "components/viz/common/gpu/context_provider.h"
#include "components/viz/common/quads/shared_bitmap.h"
#include "components/viz/common/quads/texture_mailbox.h"
+#include "components/viz/common/resources/release_callback.h"
#include "components/viz/common/resources/resource_format.h"
#include "components/viz/common/resources/resource_id.h"
#include "components/viz/common/resources/resource_settings.h"
+#include "components/viz/common/resources/single_release_callback.h"
#include "components/viz/common/resources/transferable_resource.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
@@ -58,9 +57,19 @@ class SharedBitmapManager;
} // namespace viz
namespace cc {
-class BlockingTaskRunner;
class TextureIdAllocator;
+// This class provides abstractions for allocating and transferring resources
+// between modules/threads/processes. It abstracts away GL textures vs
+// GpuMemoryBuffers vs software bitmaps behind a single ResourceId so that
+// code in common can hold onto ResourceIds, as long as the code using them
+// knows the correct type.
+//
+// The resource's underlying type is accessed through Read and Write locks that
+// help to safeguard correct usage with DCHECKs. All resources held in
+// ResourceProvider are immutable - they can not change format or size once
+// they are created, only their contents.
+//
// This class is not thread-safe and can only be called from the thread it was
// created on (in practice, the impl thread).
class CC_EXPORT ResourceProvider
@@ -73,10 +82,10 @@ class CC_EXPORT ResourceProvider
using ResourceIdMap = std::unordered_map<viz::ResourceId, viz::ResourceId>;
enum TextureHint {
TEXTURE_HINT_DEFAULT = 0x0,
- TEXTURE_HINT_IMMUTABLE = 0x1,
+ TEXTURE_HINT_MIPMAP = 0x1,
TEXTURE_HINT_FRAMEBUFFER = 0x2,
- TEXTURE_HINT_IMMUTABLE_FRAMEBUFFER =
- TEXTURE_HINT_IMMUTABLE | TEXTURE_HINT_FRAMEBUFFER
+ TEXTURE_HINT_MIPMAP_FRAMEBUFFER =
+ TEXTURE_HINT_MIPMAP | TEXTURE_HINT_FRAMEBUFFER
};
enum ResourceType {
RESOURCE_TYPE_GPU_MEMORY_BUFFER,
@@ -87,9 +96,7 @@ class CC_EXPORT ResourceProvider
ResourceProvider(viz::ContextProvider* compositor_context_provider,
viz::SharedBitmapManager* shared_bitmap_manager,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
- BlockingTaskRunner* blocking_main_thread_task_runner,
bool delegated_sync_points_required,
- bool enable_color_correct_rasterization,
const viz::ResourceSettings& resource_settings);
~ResourceProvider() override;
@@ -136,7 +143,6 @@ class CC_EXPORT ResourceProvider
}
ResourceType GetResourceType(viz::ResourceId id);
GLenum GetResourceTextureTarget(viz::ResourceId id);
- bool IsImmutable(viz::ResourceId id);
TextureHint GetTextureHint(viz::ResourceId id);
// Creates a resource of the default resource type.
@@ -154,22 +160,6 @@ class CC_EXPORT ResourceProvider
gfx::BufferUsage usage,
const gfx::ColorSpace& color_space);
- // Wraps an external texture mailbox into a GL resource.
- viz::ResourceId CreateResourceFromTextureMailbox(
- const viz::TextureMailbox& mailbox,
- std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl);
-
- viz::ResourceId CreateResourceFromTextureMailbox(
- const viz::TextureMailbox& mailbox,
- std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl,
- bool read_lock_fences_enabled);
-
- viz::ResourceId CreateResourceFromTextureMailbox(
- const viz::TextureMailbox& mailbox,
- std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl,
- bool read_lock_fences_enabled,
- gfx::BufferFormat buffer_format);
-
void DeleteResource(viz::ResourceId id);
// In the case of GPU resources, we may need to flush the GL context to ensure
// that texture deletions are seen in a timely fashion. This function should
@@ -196,9 +186,6 @@ class CC_EXPORT ResourceProvider
GLenum target() const { return target_; }
viz::ResourceFormat format() const { return format_; }
const gfx::Size& size() const { return size_; }
-
- // Will return an invalid color space unless
- // |enable_color_correct_rasterization| is true.
const gfx::ColorSpace& color_space_for_raster() const {
return color_space_;
}
@@ -212,6 +199,8 @@ class CC_EXPORT ResourceProvider
void set_synchronized() { synchronized_ = true; }
+ void set_generate_mipmap() { generate_mipmap_ = true; }
+
// Returns texture id on compositor context, allocating if necessary.
GLuint GetTexture();
@@ -251,6 +240,7 @@ class CC_EXPORT ResourceProvider
gpu::SyncToken sync_token_;
bool has_sync_token_ = false;
bool synchronized_ = false;
+ bool generate_mipmap_ = false;
DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL);
};
@@ -284,8 +274,6 @@ class CC_EXPORT ResourceProvider
SkBitmap& sk_bitmap() { return sk_bitmap_; }
bool valid() const { return !!sk_bitmap_.getPixels(); }
- // Will return the invalid color space unless
- // |enable_color_correct_rasterization| is true.
const gfx::ColorSpace& color_space_for_raster() const {
return color_space_;
}
@@ -345,11 +333,6 @@ class CC_EXPORT ResourceProvider
// For tests only!
void CreateForTesting(viz::ResourceId id);
- // Sets the current read fence. If a resource is locked for read
- // and has read fences enabled, the resource will not allow writes
- // until this fence has passed.
- void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; }
-
// Indicates if we can currently lock this resource for write.
bool CanLockForWrite(viz::ResourceId id);
@@ -420,6 +403,7 @@ class CC_EXPORT ResourceProvider
// external resource for others to wait on.
SYNCHRONIZED,
};
+ enum MipmapState { INVALID, GENERATE, VALID };
Resource(GLuint texture_id,
const gfx::Size& size,
@@ -458,11 +442,12 @@ class CC_EXPORT ResourceProvider
void UpdateSyncToken(const gpu::SyncToken& sync_token);
int8_t* GetSyncTokenData();
void WaitSyncToken(gpu::gles2::GLES2Interface* sync_token);
+ void SetGenerateMipmap();
int child_id;
viz::ResourceId id_in_child;
GLuint gl_id;
- ReleaseCallbackImpl release_callback_impl;
+ viz::ReleaseCallback release_callback;
uint8_t* pixels;
int lock_for_read_count;
int imported_count;
@@ -495,6 +480,7 @@ class CC_EXPORT ResourceProvider
// TODO(skyostil): Use a separate sampler object for filter state.
GLenum original_filter;
GLenum filter;
+ GLenum min_filter;
GLuint image_id;
TextureHint hint;
ResourceType type;
@@ -513,6 +499,7 @@ class CC_EXPORT ResourceProvider
viz::SharedBitmap* shared_bitmap;
std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer;
gfx::ColorSpace color_space;
+ MipmapState mipmap_state = INVALID;
private:
SynchronizationState synchronization_state_ = SYNCHRONIZED;
@@ -522,22 +509,8 @@ class CC_EXPORT ResourceProvider
};
using ResourceMap = std::unordered_map<viz::ResourceId, Resource>;
- struct Child {
- Child();
- Child(const Child& other);
- ~Child();
-
- ResourceIdMap child_to_parent_map;
- ReturnCallback return_callback;
- bool marked_for_deletion;
- bool needs_sync_tokens;
- };
- using ChildMap = std::unordered_map<int, Child>;
-
Resource* InsertResource(viz::ResourceId id, Resource resource);
Resource* GetResource(viz::ResourceId id);
- const Resource* LockForRead(viz::ResourceId id);
- void UnlockForRead(viz::ResourceId id);
Resource* LockForWrite(viz::ResourceId id);
void UnlockForWrite(Resource* resource);
@@ -553,8 +526,6 @@ class CC_EXPORT ResourceProvider
GLenum unit,
GLenum filter);
- // Will return the invalid color space unless
- // |enable_color_correct_rasterization| is true.
gfx::ColorSpace GetResourceColorSpaceForRaster(
const Resource* resource) const;
@@ -563,13 +534,14 @@ class CC_EXPORT ResourceProvider
FOR_SHUTDOWN,
};
void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style);
- void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it,
- DeleteStyle style,
- const ResourceIdArray& unused);
- void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style);
void CreateMailbox(Resource* resource);
+ bool ReadLockFenceHasPassed(const Resource* resource) {
+ return !resource->read_lock_fence.get() ||
+ resource->read_lock_fence->HasPassed();
+ }
+
// Returns null if we do not have a viz::ContextProvider.
gpu::gles2::GLES2Interface* ContextGL() const;
@@ -577,25 +549,23 @@ class CC_EXPORT ResourceProvider
struct Settings {
Settings(viz::ContextProvider* compositor_context_provider,
bool delegated_sync_points_needed,
- bool enable_color_correct_rasterization,
const viz::ResourceSettings& resource_settings);
int max_texture_size = 0;
bool use_texture_storage_ext = false;
bool use_texture_format_bgra = false;
bool use_texture_usage_hint = false;
+ bool use_texture_npot = false;
bool use_sync_query = false;
ResourceType default_resource_type = RESOURCE_TYPE_GL_TEXTURE;
viz::ResourceFormat yuv_resource_format = viz::LUMINANCE_8;
viz::ResourceFormat yuv_highbit_resource_format = viz::LUMINANCE_8;
viz::ResourceFormat best_texture_format = viz::RGBA_8888;
viz::ResourceFormat best_render_buffer_format = viz::RGBA_8888;
- bool enable_color_correct_rasterization = false;
bool delegated_sync_points_required = false;
} const settings_;
ResourceMap resources_;
- ChildMap children_;
// Keep track of whether deleted resources should be batched up or returned
// immediately.
@@ -606,10 +576,11 @@ class CC_EXPORT ResourceProvider
viz::ContextProvider* compositor_context_provider_;
viz::SharedBitmapManager* shared_bitmap_manager_;
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_;
- BlockingTaskRunner* blocking_main_thread_task_runner_;
viz::ResourceId next_id_;
int next_child_;
+ bool lost_context_provider_;
+
THREAD_CHECKER(thread_checker_);
#if defined(OS_ANDROID)
@@ -618,11 +589,6 @@ class CC_EXPORT ResourceProvider
#endif
private:
- bool ReadLockFenceHasPassed(const Resource* resource) {
- return !resource->read_lock_fence.get() ||
- resource->read_lock_fence->HasPassed();
- }
-
viz::ResourceId CreateGpuResource(const gfx::Size& size,
TextureHint hint,
ResourceType type,
@@ -636,8 +602,6 @@ class CC_EXPORT ResourceProvider
bool IsGLContextLost() const;
- bool lost_context_provider_;
- scoped_refptr<Fence> current_read_lock_fence_;
std::unique_ptr<TextureIdAllocator> texture_id_allocator_;
viz::BufferToTextureTargetMap buffer_to_texture_target_map_;
diff --git a/chromium/cc/resources/resource_provider_unittest.cc b/chromium/cc/resources/resource_provider_unittest.cc
index f3604864565..5446e34d7c2 100644
--- a/chromium/cc/resources/resource_provider_unittest.cc
+++ b/chromium/cc/resources/resource_provider_unittest.cc
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <algorithm>
-#include <deque>
#include <map>
#include <set>
#include <unordered_map>
@@ -23,12 +22,11 @@
#include "cc/test/test_shared_bitmap_manager.h"
#include "cc/test/test_texture.h"
#include "cc/test/test_web_graphics_context_3d.h"
-#include "cc/trees/blocking_task_runner.h"
-#include "components/viz/common/quads/single_release_callback.h"
#include "components/viz/common/resources/buffer_to_texture_target_map.h"
#include "components/viz/common/resources/resource_format_utils.h"
#include "components/viz/common/resources/returned_resource.h"
#include "components/viz/common/resources/shared_bitmap_manager.h"
+#include "components/viz/common/resources/single_release_callback.h"
#include "components/viz/test/test_gpu_memory_buffer_manager.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -49,7 +47,6 @@ namespace cc {
namespace {
static const bool kUseGpuMemoryBufferResources = false;
-static const bool kEnableColorCorrectRendering = false;
static const bool kDelegatedSyncPointsRequired = true;
MATCHER_P(MatchesSyncToken, sync_token, "") {
@@ -59,26 +56,20 @@ MATCHER_P(MatchesSyncToken, sync_token, "") {
}
static void EmptyReleaseCallback(const gpu::SyncToken& sync_token,
- bool lost_resource,
- BlockingTaskRunner* main_thread_task_runner) {}
+ bool lost_resource) {}
-static void ReleaseCallback(
- gpu::SyncToken* release_sync_token,
- bool* release_lost_resource,
- BlockingTaskRunner** release_main_thread_task_runner,
- const gpu::SyncToken& sync_token,
- bool lost_resource,
- BlockingTaskRunner* main_thread_task_runner) {
+static void ReleaseCallback(gpu::SyncToken* release_sync_token,
+ bool* release_lost_resource,
+ const gpu::SyncToken& sync_token,
+ bool lost_resource) {
*release_sync_token = sync_token;
*release_lost_resource = lost_resource;
- *release_main_thread_task_runner = main_thread_task_runner;
}
static void SharedBitmapReleaseCallback(
std::unique_ptr<viz::SharedBitmap> bitmap,
const gpu::SyncToken& sync_token,
- bool lost_resource,
- BlockingTaskRunner* main_thread_task_runner) {}
+ bool lost_resource) {}
static void ReleaseSharedBitmapCallback(
std::unique_ptr<viz::SharedBitmap> shared_bitmap,
@@ -86,8 +77,7 @@ static void ReleaseSharedBitmapCallback(
gpu::SyncToken* release_sync_token,
bool* lost_resource_result,
const gpu::SyncToken& sync_token,
- bool lost_resource,
- BlockingTaskRunner* main_thread_task_runner) {
+ bool lost_resource) {
*release_called = true;
*release_sync_token = sync_token;
*lost_resource_result = lost_resource;
@@ -400,7 +390,7 @@ class ResourceProviderContext : public TestWebGraphicsContext3D {
};
ContextSharedData* shared_data_;
gpu::SyncToken last_waited_sync_token_;
- std::deque<std::unique_ptr<PendingProduceTexture>> pending_produce_textures_;
+ std::vector<std::unique_ptr<PendingProduceTexture>> pending_produce_textures_;
};
void GetResourcePixels(DisplayResourceProvider* resource_provider,
@@ -422,9 +412,8 @@ void GetResourcePixels(DisplayResourceProvider* resource_provider,
case ResourceProvider::RESOURCE_TYPE_BITMAP: {
DisplayResourceProvider::ScopedReadLockSoftware lock_software(
resource_provider, id);
- memcpy(pixels,
- lock_software.sk_bitmap()->getPixels(),
- lock_software.sk_bitmap()->getSize());
+ memcpy(pixels, lock_software.sk_bitmap()->getPixels(),
+ lock_software.sk_bitmap()->computeByteSize());
break;
}
}
@@ -436,18 +425,16 @@ class ResourceProviderTest
explicit ResourceProviderTest(bool child_needs_sync_token)
: shared_data_(ContextSharedData::Create()),
context3d_(NULL),
- child_context_(NULL),
- main_thread_task_runner_(BlockingTaskRunner::Create(NULL)) {
+ child_context_(NULL) {
switch (GetParam()) {
case ResourceProvider::RESOURCE_TYPE_GPU_MEMORY_BUFFER:
case ResourceProvider::RESOURCE_TYPE_GL_TEXTURE: {
- std::unique_ptr<ResourceProviderContext> context3d(
- ResourceProviderContext::Create(shared_data_.get()));
+ auto context3d(ResourceProviderContext::Create(shared_data_.get()));
context3d_ = context3d.get();
context_provider_ = TestContextProvider::Create(std::move(context3d));
context_provider_->BindToCurrentThread();
- std::unique_ptr<ResourceProviderContext> child_context_owned =
+ auto child_context_owned =
ResourceProviderContext::Create(shared_data_.get());
child_context_ = child_context_owned.get();
child_context_provider_ =
@@ -468,13 +455,10 @@ class ResourceProviderTest
viz::ResourceSettings resource_settings = CreateResourceSettings();
resource_provider_ = std::make_unique<DisplayResourceProvider>(
context_provider_.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), main_thread_task_runner_.get(),
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- resource_settings);
+ gpu_memory_buffer_manager_.get(), resource_settings);
child_resource_provider_ = std::make_unique<LayerTreeResourceProvider>(
child_context_provider_.get(), shared_bitmap_manager_.get(),
- child_gpu_memory_buffer_manager_.get(), main_thread_task_runner_.get(),
- child_needs_sync_token, kEnableColorCorrectRendering,
+ child_gpu_memory_buffer_manager_.get(), child_needs_sync_token,
resource_settings);
}
@@ -482,8 +466,7 @@ class ResourceProviderTest
static void CollectResources(
std::vector<viz::ReturnedResource>* array,
- const std::vector<viz::ReturnedResource>& returned,
- BlockingTaskRunner* main_thread_task_runner) {
+ const std::vector<viz::ReturnedResource>& returned) {
array->insert(array->end(), returned.begin(), returned.end());
}
@@ -516,8 +499,8 @@ class ResourceProviderTest
EXPECT_TRUE(sync_token->HasData());
std::unique_ptr<viz::SharedBitmap> shared_bitmap;
- std::unique_ptr<SingleReleaseCallbackImpl> callback =
- SingleReleaseCallbackImpl::Create(base::Bind(
+ std::unique_ptr<viz::SingleReleaseCallback> callback =
+ viz::SingleReleaseCallback::Create(base::Bind(
ReleaseSharedBitmapCallback, base::Passed(&shared_bitmap),
release_called, release_sync_token, lost_resource));
return child_resource_provider_->CreateResourceFromTextureMailbox(
@@ -529,8 +512,8 @@ class ResourceProviderTest
CreateAndFillSharedBitmap(shared_bitmap_manager_.get(), size, 0));
viz::SharedBitmap* shared_bitmap_ptr = shared_bitmap.get();
- std::unique_ptr<SingleReleaseCallbackImpl> callback =
- SingleReleaseCallbackImpl::Create(base::Bind(
+ std::unique_ptr<viz::SingleReleaseCallback> callback =
+ viz::SingleReleaseCallback::Create(base::Bind(
ReleaseSharedBitmapCallback, base::Passed(&shared_bitmap),
release_called, release_sync_token, lost_resource));
return child_resource_provider_->CreateResourceFromTextureMailbox(
@@ -544,7 +527,6 @@ class ResourceProviderTest
ResourceProviderContext* child_context_;
scoped_refptr<TestContextProvider> context_provider_;
scoped_refptr<TestContextProvider> child_context_provider_;
- std::unique_ptr<BlockingTaskRunner> main_thread_task_runner_;
std::unique_ptr<viz::TestGpuMemoryBufferManager> gpu_memory_buffer_manager_;
std::unique_ptr<DisplayResourceProvider> resource_provider_;
std::unique_ptr<viz::TestGpuMemoryBufferManager>
@@ -564,8 +546,7 @@ void CheckCreateResource(ResourceProvider::ResourceType expected_default_type,
ASSERT_EQ(4U, pixel_size);
viz::ResourceId id = resource_provider->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
EXPECT_EQ(1, static_cast<int>(resource_provider->num_resources()));
if (expected_default_type == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
EXPECT_EQ(0u, context->NumTextures());
@@ -596,8 +577,7 @@ TEST_P(ResourceProviderTest, SimpleUpload) {
ASSERT_EQ(16U, pixel_size);
viz::ResourceId id = resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t image[16] = {0};
resource_provider_->CopyToResource(id, image, size);
@@ -632,18 +612,17 @@ TEST_P(ResourceProviderTest, TransferGLResources) {
gfx::ColorSpace color_space1 = gfx::ColorSpace::CreateSRGB();
viz::ResourceId id1 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, color_space1);
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, color_space1);
uint8_t data1[4] = { 1, 2, 3, 4 };
child_resource_provider_->CopyToResource(id1, data1, size);
viz::ResourceId id2 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t data2[4] = { 5, 5, 5, 5 };
child_resource_provider_->CopyToResource(id2, data2, size);
viz::ResourceId id3 = child_resource_provider_->CreateGpuMemoryBufferResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format,
gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gfx::ColorSpace());
{
LayerTreeResourceProvider::ScopedWriteLockGpuMemoryBuffer lock(
@@ -668,8 +647,8 @@ TEST_P(ResourceProviderTest, TransferGLResources) {
id4_mailbox.set_color_space(color_space4);
viz::ResourceId id4 =
child_resource_provider_->CreateResourceFromTextureMailbox(
- id4_mailbox,
- SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)));
+ id4_mailbox, viz::SingleReleaseCallback::Create(
+ base::Bind(&EmptyReleaseCallback)));
std::vector<viz::ReturnedResource> returned_to_child;
int child_id =
@@ -917,8 +896,8 @@ TEST_P(ResourceProviderTest, OverlayPromotionHint) {
id1_mailbox.set_is_backed_by_surface_texture(true);
viz::ResourceId id1 =
child_resource_provider_->CreateResourceFromTextureMailbox(
- id1_mailbox,
- SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)));
+ id1_mailbox, viz::SingleReleaseCallback::Create(
+ base::Bind(&EmptyReleaseCallback)));
viz::TextureMailbox id2_mailbox(external_mailbox, external_sync_token,
GL_TEXTURE_EXTERNAL_OES);
@@ -927,8 +906,8 @@ TEST_P(ResourceProviderTest, OverlayPromotionHint) {
id2_mailbox.set_is_backed_by_surface_texture(false);
viz::ResourceId id2 =
child_resource_provider_->CreateResourceFromTextureMailbox(
- id2_mailbox,
- SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)));
+ id2_mailbox, viz::SingleReleaseCallback::Create(
+ base::Bind(&EmptyReleaseCallback)));
std::vector<viz::ReturnedResource> returned_to_child;
int child_id =
@@ -1006,13 +985,12 @@ TEST_P(ResourceProviderTestNoSyncToken, TransferGLResources) {
ASSERT_EQ(4U, pixel_size);
viz::ResourceId id1 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t data1[4] = {1, 2, 3, 4};
child_resource_provider_->CopyToResource(id1, data1, size);
viz::ResourceId id2 = child_resource_provider_->CreateGpuMemoryBufferResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format,
gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gfx::ColorSpace());
{
// Ensure locking the memory buffer doesn't create an unnecessary sync
@@ -1037,7 +1015,8 @@ TEST_P(ResourceProviderTestNoSyncToken, TransferGLResources) {
child_resource_provider_->CreateResourceFromTextureMailbox(
viz::TextureMailbox(external_mailbox, external_sync_token,
GL_TEXTURE_EXTERNAL_OES),
- SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)));
+ viz::SingleReleaseCallback::Create(
+ base::Bind(&EmptyReleaseCallback)));
std::vector<viz::ReturnedResource> returned_to_child;
int child_id =
@@ -1122,7 +1101,7 @@ TEST_P(ResourceProviderTest, SetBatchPreventsReturn) {
viz::ResourceId ids[2];
for (size_t i = 0; i < arraysize(ids); i++) {
ids[i] = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format,
gfx::ColorSpace());
child_resource_provider_->CopyToResource(ids[i], data1, size);
resource_ids_to_transfer.push_back(ids[i]);
@@ -1175,8 +1154,7 @@ TEST_P(ResourceProviderTest, ReadLockCountStopsReturnToChildOrDelete) {
viz::ResourceFormat format = viz::RGBA_8888;
viz::ResourceId id1 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t data1[4] = {1, 2, 3, 4};
child_resource_provider_->CopyToResource(id1, data1, size);
@@ -1237,8 +1215,7 @@ TEST_P(ResourceProviderTest, ReadLockFenceStopsReturnToChildOrDelete) {
viz::ResourceFormat format = viz::RGBA_8888;
viz::ResourceId id1 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t data1[4] = {1, 2, 3, 4};
child_resource_provider_->CopyToResource(id1, data1, size);
child_resource_provider_->EnableReadLockFencesForTesting(id1);
@@ -1292,15 +1269,13 @@ TEST_P(ResourceProviderTest, ReadLockFenceDestroyChild) {
viz::ResourceFormat format = viz::RGBA_8888;
viz::ResourceId id1 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t data[4] = {1, 2, 3, 4};
child_resource_provider_->CopyToResource(id1, data, size);
child_resource_provider_->EnableReadLockFencesForTesting(id1);
viz::ResourceId id2 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
child_resource_provider_->CopyToResource(id2, data, size);
std::vector<viz::ReturnedResource> returned_to_child;
@@ -1357,15 +1332,13 @@ TEST_P(ResourceProviderTest, ReadLockFenceContextLost) {
viz::ResourceFormat format = viz::RGBA_8888;
viz::ResourceId id1 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t data[4] = {1, 2, 3, 4};
child_resource_provider_->CopyToResource(id1, data, size);
child_resource_provider_->EnableReadLockFencesForTesting(id1);
viz::ResourceId id2 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
child_resource_provider_->CopyToResource(id2, data, size);
std::vector<viz::ReturnedResource> returned_to_child;
@@ -1418,14 +1391,12 @@ TEST_P(ResourceProviderTest, TransferSoftwareResources) {
ASSERT_EQ(4U, pixel_size);
viz::ResourceId id1 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t data1[4] = { 1, 2, 3, 4 };
child_resource_provider_->CopyToResource(id1, data1, size);
viz::ResourceId id2 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t data2[4] = { 5, 5, 5, 5 };
child_resource_provider_->CopyToResource(id2, data2, size);
@@ -1435,7 +1406,7 @@ TEST_P(ResourceProviderTest, TransferSoftwareResources) {
viz::ResourceId id3 =
child_resource_provider_->CreateResourceFromTextureMailbox(
viz::TextureMailbox(shared_bitmap_ptr, gfx::Size(1, 1)),
- SingleReleaseCallbackImpl::Create(base::Bind(
+ viz::SingleReleaseCallback::Create(base::Bind(
&SharedBitmapReleaseCallback, base::Passed(&shared_bitmap))));
std::vector<viz::ReturnedResource> returned_to_child;
@@ -1614,12 +1585,10 @@ TEST_P(ResourceProviderTest, TransferGLToSoftware) {
ResourceProviderContext::Create(shared_data_.get()));
child_context_provider->BindToCurrentThread();
- std::unique_ptr<LayerTreeResourceProvider> child_resource_provider(
- std::make_unique<LayerTreeResourceProvider>(
- child_context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto child_resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ child_context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
gfx::Size size(1, 1);
viz::ResourceFormat format = viz::RGBA_8888;
@@ -1627,8 +1596,7 @@ TEST_P(ResourceProviderTest, TransferGLToSoftware) {
ASSERT_EQ(4U, pixel_size);
viz::ResourceId id1 = child_resource_provider->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t data1[4] = { 1, 2, 3, 4 };
child_resource_provider->CopyToResource(id1, data1, size);
@@ -1675,8 +1643,7 @@ TEST_P(ResourceProviderTest, TransferInvalidSoftware) {
ASSERT_EQ(4U, pixel_size);
viz::ResourceId id1 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t data1[4] = { 1, 2, 3, 4 };
child_resource_provider_->CopyToResource(id1, data1, size);
@@ -1724,14 +1691,12 @@ TEST_P(ResourceProviderTest, DeleteExportedResources) {
ASSERT_EQ(4U, pixel_size);
viz::ResourceId id1 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t data1[4] = { 1, 2, 3, 4 };
child_resource_provider_->CopyToResource(id1, data1, size);
viz::ResourceId id2 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t data2[4] = {5, 5, 5, 5};
child_resource_provider_->CopyToResource(id2, data2, size);
@@ -1783,14 +1748,12 @@ TEST_P(ResourceProviderTest, DestroyChildWithExportedResources) {
ASSERT_EQ(4U, pixel_size);
viz::ResourceId id1 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t data1[4] = {1, 2, 3, 4};
child_resource_provider_->CopyToResource(id1, data1, size);
viz::ResourceId id2 = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t data2[4] = {5, 5, 5, 5};
child_resource_provider_->CopyToResource(id2, data2, size);
@@ -1836,8 +1799,7 @@ TEST_P(ResourceProviderTest, DeleteTransferredResources) {
ASSERT_EQ(4U, pixel_size);
viz::ResourceId id = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
uint8_t data[4] = { 1, 2, 3, 4 };
child_resource_provider_->CopyToResource(id, data, size);
@@ -1885,8 +1847,7 @@ TEST_P(ResourceProviderTest, DeleteTransferredResources) {
class ResourceProviderTestTextureFilters : public ResourceProviderTest {
public:
static void RunTest(GLenum child_filter, GLenum parent_filter) {
- std::unique_ptr<TextureStateTrackingContext> child_context_owned(
- new TextureStateTrackingContext);
+ auto child_context_owned(std::make_unique<TextureStateTrackingContext>());
TextureStateTrackingContext* child_context = child_context_owned.get();
auto child_context_provider =
@@ -1895,25 +1856,20 @@ class ResourceProviderTestTextureFilters : public ResourceProviderTest {
auto shared_bitmap_manager = std::make_unique<TestSharedBitmapManager>();
viz::ResourceSettings resource_settings = CreateResourceSettings();
- std::unique_ptr<LayerTreeResourceProvider> child_resource_provider(
- std::make_unique<LayerTreeResourceProvider>(
- child_context_provider.get(), shared_bitmap_manager.get(), nullptr,
- nullptr, kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- resource_settings));
-
- std::unique_ptr<TextureStateTrackingContext> parent_context_owned(
- new TextureStateTrackingContext);
+ auto child_resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ child_context_provider.get(), shared_bitmap_manager.get(), nullptr,
+ kDelegatedSyncPointsRequired, resource_settings));
+
+ auto parent_context_owned(std::make_unique<TextureStateTrackingContext>());
TextureStateTrackingContext* parent_context = parent_context_owned.get();
auto parent_context_provider =
TestContextProvider::Create(std::move(parent_context_owned));
parent_context_provider->BindToCurrentThread();
- std::unique_ptr<DisplayResourceProvider> parent_resource_provider(
- std::make_unique<DisplayResourceProvider>(
- parent_context_provider.get(), shared_bitmap_manager.get(), nullptr,
- nullptr, kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- resource_settings));
+ auto parent_resource_provider(std::make_unique<DisplayResourceProvider>(
+ parent_context_provider.get(), shared_bitmap_manager.get(), nullptr,
+ resource_settings));
gfx::Size size(1, 1);
viz::ResourceFormat format = viz::RGBA_8888;
@@ -1924,7 +1880,7 @@ class ResourceProviderTestTextureFilters : public ResourceProviderTest {
ASSERT_EQ(4U, pixel_size);
viz::ResourceId id = child_resource_provider->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format,
gfx::ColorSpace());
// The new texture is created with GL_LINEAR.
@@ -2053,14 +2009,12 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) {
gpu::SyncToken release_sync_token;
bool lost_resource = false;
- BlockingTaskRunner* main_thread_task_runner = nullptr;
- ReleaseCallbackImpl callback =
- base::Bind(ReleaseCallback, &release_sync_token, &lost_resource,
- &main_thread_task_runner);
+ viz::ReleaseCallback callback =
+ base::Bind(ReleaseCallback, &release_sync_token, &lost_resource);
viz::ResourceId resource =
child_resource_provider_->CreateResourceFromTextureMailbox(
viz::TextureMailbox(mailbox, sync_token, GL_TEXTURE_2D),
- SingleReleaseCallbackImpl::Create(callback));
+ viz::SingleReleaseCallback::Create(callback));
EXPECT_EQ(1u, context()->NumTextures());
EXPECT_FALSE(release_sync_token.HasData());
{
@@ -2105,7 +2059,6 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) {
EXPECT_LE(list[0].mailbox_holder.sync_token.release_count(),
release_sync_token.release_count());
EXPECT_FALSE(lost_resource);
- EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner);
}
// We're going to do the same thing as above, but testing the case where we
@@ -2115,7 +2068,7 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) {
release_sync_token.Clear();
resource = child_resource_provider_->CreateResourceFromTextureMailbox(
viz::TextureMailbox(mailbox, sync_token, GL_TEXTURE_2D),
- SingleReleaseCallbackImpl::Create(callback));
+ viz::SingleReleaseCallback::Create(callback));
EXPECT_EQ(1u, context()->NumTextures());
EXPECT_FALSE(release_sync_token.HasData());
{
@@ -2161,7 +2114,6 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) {
EXPECT_LE(list[0].mailbox_holder.sync_token.release_count(),
release_sync_token.release_count());
EXPECT_FALSE(lost_resource);
- EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner);
}
context()->waitSyncToken(release_sync_token.GetConstData());
@@ -2174,8 +2126,7 @@ TEST_P(ResourceProviderTest, LostResourceInParent) {
gfx::Size size(1, 1);
viz::ResourceFormat format = viz::RGBA_8888;
viz::ResourceId resource = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
child_resource_provider_->AllocateForTesting(resource);
// Expect a GL resource to be lost.
bool should_lose_resource =
@@ -2340,25 +2291,21 @@ TEST_P(ResourceProviderTest, LostContext) {
gpu::SyncToken release_sync_token;
bool lost_resource = false;
- BlockingTaskRunner* main_thread_task_runner = nullptr;
- std::unique_ptr<SingleReleaseCallbackImpl> callback =
- SingleReleaseCallbackImpl::Create(
- base::Bind(&ReleaseCallback, &release_sync_token, &lost_resource,
- &main_thread_task_runner));
- resource_provider_->CreateResourceFromTextureMailbox(
+ std::unique_ptr<viz::SingleReleaseCallback> callback =
+ viz::SingleReleaseCallback::Create(
+ base::Bind(&ReleaseCallback, &release_sync_token, &lost_resource));
+ child_resource_provider_->CreateResourceFromTextureMailbox(
viz::TextureMailbox(mailbox, sync_token, GL_TEXTURE_2D),
std::move(callback));
EXPECT_FALSE(release_sync_token.HasData());
EXPECT_FALSE(lost_resource);
- EXPECT_FALSE(main_thread_task_runner);
- resource_provider_->DidLoseVulkanContextProvider();
- resource_provider_ = nullptr;
+ child_resource_provider_->DidLoseVulkanContextProvider();
+ child_resource_provider_ = nullptr;
EXPECT_LE(sync_token.release_count(), release_sync_token.release_count());
EXPECT_TRUE(lost_resource);
- EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner);
}
TEST_P(ResourceProviderTest, ScopedSampler) {
@@ -2366,26 +2313,21 @@ TEST_P(ResourceProviderTest, ScopedSampler) {
if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
return;
- std::unique_ptr<TextureStateTrackingContext> context_owned(
- new TextureStateTrackingContext);
+ auto context_owned(std::make_unique<TextureStateTrackingContext>());
TextureStateTrackingContext* context = context_owned.get();
auto context_provider = TestContextProvider::Create(std::move(context_owned));
context_provider->BindToCurrentThread();
- std::unique_ptr<DisplayResourceProvider> resource_provider(
- std::make_unique<DisplayResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<DisplayResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), CreateResourceSettings()));
gfx::Size size(1, 1);
viz::ResourceFormat format = viz::RGBA_8888;
int texture_id = 1;
viz::ResourceId id = resource_provider->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
// Check that the texture gets created with the right sampler settings.
EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id))
@@ -2445,18 +2387,15 @@ TEST_P(ResourceProviderTest, ManagedResource) {
if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
return;
- std::unique_ptr<TextureStateTrackingContext> context_owned(
- new TextureStateTrackingContext);
+ auto context_owned(std::make_unique<TextureStateTrackingContext>());
TextureStateTrackingContext* context = context_owned.get();
auto context_provider = TestContextProvider::Create(std::move(context_owned));
context_provider->BindToCurrentThread();
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
gfx::Size size(1, 1);
viz::ResourceFormat format = viz::RGBA_8888;
@@ -2464,8 +2403,7 @@ TEST_P(ResourceProviderTest, ManagedResource) {
// Check that the texture gets created with the right sampler settings.
viz::ResourceId id = resource_provider->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
EXPECT_CALL(*context,
texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
@@ -2488,18 +2426,15 @@ TEST_P(ResourceProviderTest, TextureWrapMode) {
if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
return;
- std::unique_ptr<TextureStateTrackingContext> context_owned(
- new TextureStateTrackingContext);
+ auto context_owned(std::make_unique<TextureStateTrackingContext>());
TextureStateTrackingContext* context = context_owned.get();
auto context_provider = TestContextProvider::Create(std::move(context_owned));
context_provider->BindToCurrentThread();
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
gfx::Size size(1, 1);
viz::ResourceFormat format = viz::RGBA_8888;
@@ -2507,7 +2442,7 @@ TEST_P(ResourceProviderTest, TextureWrapMode) {
for (int texture_id = 1; texture_id <= 2; ++texture_id) {
// Check that the texture gets created with the right sampler settings.
viz::ResourceId id = resource_provider->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format,
gfx::ColorSpace());
EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
EXPECT_CALL(*context,
@@ -2530,29 +2465,24 @@ TEST_P(ResourceProviderTest, TextureHint) {
if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
return;
- std::unique_ptr<TextureStateTrackingContext> context_owned(
- new TextureStateTrackingContext);
+ auto context_owned(std::make_unique<TextureStateTrackingContext>());
TextureStateTrackingContext* context = context_owned.get();
context->set_support_texture_storage(true);
context->set_support_texture_usage(true);
auto context_provider = TestContextProvider::Create(std::move(context_owned));
context_provider->BindToCurrentThread();
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
gfx::Size size(1, 1);
viz::ResourceFormat format = viz::RGBA_8888;
- const ResourceProvider::TextureHint hints[4] = {
+ const ResourceProvider::TextureHint hints[] = {
ResourceProvider::TEXTURE_HINT_DEFAULT,
- ResourceProvider::TEXTURE_HINT_IMMUTABLE,
ResourceProvider::TEXTURE_HINT_FRAMEBUFFER,
- ResourceProvider::TEXTURE_HINT_IMMUTABLE_FRAMEBUFFER,
};
for (GLuint texture_id = 1; texture_id <= arraysize(hints); ++texture_id) {
// Check that the texture gets created with the right sampler settings.
@@ -2569,7 +2499,8 @@ TEST_P(ResourceProviderTest, TextureHint) {
EXPECT_CALL(
*context,
texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
- // Check only TEXTURE_HINT_FRAMEBUFFER set GL_TEXTURE_USAGE_ANGLE.
+ // Check that GL_TEXTURE_USAGE_ANGLE is set iff the TEXTURE_HINT_FRAMEBUFFER
+ // hint is used.
bool is_framebuffer_hint =
hints[texture_id - 1] & ResourceProvider::TEXTURE_HINT_FRAMEBUFFER;
EXPECT_CALL(*context,
@@ -2593,39 +2524,63 @@ TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) {
std::unique_ptr<viz::SharedBitmap> shared_bitmap(
CreateAndFillSharedBitmap(shared_bitmap_manager_.get(), size, kBadBeef));
- std::unique_ptr<DisplayResourceProvider> resource_provider(
- std::make_unique<DisplayResourceProvider>(
- nullptr, shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), main_thread_task_runner_.get(),
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<DisplayResourceProvider>(
+ nullptr, shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(),
+ CreateResourceSettings()));
+
+ auto child_resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ nullptr, shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(),
+ kDelegatedSyncPointsRequired, CreateResourceSettings()));
gpu::SyncToken release_sync_token;
bool lost_resource = false;
- BlockingTaskRunner* main_thread_task_runner = nullptr;
- std::unique_ptr<SingleReleaseCallbackImpl> callback =
- SingleReleaseCallbackImpl::Create(
- base::Bind(&ReleaseCallback, &release_sync_token, &lost_resource,
- &main_thread_task_runner));
+ std::unique_ptr<viz::SingleReleaseCallback> callback =
+ viz::SingleReleaseCallback::Create(
+ base::Bind(&ReleaseCallback, &release_sync_token, &lost_resource));
viz::TextureMailbox mailbox(shared_bitmap.get(), size);
- viz::ResourceId id = resource_provider->CreateResourceFromTextureMailbox(
- mailbox, std::move(callback));
- EXPECT_NE(0u, id);
+ viz::ResourceId resource_id =
+ child_resource_provider->CreateResourceFromTextureMailbox(
+ mailbox, std::move(callback));
+ EXPECT_NE(0u, resource_id);
+
+ // Transfer resources to the parent.
+ ResourceProvider::ResourceIdArray resource_ids_to_transfer;
+ resource_ids_to_transfer.push_back(resource_id);
+
+ std::vector<viz::TransferableResource> send_to_parent;
+ std::vector<viz::ReturnedResource> returned_to_child;
+ int child_id = resource_provider->CreateChild(
+ base::Bind(&CollectResources, &returned_to_child));
+ child_resource_provider->PrepareSendToParent(resource_ids_to_transfer,
+ &send_to_parent);
+ resource_provider->ReceiveFromChild(child_id, send_to_parent);
+
+ // In DisplayResourceProvider's namespace, use the mapped resource id.
+ ResourceProvider::ResourceIdMap resource_map =
+ resource_provider->GetChildToParentMap(child_id);
+ viz::ResourceId mapped_resource_id = resource_map[resource_id];
{
DisplayResourceProvider::ScopedReadLockSoftware lock(
- resource_provider.get(), id);
+ resource_provider.get(), mapped_resource_id);
const SkBitmap* sk_bitmap = lock.sk_bitmap();
EXPECT_EQ(sk_bitmap->width(), size.width());
EXPECT_EQ(sk_bitmap->height(), size.height());
EXPECT_EQ(*sk_bitmap->getAddr32(16, 16), kBadBeef);
}
- resource_provider->DeleteResource(id);
+ EXPECT_EQ(0u, returned_to_child.size());
+ // Transfer resources back from the parent to the child. Set no resources as
+ // being in use.
+ resource_provider->DeclareUsedResourcesFromChild(child_id,
+ viz::ResourceIdSet());
+ EXPECT_EQ(1u, returned_to_child.size());
+ child_resource_provider->ReceiveReturnsFromParent(returned_to_child);
+
+ child_resource_provider->DeleteResource(resource_id);
EXPECT_FALSE(release_sync_token.HasData());
EXPECT_FALSE(lost_resource);
- EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner);
}
class ResourceProviderTestTextureMailboxGLFilters
@@ -2634,59 +2589,85 @@ class ResourceProviderTestTextureMailboxGLFilters
static void RunTest(
TestSharedBitmapManager* shared_bitmap_manager,
viz::TestGpuMemoryBufferManager* gpu_memory_buffer_manager,
- BlockingTaskRunner* main_thread_task_runner,
bool mailbox_nearest_neighbor,
GLenum sampler_filter) {
- std::unique_ptr<TextureStateTrackingContext> context_owned(
- new TextureStateTrackingContext);
+ auto context_owned(std::make_unique<TextureStateTrackingContext>());
TextureStateTrackingContext* context = context_owned.get();
auto context_provider =
TestContextProvider::Create(std::move(context_owned));
context_provider->BindToCurrentThread();
- std::unique_ptr<DisplayResourceProvider> resource_provider(
- std::make_unique<DisplayResourceProvider>(
- context_provider.get(), shared_bitmap_manager,
- gpu_memory_buffer_manager, main_thread_task_runner,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<DisplayResourceProvider>(
+ context_provider.get(), shared_bitmap_manager,
+ gpu_memory_buffer_manager, CreateResourceSettings()));
+
+ auto child_context_owned(std::make_unique<TextureStateTrackingContext>());
+ TextureStateTrackingContext* child_context = child_context_owned.get();
+ auto child_context_provider =
+ TestContextProvider::Create(std::move(child_context_owned));
+ child_context_provider->BindToCurrentThread();
+
+ auto child_resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ child_context_provider.get(), shared_bitmap_manager,
+ gpu_memory_buffer_manager, kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
unsigned texture_id = 1;
gpu::SyncToken sync_token(gpu::CommandBufferNamespace::GPU_IO, 0,
gpu::CommandBufferId::FromUnsafeValue(0x12),
0x34);
unsigned target = GL_TEXTURE_2D;
- const GLuint64 current_fence_sync = context->GetNextFenceSync();
+ const GLuint64 current_fence_sync = child_context->GetNextFenceSync();
- EXPECT_CALL(*context, bindTexture(_, _)).Times(0);
- EXPECT_CALL(*context, waitSyncToken(_)).Times(0);
- EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0);
- EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0);
+ EXPECT_CALL(*child_context, bindTexture(_, _)).Times(0);
+ EXPECT_CALL(*child_context, waitSyncToken(_)).Times(0);
+ EXPECT_CALL(*child_context, produceTextureDirectCHROMIUM(_, _, _)).Times(0);
+ EXPECT_CALL(*child_context, createAndConsumeTextureCHROMIUM(_, _)).Times(0);
gpu::Mailbox gpu_mailbox;
memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1);
gpu::SyncToken release_sync_token;
bool lost_resource = false;
- BlockingTaskRunner* mailbox_task_runner = nullptr;
- std::unique_ptr<SingleReleaseCallbackImpl> callback =
- SingleReleaseCallbackImpl::Create(
- base::Bind(&ReleaseCallback, &release_sync_token, &lost_resource,
- &mailbox_task_runner));
+ std::unique_ptr<viz::SingleReleaseCallback> callback =
+ viz::SingleReleaseCallback::Create(
+ base::Bind(&ReleaseCallback, &release_sync_token, &lost_resource));
viz::TextureMailbox mailbox(gpu_mailbox, sync_token, target);
mailbox.set_nearest_neighbor(mailbox_nearest_neighbor);
- viz::ResourceId id = resource_provider->CreateResourceFromTextureMailbox(
- mailbox, std::move(callback));
- EXPECT_NE(0u, id);
- EXPECT_EQ(current_fence_sync, context->GetNextFenceSync());
+ viz::ResourceId resource_id =
+ child_resource_provider->CreateResourceFromTextureMailbox(
+ mailbox, std::move(callback));
+ EXPECT_NE(0u, resource_id);
+ EXPECT_EQ(current_fence_sync, child_context->GetNextFenceSync());
- Mock::VerifyAndClearExpectations(context);
+ Mock::VerifyAndClearExpectations(child_context);
+ // Transfer resources to the parent.
+ ResourceProvider::ResourceIdArray resource_ids_to_transfer;
+ resource_ids_to_transfer.push_back(resource_id);
+
+ std::vector<viz::TransferableResource> send_to_parent;
+ std::vector<viz::ReturnedResource> returned_to_child;
+ int child_id = resource_provider->CreateChild(
+ base::Bind(&CollectResources, &returned_to_child));
+ child_resource_provider->PrepareSendToParent(resource_ids_to_transfer,
+ &send_to_parent);
+ resource_provider->ReceiveFromChild(child_id, send_to_parent);
+
+ // In DisplayResourceProvider's namespace, use the mapped resource id.
+ ResourceProvider::ResourceIdMap resource_map =
+ resource_provider->GetChildToParentMap(child_id);
+ viz::ResourceId mapped_resource_id = resource_map[resource_id];
{
+ // The verified flush flag will be set by
+ // LayerTreeResourceProvider::PrepareSendToParent. Before checking if
+ // the gpu::SyncToken matches, set this flag first.
+ sync_token.SetVerifyFlush();
+
// Mailbox sync point WaitSyncToken before using the texture.
EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token)));
- resource_provider->WaitSyncToken(id);
+ resource_provider->WaitSyncToken(mapped_resource_id);
Mock::VerifyAndClearExpectations(context);
EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(target, _))
@@ -2704,24 +2685,33 @@ class ResourceProviderTestTextureMailboxGLFilters
GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, sampler_filter));
}
- DisplayResourceProvider::ScopedSamplerGL lock(resource_provider.get(), id,
- sampler_filter);
+ DisplayResourceProvider::ScopedSamplerGL lock(
+ resource_provider.get(), mapped_resource_id, sampler_filter);
Mock::VerifyAndClearExpectations(context);
EXPECT_EQ(current_fence_sync, context->GetNextFenceSync());
// When done with it, a sync point should be inserted, but no produce is
// necessary.
- EXPECT_CALL(*context, bindTexture(_, _)).Times(0);
- EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0);
+ EXPECT_CALL(*child_context, bindTexture(_, _)).Times(0);
+ EXPECT_CALL(*child_context, produceTextureDirectCHROMIUM(_, _, _))
+ .Times(0);
- EXPECT_CALL(*context, waitSyncToken(_)).Times(0);
- EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0);
+ EXPECT_CALL(*child_context, waitSyncToken(_)).Times(0);
+ EXPECT_CALL(*child_context, createAndConsumeTextureCHROMIUM(_, _))
+ .Times(0);
}
- resource_provider->DeleteResource(id);
+ EXPECT_EQ(0u, returned_to_child.size());
+ // Transfer resources back from the parent to the child. Set no resources as
+ // being in use.
+ resource_provider->DeclareUsedResourcesFromChild(child_id,
+ viz::ResourceIdSet());
+ EXPECT_EQ(1u, returned_to_child.size());
+ child_resource_provider->ReceiveReturnsFromParent(returned_to_child);
+
+ child_resource_provider->DeleteResource(resource_id);
EXPECT_TRUE(release_sync_token.HasData());
EXPECT_FALSE(lost_resource);
- EXPECT_EQ(main_thread_task_runner, mailbox_task_runner);
}
};
@@ -2733,7 +2723,6 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_LinearToLinear) {
ResourceProviderTestTextureMailboxGLFilters::RunTest(
shared_bitmap_manager_.get(),
gpu_memory_buffer_manager_.get(),
- main_thread_task_runner_.get(),
false,
GL_LINEAR);
}
@@ -2746,7 +2735,6 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_NearestToNearest) {
ResourceProviderTestTextureMailboxGLFilters::RunTest(
shared_bitmap_manager_.get(),
gpu_memory_buffer_manager_.get(),
- main_thread_task_runner_.get(),
true,
GL_NEAREST);
}
@@ -2759,7 +2747,6 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_NearestToLinear) {
ResourceProviderTestTextureMailboxGLFilters::RunTest(
shared_bitmap_manager_.get(),
gpu_memory_buffer_manager_.get(),
- main_thread_task_runner_.get(),
true,
GL_LINEAR);
}
@@ -2772,7 +2759,6 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_LinearToNearest) {
ResourceProviderTestTextureMailboxGLFilters::RunTest(
shared_bitmap_manager_.get(),
gpu_memory_buffer_manager_.get(),
- main_thread_task_runner_.get(),
false,
GL_NEAREST);
}
@@ -2782,47 +2768,77 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) {
if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
return;
- std::unique_ptr<TextureStateTrackingContext> context_owned(
- new TextureStateTrackingContext);
+ auto context_owned(std::make_unique<TextureStateTrackingContext>());
TextureStateTrackingContext* context = context_owned.get();
auto context_provider = TestContextProvider::Create(std::move(context_owned));
context_provider->BindToCurrentThread();
- std::unique_ptr<DisplayResourceProvider> resource_provider(
- std::make_unique<DisplayResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<DisplayResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), CreateResourceSettings()));
+
+ auto child_context_owned(std::make_unique<TextureStateTrackingContext>());
+ TextureStateTrackingContext* child_context = child_context_owned.get();
+ auto child_context_provider =
+ TestContextProvider::Create(std::move(child_context_owned));
+ child_context_provider->BindToCurrentThread();
+
+ auto child_resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ child_context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
gpu::SyncToken sync_token(gpu::CommandBufferNamespace::GPU_IO, 0,
gpu::CommandBufferId::FromUnsafeValue(0x12), 0x34);
- const GLuint64 current_fence_sync = context->GetNextFenceSync();
+ const GLuint64 current_fence_sync = child_context->GetNextFenceSync();
unsigned target = GL_TEXTURE_EXTERNAL_OES;
- EXPECT_CALL(*context, bindTexture(_, _)).Times(0);
- EXPECT_CALL(*context, waitSyncToken(_)).Times(0);
- EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0);
- EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0);
+ EXPECT_CALL(*child_context, bindTexture(_, _)).Times(0);
+ EXPECT_CALL(*child_context, waitSyncToken(_)).Times(0);
+ EXPECT_CALL(*child_context, produceTextureDirectCHROMIUM(_, _, _)).Times(0);
+ EXPECT_CALL(*child_context, createAndConsumeTextureCHROMIUM(_, _)).Times(0);
gpu::Mailbox gpu_mailbox;
memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1);
- std::unique_ptr<SingleReleaseCallbackImpl> callback =
- SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback));
+ std::unique_ptr<viz::SingleReleaseCallback> callback =
+ viz::SingleReleaseCallback::Create(base::Bind(&EmptyReleaseCallback));
viz::TextureMailbox mailbox(gpu_mailbox, sync_token, target);
- viz::ResourceId id = resource_provider->CreateResourceFromTextureMailbox(
- mailbox, std::move(callback));
- EXPECT_NE(0u, id);
- EXPECT_EQ(current_fence_sync, context->GetNextFenceSync());
+ viz::ResourceId resource_id =
+ child_resource_provider->CreateResourceFromTextureMailbox(
+ mailbox, std::move(callback));
+ EXPECT_NE(0u, resource_id);
+ EXPECT_EQ(current_fence_sync, child_context->GetNextFenceSync());
- Mock::VerifyAndClearExpectations(context);
+ Mock::VerifyAndClearExpectations(child_context);
+
+ // Transfer resources to the parent.
+ ResourceProvider::ResourceIdArray resource_ids_to_transfer;
+ resource_ids_to_transfer.push_back(resource_id);
+ std::vector<viz::TransferableResource> send_to_parent;
+ std::vector<viz::ReturnedResource> returned_to_child;
+ int child_id = resource_provider->CreateChild(
+ base::Bind(&CollectResources, &returned_to_child));
+ child_resource_provider->PrepareSendToParent(resource_ids_to_transfer,
+ &send_to_parent);
+ resource_provider->ReceiveFromChild(child_id, send_to_parent);
+
+ // Before create DrawQuad in DisplayResourceProvider's namespace, get the
+ // mapped resource id first.
+ ResourceProvider::ResourceIdMap resource_map =
+ resource_provider->GetChildToParentMap(child_id);
+ viz::ResourceId mapped_resource_id = resource_map[resource_id];
{
+ // The verified flush flag will be set by
+ // LayerTreeResourceProvider::PrepareSendToParent. Before checking if
+ // the gpu::SyncToken matches, set this flag first.
+ sync_token.SetVerifyFlush();
+
// Mailbox sync point WaitSyncToken before using the texture.
EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token)));
- resource_provider->WaitSyncToken(id);
+ resource_provider->WaitSyncToken(mapped_resource_id);
Mock::VerifyAndClearExpectations(context);
unsigned texture_id = 1;
@@ -2832,7 +2848,8 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) {
EXPECT_CALL(*context, produceTextureDirectCHROMIUM(_, _, _)).Times(0);
- DisplayResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id);
+ DisplayResourceProvider::ScopedReadLockGL lock(resource_provider.get(),
+ mapped_resource_id);
Mock::VerifyAndClearExpectations(context);
// When done with it, a sync point should be inserted, but no produce is
@@ -2842,7 +2859,17 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) {
EXPECT_CALL(*context, waitSyncToken(_)).Times(0);
EXPECT_CALL(*context, createAndConsumeTextureCHROMIUM(_, _)).Times(0);
+ Mock::VerifyAndClearExpectations(context);
}
+ EXPECT_EQ(0u, returned_to_child.size());
+ // Transfer resources back from the parent to the child. Set no resources as
+ // being in use.
+ resource_provider->DeclareUsedResourcesFromChild(child_id,
+ viz::ResourceIdSet());
+ EXPECT_EQ(1u, returned_to_child.size());
+ child_resource_provider->ReceiveReturnsFromParent(returned_to_child);
+
+ child_resource_provider->DeleteResource(resource_id);
}
TEST_P(ResourceProviderTest,
@@ -2851,18 +2878,15 @@ TEST_P(ResourceProviderTest,
if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
return;
- std::unique_ptr<TextureStateTrackingContext> context_owned(
- new TextureStateTrackingContext);
+ auto context_owned(std::make_unique<TextureStateTrackingContext>());
TextureStateTrackingContext* context = context_owned.get();
auto context_provider = TestContextProvider::Create(std::move(context_owned));
context_provider->BindToCurrentThread();
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
gpu::SyncToken sync_token(gpu::CommandBufferNamespace::GPU_IO, 0,
gpu::CommandBufferId::FromUnsafeValue(0x12), 0x34);
@@ -2876,8 +2900,8 @@ TEST_P(ResourceProviderTest,
gpu::Mailbox gpu_mailbox;
memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1);
- std::unique_ptr<SingleReleaseCallbackImpl> callback =
- SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback));
+ std::unique_ptr<viz::SingleReleaseCallback> callback =
+ viz::SingleReleaseCallback::Create(base::Bind(&EmptyReleaseCallback));
viz::TextureMailbox mailbox(gpu_mailbox, sync_token, target);
@@ -2906,18 +2930,15 @@ TEST_P(ResourceProviderTest, TextureMailbox_WaitSyncTokenIfNeeded_NoSyncToken) {
if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
return;
- std::unique_ptr<TextureStateTrackingContext> context_owned(
- new TextureStateTrackingContext);
+ auto context_owned(std::make_unique<TextureStateTrackingContext>());
TextureStateTrackingContext* context = context_owned.get();
auto context_provider = TestContextProvider::Create(std::move(context_owned));
context_provider->BindToCurrentThread();
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
gpu::SyncToken sync_token;
const GLuint64 current_fence_sync = context->GetNextFenceSync();
@@ -2930,8 +2951,8 @@ TEST_P(ResourceProviderTest, TextureMailbox_WaitSyncTokenIfNeeded_NoSyncToken) {
gpu::Mailbox gpu_mailbox;
memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1);
- std::unique_ptr<SingleReleaseCallbackImpl> callback =
- SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback));
+ std::unique_ptr<viz::SingleReleaseCallback> callback =
+ viz::SingleReleaseCallback::Create(base::Bind(&EmptyReleaseCallback));
viz::TextureMailbox mailbox(gpu_mailbox, sync_token, target);
@@ -2955,18 +2976,15 @@ TEST_P(ResourceProviderTest, TextureMailbox_PrepareSendToParent_NoSyncToken) {
if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
return;
- std::unique_ptr<TextureStateTrackingContext> context_owned(
- new TextureStateTrackingContext);
+ auto context_owned(std::make_unique<TextureStateTrackingContext>());
TextureStateTrackingContext* context = context_owned.get();
auto context_provider = TestContextProvider::Create(std::move(context_owned));
context_provider->BindToCurrentThread();
- std::unique_ptr<LayerTreeResourceProvider> resource_provider(
- std::make_unique<LayerTreeResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
EXPECT_CALL(*context, bindTexture(_, _)).Times(0);
EXPECT_CALL(*context, waitSyncToken(_)).Times(0);
@@ -2976,8 +2994,8 @@ TEST_P(ResourceProviderTest, TextureMailbox_PrepareSendToParent_NoSyncToken) {
viz::TextureMailbox mailbox(gpu::Mailbox::Generate(), gpu::SyncToken(),
GL_TEXTURE_2D);
- std::unique_ptr<SingleReleaseCallbackImpl> callback =
- SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback));
+ std::unique_ptr<viz::SingleReleaseCallback> callback =
+ viz::SingleReleaseCallback::Create(base::Bind(&EmptyReleaseCallback));
viz::ResourceId id = resource_provider->CreateResourceFromTextureMailbox(
mailbox, std::move(callback));
@@ -3066,21 +3084,19 @@ class AllocationTrackingContext3D : public TextureStateTrackingContext {
};
TEST_P(ResourceProviderTest, TextureAllocation) {
- // Only for GL textures.
if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
return;
+
std::unique_ptr<AllocationTrackingContext3D> context_owned(
new StrictMock<AllocationTrackingContext3D>);
AllocationTrackingContext3D* context = context_owned.get();
auto context_provider = TestContextProvider::Create(std::move(context_owned));
context_provider->BindToCurrentThread();
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
gfx::Size size(2, 2);
gfx::Vector2d offset(0, 0);
@@ -3091,8 +3107,7 @@ TEST_P(ResourceProviderTest, TextureAllocation) {
// Lazy allocation. Don't allocate when creating the resource.
id = resource_provider->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1);
@@ -3105,8 +3120,7 @@ TEST_P(ResourceProviderTest, TextureAllocation) {
// Do allocate when we set the pixels.
id = resource_provider->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
- gfx::ColorSpace());
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, gfx::ColorSpace());
EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3);
@@ -3120,34 +3134,16 @@ TEST_P(ResourceProviderTest, TextureAllocation) {
Mock::VerifyAndClearExpectations(context);
}
-TEST_P(ResourceProviderTest, TextureAllocationHint) {
- // Only for GL textures.
- if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
- return;
- std::unique_ptr<AllocationTrackingContext3D> context_owned(
- new StrictMock<AllocationTrackingContext3D>);
- AllocationTrackingContext3D* context = context_owned.get();
- context->set_support_texture_storage(true);
- context->set_support_texture_usage(true);
- auto context_provider = TestContextProvider::Create(std::move(context_owned));
- context_provider->BindToCurrentThread();
-
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
-
+static void TestTextureAllocationHint(
+ AllocationTrackingContext3D* context,
+ LayerTreeResourceProvider* resource_provider) {
gfx::Size size(2, 2);
const viz::ResourceFormat formats[3] = {viz::RGBA_8888, viz::BGRA_8888,
viz::RGBA_F16};
- const ResourceProvider::TextureHint hints[4] = {
+ const ResourceProvider::TextureHint hints[2] = {
ResourceProvider::TEXTURE_HINT_DEFAULT,
- ResourceProvider::TEXTURE_HINT_IMMUTABLE,
ResourceProvider::TEXTURE_HINT_FRAMEBUFFER,
- ResourceProvider::TEXTURE_HINT_IMMUTABLE_FRAMEBUFFER,
};
for (size_t i = 0; i < arraysize(formats); ++i) {
for (GLuint texture_id = 1; texture_id <= arraysize(hints); ++texture_id) {
@@ -3157,10 +3153,11 @@ TEST_P(ResourceProviderTest, TextureAllocationHint) {
EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
- bool is_immutable_hint =
- hints[texture_id - 1] & ResourceProvider::TEXTURE_HINT_IMMUTABLE;
+ // Resources are immutable when possible, so texStorage2DEXT should happen
+ // instead of texImage2D when the context support or format allows.
bool support_immutable_texture =
- is_immutable_hint && formats[i] != viz::BGRA_8888;
+ context->test_capabilities().texture_format_bgra8888 ||
+ formats[i] != viz::BGRA_8888;
EXPECT_CALL(*context, texStorage2DEXT(_, _, _, 2, 2))
.Times(support_immutable_texture ? 1 : 0);
EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _))
@@ -3175,63 +3172,59 @@ TEST_P(ResourceProviderTest, TextureAllocationHint) {
}
}
-TEST_P(ResourceProviderTest, TextureAllocationHint_BGRA) {
+TEST_P(ResourceProviderTest, TextureAllocationHint) {
// Only for GL textures.
if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
return;
- std::unique_ptr<AllocationTrackingContext3D> context_owned(
- new StrictMock<AllocationTrackingContext3D>);
- AllocationTrackingContext3D* context = context_owned.get();
- context->set_support_texture_format_bgra8888(true);
+
+ auto context = base::MakeUnique<StrictMock<AllocationTrackingContext3D>>();
+ auto* context_ptr = context.get();
+
+ // BGRA storage is not supported.
+ context->set_support_texture_format_bgra8888(false);
+
context->set_support_texture_storage(true);
context->set_support_texture_usage(true);
- auto context_provider = TestContextProvider::Create(std::move(context_owned));
+ auto context_provider = TestContextProvider::Create(std::move(context));
context_provider->BindToCurrentThread();
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
- gfx::Size size(2, 2);
- const viz::ResourceFormat formats[2] = {viz::RGBA_8888, viz::BGRA_8888};
+ TestTextureAllocationHint(context_ptr, resource_provider.get());
+}
- const ResourceProvider::TextureHint hints[4] = {
- ResourceProvider::TEXTURE_HINT_DEFAULT,
- ResourceProvider::TEXTURE_HINT_IMMUTABLE,
- ResourceProvider::TEXTURE_HINT_FRAMEBUFFER,
- ResourceProvider::TEXTURE_HINT_IMMUTABLE_FRAMEBUFFER,
- };
- for (size_t i = 0; i < arraysize(formats); ++i) {
- for (GLuint texture_id = 1; texture_id <= arraysize(hints); ++texture_id) {
- // Lazy allocation. Don't allocate when creating the resource.
- viz::ResourceId id = resource_provider->CreateResource(
- size, hints[texture_id - 1], formats[i], gfx::ColorSpace());
+TEST_P(ResourceProviderTest, TextureAllocationHint_BGRA) {
+ // Only for GL textures.
+ if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
+ return;
- EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
- EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
- bool is_immutable_hint =
- hints[texture_id - 1] & ResourceProvider::TEXTURE_HINT_IMMUTABLE;
- EXPECT_CALL(*context, texStorage2DEXT(_, _, _, 2, 2))
- .Times(is_immutable_hint ? 1 : 0);
- EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _))
- .Times(is_immutable_hint ? 0 : 1);
- resource_provider->AllocateForTesting(id);
+ auto context = base::MakeUnique<StrictMock<AllocationTrackingContext3D>>();
+ auto* context_ptr = context.get();
- EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
- resource_provider->DeleteResource(id);
+ // BGRA storage is supported.
+ context->set_support_texture_format_bgra8888(true);
- Mock::VerifyAndClearExpectations(context);
- }
- }
+ context->set_support_texture_storage(true);
+ context->set_support_texture_usage(true);
+ auto context_provider = TestContextProvider::Create(std::move(context));
+ context_provider->BindToCurrentThread();
+
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
+
+ TestTextureAllocationHint(context_ptr, resource_provider.get());
}
TEST_P(ResourceProviderTest, Image_GLTexture) {
// Only for GL textures.
if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE)
return;
+
std::unique_ptr<AllocationTrackingContext3D> context_owned(
new StrictMock<AllocationTrackingContext3D>);
AllocationTrackingContext3D* context = context_owned.get();
@@ -3244,15 +3237,13 @@ TEST_P(ResourceProviderTest, Image_GLTexture) {
const unsigned kTextureId = 123u;
const unsigned kImageId = 234u;
- std::unique_ptr<LayerTreeResourceProvider> resource_provider(
- std::make_unique<LayerTreeResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
viz::ResourceId id = resource_provider->CreateGpuMemoryBufferResource(
- gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_DEFAULT,
format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gfx::ColorSpace());
InSequence sequence;
@@ -3300,16 +3291,14 @@ TEST_P(ResourceProviderTest, CompressedTextureETC1Allocate) {
context_provider->BindToCurrentThread();
gfx::Size size(4, 4);
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
int texture_id = 123;
viz::ResourceId id = resource_provider->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, viz::ETC1,
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, viz::ETC1,
gfx::ColorSpace());
EXPECT_NE(0u, id);
EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
@@ -3332,17 +3321,15 @@ TEST_P(ResourceProviderTest, CompressedTextureETC1Upload) {
context_provider->BindToCurrentThread();
gfx::Size size(4, 4);
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
int texture_id = 123;
uint8_t pixels[8];
viz::ResourceId id = resource_provider->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, viz::ETC1,
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, viz::ETC1,
gfx::ColorSpace());
EXPECT_NE(0u, id);
EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
@@ -3376,8 +3363,7 @@ class TextureIdAllocationTrackingContext : public TestWebGraphicsContext3D {
};
TEST(ResourceProviderTest, TextureAllocationChunkSize) {
- std::unique_ptr<TextureIdAllocationTrackingContext> context_owned(
- new TextureIdAllocationTrackingContext);
+ auto context_owned(std::make_unique<TextureIdAllocationTrackingContext>());
TextureIdAllocationTrackingContext* context = context_owned.get();
auto context_provider = TestContextProvider::Create(std::move(context_owned));
context_provider->BindToCurrentThread();
@@ -3388,14 +3374,13 @@ TEST(ResourceProviderTest, TextureAllocationChunkSize) {
{
size_t kTextureAllocationChunkSize = 1;
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager.get(), nullptr,
- nullptr, kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings(kTextureAllocationChunkSize)));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager.get(), nullptr,
+ kDelegatedSyncPointsRequired,
+ CreateResourceSettings(kTextureAllocationChunkSize)));
viz::ResourceId id = resource_provider->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format,
gfx::ColorSpace());
resource_provider->AllocateForTesting(id);
Mock::VerifyAndClearExpectations(context);
@@ -3406,14 +3391,13 @@ TEST(ResourceProviderTest, TextureAllocationChunkSize) {
{
size_t kTextureAllocationChunkSize = 8;
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager.get(), nullptr,
- nullptr, kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings(kTextureAllocationChunkSize)));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager.get(), nullptr,
+ kDelegatedSyncPointsRequired,
+ CreateResourceSettings(kTextureAllocationChunkSize)));
viz::ResourceId id = resource_provider->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format,
gfx::ColorSpace());
resource_provider->AllocateForTesting(id);
Mock::VerifyAndClearExpectations(context);
@@ -3436,7 +3420,7 @@ TEST_P(ResourceProviderTest, GetSyncTokenForResources) {
ResourceProvider::ResourceIdArray array;
for (uint32_t i = 0; i < arraysize(release_counts); ++i) {
viz::ResourceId id = child_resource_provider_->CreateResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format,
gfx::ColorSpace());
array.push_back(id);
@@ -3467,15 +3451,13 @@ TEST_P(ResourceProviderTest, ScopedWriteLockGL) {
const viz::ResourceFormat format = viz::RGBA_8888;
const unsigned kTextureId = 123u;
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
viz::ResourceId id = resource_provider->CreateResource(
- gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_DEFAULT,
format, gfx::ColorSpace());
InSequence sequence;
@@ -3517,15 +3499,13 @@ TEST_P(ResourceProviderTest, ScopedWriteLockGL_GpuMemoryBuffer) {
const unsigned kTextureId = 123u;
const unsigned kImageId = 234u;
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
viz::ResourceId id = resource_provider->CreateGpuMemoryBufferResource(
- gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_DEFAULT,
format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gfx::ColorSpace());
InSequence sequence;
@@ -3570,15 +3550,13 @@ TEST_P(ResourceProviderTest, ScopedWriteLockGL_Mailbox) {
const unsigned kTextureId = 123u;
const unsigned kWorkerTextureId = 234u;
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
viz::ResourceId id = resource_provider->CreateResource(
- gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_DEFAULT,
format, gfx::ColorSpace());
InSequence sequence;
@@ -3655,15 +3633,13 @@ TEST_P(ResourceProviderTest, ScopedWriteLockGL_GpuMemoryBuffer_Mailbox) {
const unsigned kWorkerTextureId = 234u;
const unsigned kImageId = 345u;
- std::unique_ptr<ResourceProvider> resource_provider(
- std::make_unique<ResourceProvider>(
- context_provider.get(), shared_bitmap_manager_.get(),
- gpu_memory_buffer_manager_.get(), nullptr,
- kDelegatedSyncPointsRequired, kEnableColorCorrectRendering,
- CreateResourceSettings()));
+ auto resource_provider(std::make_unique<LayerTreeResourceProvider>(
+ context_provider.get(), shared_bitmap_manager_.get(),
+ gpu_memory_buffer_manager_.get(), kDelegatedSyncPointsRequired,
+ CreateResourceSettings()));
viz::ResourceId id = resource_provider->CreateGpuMemoryBufferResource(
- gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ gfx::Size(kWidth, kHeight), ResourceProvider::TEXTURE_HINT_DEFAULT,
format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gfx::ColorSpace());
InSequence sequence;
diff --git a/chromium/cc/resources/return_callback.h b/chromium/cc/resources/return_callback.h
index 30f0cf9ac5d..a8d5c3a1819 100644
--- a/chromium/cc/resources/return_callback.h
+++ b/chromium/cc/resources/return_callback.h
@@ -9,11 +9,9 @@
#include "components/viz/common/resources/returned_resource.h"
namespace cc {
-class BlockingTaskRunner;
-typedef base::Callback<void(const std::vector<viz::ReturnedResource>&,
- BlockingTaskRunner* main_thread_task_runner)>
- ReturnCallback;
+using ReturnCallback =
+ base::Callback<void(const std::vector<viz::ReturnedResource>&)>;
} // namespace cc
diff --git a/chromium/cc/resources/scoped_resource.cc b/chromium/cc/resources/scoped_resource.cc
index 75fa38f741f..e63e9c26dc4 100644
--- a/chromium/cc/resources/scoped_resource.cc
+++ b/chromium/cc/resources/scoped_resource.cc
@@ -25,6 +25,7 @@ void ScopedResource::Allocate(const gfx::Size& size,
set_dimensions(size, format);
set_id(resource_provider_->CreateResource(size, hint, format, color_space));
set_color_space(color_space);
+ hint_ = hint;
#if DCHECK_IS_ON()
allocate_thread_id_ = base::PlatformThread::CurrentId();
@@ -41,9 +42,10 @@ void ScopedResource::AllocateWithGpuMemoryBuffer(
set_dimensions(size, format);
set_id(resource_provider_->CreateGpuMemoryBufferResource(
- size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format, usage,
+ size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, usage,
color_space));
set_color_space(color_space);
+ hint_ = ResourceProvider::TEXTURE_HINT_DEFAULT;
#if DCHECK_IS_ON()
allocate_thread_id_ = base::PlatformThread::CurrentId();
diff --git a/chromium/cc/resources/scoped_resource.h b/chromium/cc/resources/scoped_resource.h
index 1e0b0eba5d8..8fc989ce38f 100644
--- a/chromium/cc/resources/scoped_resource.h
+++ b/chromium/cc/resources/scoped_resource.h
@@ -34,8 +34,12 @@ class CC_EXPORT ScopedResource : public Resource {
const gfx::ColorSpace& color_space);
void Free();
+ ResourceProvider::TextureHint hint() const { return hint_; }
+
private:
ResourceProvider* resource_provider_;
+ ResourceProvider::TextureHint hint_ =
+ ResourceProvider::TextureHint::TEXTURE_HINT_DEFAULT;
#if DCHECK_IS_ON()
base::PlatformThreadId allocate_thread_id_;
diff --git a/chromium/cc/resources/scoped_resource_unittest.cc b/chromium/cc/resources/scoped_resource_unittest.cc
index 42b2e3671fa..73cedf27ae0 100644
--- a/chromium/cc/resources/scoped_resource_unittest.cc
+++ b/chromium/cc/resources/scoped_resource_unittest.cc
@@ -46,7 +46,7 @@ TEST(ScopedResourceTest, CreateScopedResource) {
FakeResourceProvider::Create(context_provider.get(),
shared_bitmap_manager.get());
auto texture = std::make_unique<ScopedResource>(resource_provider.get());
- texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_DEFAULT,
viz::RGBA_8888, gfx::ColorSpace());
// The texture has an allocated byte-size now.
@@ -73,9 +73,8 @@ TEST(ScopedResourceTest, ScopedResourceIsDeleted) {
auto texture = std::make_unique<ScopedResource>(resource_provider.get());
EXPECT_EQ(0u, resource_provider->num_resources());
- texture->Allocate(gfx::Size(30, 30),
- ResourceProvider::TEXTURE_HINT_IMMUTABLE, viz::RGBA_8888,
- gfx::ColorSpace());
+ texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_DEFAULT,
+ viz::RGBA_8888, gfx::ColorSpace());
EXPECT_LT(0u, texture->id());
EXPECT_EQ(1u, resource_provider->num_resources());
}
@@ -84,9 +83,8 @@ TEST(ScopedResourceTest, ScopedResourceIsDeleted) {
{
auto texture = std::make_unique<ScopedResource>(resource_provider.get());
EXPECT_EQ(0u, resource_provider->num_resources());
- texture->Allocate(gfx::Size(30, 30),
- ResourceProvider::TEXTURE_HINT_IMMUTABLE, viz::RGBA_8888,
- gfx::ColorSpace());
+ texture->Allocate(gfx::Size(30, 30), ResourceProvider::TEXTURE_HINT_DEFAULT,
+ viz::RGBA_8888, gfx::ColorSpace());
EXPECT_LT(0u, texture->id());
EXPECT_EQ(1u, resource_provider->num_resources());
texture->Free();
diff --git a/chromium/cc/resources/single_release_callback_impl.cc b/chromium/cc/resources/single_release_callback_impl.cc
deleted file mode 100644
index bab9dd462d8..00000000000
--- a/chromium/cc/resources/single_release_callback_impl.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/resources/single_release_callback_impl.h"
-
-#include "base/callback_helpers.h"
-#include "base/logging.h"
-#include "cc/trees/blocking_task_runner.h"
-
-namespace cc {
-
-SingleReleaseCallbackImpl::SingleReleaseCallbackImpl(
- const ReleaseCallbackImpl& callback)
- : callback_(callback) {
- DCHECK(!callback_.is_null())
- << "Use a NULL SingleReleaseCallbackImpl for an empty callback.";
-}
-
-SingleReleaseCallbackImpl::~SingleReleaseCallbackImpl() {
- DCHECK(callback_.is_null()) << "SingleReleaseCallbackImpl was never run.";
-}
-
-void SingleReleaseCallbackImpl::Run(
- const gpu::SyncToken& sync_token,
- bool is_lost,
- BlockingTaskRunner* main_thread_task_runner) {
- DCHECK(!callback_.is_null())
- << "SingleReleaseCallbackImpl was run more than once.";
- base::ResetAndReturn(&callback_)
- .Run(sync_token, is_lost, main_thread_task_runner);
-}
-
-} // namespace cc
diff --git a/chromium/cc/resources/single_release_callback_impl.h b/chromium/cc/resources/single_release_callback_impl.h
deleted file mode 100644
index f5a8af05645..00000000000
--- a/chromium/cc/resources/single_release_callback_impl.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_RESOURCES_SINGLE_RELEASE_CALLBACK_IMPL_H_
-#define CC_RESOURCES_SINGLE_RELEASE_CALLBACK_IMPL_H_
-
-#include <memory>
-
-#include "base/memory/ptr_util.h"
-#include "cc/cc_export.h"
-#include "cc/resources/release_callback_impl.h"
-
-namespace cc {
-
-class CC_EXPORT SingleReleaseCallbackImpl {
- public:
- static std::unique_ptr<SingleReleaseCallbackImpl> Create(
- const ReleaseCallbackImpl& cb) {
- return base::WrapUnique(new SingleReleaseCallbackImpl(cb));
- }
-
- ~SingleReleaseCallbackImpl();
-
- void Run(const gpu::SyncToken& sync_token,
- bool is_lost,
- BlockingTaskRunner* main_thread_task_runner);
-
- private:
- explicit SingleReleaseCallbackImpl(const ReleaseCallbackImpl& callback);
-
- ReleaseCallbackImpl callback_;
-};
-
-} // namespace cc
-
-#endif // CC_RESOURCES_SINGLE_RELEASE_CALLBACK_IMPL_H_
diff --git a/chromium/cc/resources/video_resource_updater.cc b/chromium/cc/resources/video_resource_updater.cc
index f27a011b7da..dfeab2c0922 100644
--- a/chromium/cc/resources/video_resource_updater.cc
+++ b/chromium/cc/resources/video_resource_updater.cc
@@ -210,7 +210,6 @@ VideoResourceUpdater::RecycleOrAllocateResource(
viz::ResourceFormat resource_format,
const gfx::ColorSpace& color_space,
bool software_resource,
- bool immutable_hint,
int unique_id,
int plane_index) {
ResourceList::iterator recyclable_resource = all_resources_.end();
@@ -240,8 +239,7 @@ VideoResourceUpdater::RecycleOrAllocateResource(
if (!in_use && it->resource_size() == resource_size &&
it->resource_format() == resource_format &&
- it->mailbox().IsZero() == software_resource &&
- resource_provider_->IsImmutable(it->resource_id()) == immutable_hint) {
+ it->mailbox().IsZero() == software_resource) {
recyclable_resource = it;
}
}
@@ -251,22 +249,18 @@ VideoResourceUpdater::RecycleOrAllocateResource(
// There was nothing available to reuse or recycle. Allocate a new resource.
return AllocateResource(resource_size, resource_format, color_space,
- !software_resource, immutable_hint);
+ !software_resource);
}
VideoResourceUpdater::ResourceList::iterator
VideoResourceUpdater::AllocateResource(const gfx::Size& plane_size,
viz::ResourceFormat format,
const gfx::ColorSpace& color_space,
- bool has_mailbox,
- bool immutable_hint) {
+ bool has_mailbox) {
// TODO(danakj): Abstract out hw/sw resource create/delete from
// ResourceProvider and stop using ResourceProvider in this class.
const viz::ResourceId resource_id = resource_provider_->CreateResource(
- plane_size,
- immutable_hint ? ResourceProvider::TEXTURE_HINT_IMMUTABLE
- : ResourceProvider::TEXTURE_HINT_DEFAULT,
- format, color_space);
+ plane_size, ResourceProvider::TEXTURE_HINT_DEFAULT, format, color_space);
DCHECK_NE(resource_id, 0u);
gpu::Mailbox mailbox;
@@ -389,10 +383,9 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
return VideoFrameExternalResources();
}
- const bool is_immutable = true;
ResourceList::iterator resource_it = RecycleOrAllocateResource(
output_plane_resource_size, output_resource_format, output_color_space,
- software_compositor, is_immutable, video_frame->unique_id(), i);
+ software_compositor, video_frame->unique_id(), i);
resource_it->add_ref();
plane_resources.push_back(resource_it);
@@ -464,12 +457,29 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
}
std::unique_ptr<media::HalfFloatMaker> half_float_maker;
- if (resource_provider_->YuvResourceFormat(bits_per_channel) ==
- viz::LUMINANCE_F16) {
- half_float_maker =
- media::HalfFloatMaker::NewHalfFloatMaker(bits_per_channel);
- external_resources.offset = half_float_maker->Offset();
- external_resources.multiplier = half_float_maker->Multiplier();
+
+ switch (resource_provider_->YuvResourceFormat(bits_per_channel)) {
+ case viz::LUMINANCE_F16:
+ half_float_maker =
+ media::HalfFloatMaker::NewHalfFloatMaker(bits_per_channel);
+ external_resources.offset = half_float_maker->Offset();
+ external_resources.multiplier = half_float_maker->Multiplier();
+ break;
+ case viz::R16_EXT:
+ external_resources.multiplier = 65535.0f / ((1 << bits_per_channel) - 1);
+ external_resources.offset = 0;
+ break;
+ case viz::LUMINANCE_8:
+ case viz::RED_8:
+ break;
+ case viz::ALPHA_8:
+ case viz::RGBA_8888:
+ case viz::RGBA_4444:
+ case viz::BGRA_8888:
+ case viz::RGB_565:
+ case viz::ETC1:
+ case viz::RGBA_F16:
+ NOTREACHED();
}
for (size_t i = 0; i < plane_resources.size(); ++i) {
@@ -497,6 +507,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
size_t upload_image_stride =
MathUtil::CheckedRoundUp<size_t>(bytes_per_row, 4u);
+ // R16_EXT can represent 16-bit int, so we don't need a conversion step.
bool needs_conversion = false;
int shift = 0;
@@ -504,9 +515,10 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
// step.
if (plane_resource.resource_format() == viz::LUMINANCE_F16) {
needs_conversion = true;
- } else if (bits_per_channel > 8) {
- // If bits_per_channel > 8 and we can't use viz::LUMINANCE_F16, we need
- // to shift the data down and create an 8-bit texture.
+ } else if (plane_resource.resource_format() != viz::R16_EXT &&
+ bits_per_channel > 8) {
+ // If bits_per_channel > 8 and we can't use viz::LUMINANCE_F16 or
+ // R16_EXT we need to shift the data down and create an 8-bit texture.
needs_conversion = true;
shift = bits_per_channel - 8;
}
@@ -581,8 +593,7 @@ void VideoResourceUpdater::ReturnTexture(
base::WeakPtr<VideoResourceUpdater> updater,
const scoped_refptr<media::VideoFrame>& video_frame,
const gpu::SyncToken& sync_token,
- bool lost_resource,
- BlockingTaskRunner* main_thread_task_runner) {
+ bool lost_resource) {
// TODO(dshwang) this case should be forwarded to the decoder as lost
// resource.
if (lost_resource || !updater.get())
@@ -605,13 +616,12 @@ void VideoResourceUpdater::CopyPlaneTexture(
// target to avoid loss of precision or dropping any alpha component.
const viz::ResourceFormat copy_target_format = viz::ResourceFormat::RGBA_8888;
- const bool is_immutable = false;
const int no_unique_id = 0;
const int no_plane_index = -1; // Do not recycle referenced textures.
VideoResourceUpdater::ResourceList::iterator resource =
RecycleOrAllocateResource(output_plane_resource_size, copy_target_format,
- resource_color_space, false, is_immutable,
- no_unique_id, no_plane_index);
+ resource_color_space, false, no_unique_id,
+ no_plane_index);
resource->add_ref();
ResourceProvider::ScopedWriteLockGL lock(resource_provider_,
@@ -637,7 +647,7 @@ void VideoResourceUpdater::CopyPlaneTexture(
// Set sync token otherwise resource is assumed to be synchronized.
viz::TextureMailbox mailbox(resource->mailbox(), sync_token, GL_TEXTURE_2D,
- video_frame->coded_size(), false, false);
+ video_frame->coded_size(), false);
mailbox.set_color_space(resource_color_space);
external_resources->mailboxes.push_back(mailbox);
@@ -686,8 +696,7 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes(
mailbox_holder.mailbox, mailbox_holder.sync_token,
mailbox_holder.texture_target, video_frame->coded_size(),
video_frame->metadata()->IsTrue(
- media::VideoFrameMetadata::ALLOW_OVERLAY),
- false);
+ media::VideoFrameMetadata::ALLOW_OVERLAY));
mailbox.set_color_space(resource_color_space);
#if defined(OS_ANDROID)
mailbox.set_is_backed_by_surface_texture(video_frame->metadata()->IsTrue(
@@ -708,8 +717,7 @@ void VideoResourceUpdater::RecycleResource(
base::WeakPtr<VideoResourceUpdater> updater,
viz::ResourceId resource_id,
const gpu::SyncToken& sync_token,
- bool lost_resource,
- BlockingTaskRunner* main_thread_task_runner) {
+ bool lost_resource) {
if (!updater.get()) {
// Resource was already deleted.
return;
diff --git a/chromium/cc/resources/video_resource_updater.h b/chromium/cc/resources/video_resource_updater.h
index a7ac7e5c734..34bf4bf3e0f 100644
--- a/chromium/cc/resources/video_resource_updater.h
+++ b/chromium/cc/resources/video_resource_updater.h
@@ -17,8 +17,8 @@
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "cc/cc_export.h"
-#include "cc/resources/release_callback_impl.h"
#include "components/viz/common/quads/texture_mailbox.h"
+#include "components/viz/common/resources/release_callback.h"
#include "components/viz/common/resources/resource_format.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/size.h"
@@ -54,14 +54,14 @@ class CC_EXPORT VideoFrameExternalResources {
ResourceType type;
std::vector<viz::TextureMailbox> mailboxes;
- std::vector<ReleaseCallbackImpl> release_callbacks;
+ std::vector<viz::ReleaseCallback> release_callbacks;
bool read_lock_fences_enabled;
// Format of the storage of the resource, if known.
gfx::BufferFormat buffer_format;
// TODO(danakj): Remove these too.
std::vector<unsigned> software_resources;
- ReleaseCallbackImpl software_release_callback;
+ viz::ReleaseCallback software_release_callback;
// Used by hardware textures which do not return values in the 0-1 range.
// After a lookup, subtract offset and multiply by multiplier.
@@ -86,6 +86,10 @@ class CC_EXPORT VideoResourceUpdater {
VideoFrameExternalResources CreateExternalResourcesFromVideoFrame(
scoped_refptr<media::VideoFrame> video_frame);
+ void SetUseR16ForTesting(bool use_r16_for_testing) {
+ use_r16_for_testing_ = use_r16_for_testing;
+ }
+
private:
class PlaneResource {
public:
@@ -150,14 +154,12 @@ class CC_EXPORT VideoResourceUpdater {
viz::ResourceFormat resource_format,
const gfx::ColorSpace& color_space,
bool software_resource,
- bool immutable_hint,
int unique_id,
int plane_index);
ResourceList::iterator AllocateResource(const gfx::Size& plane_size,
viz::ResourceFormat format,
const gfx::ColorSpace& color_space,
- bool has_mailbox,
- bool immutable_hint);
+ bool has_mailbox);
void DeleteResource(ResourceList::iterator resource_it);
void CopyPlaneTexture(media::VideoFrame* video_frame,
const gfx::ColorSpace& resource_color_space,
@@ -171,19 +173,18 @@ class CC_EXPORT VideoResourceUpdater {
static void RecycleResource(base::WeakPtr<VideoResourceUpdater> updater,
unsigned resource_id,
const gpu::SyncToken& sync_token,
- bool lost_resource,
- BlockingTaskRunner* main_thread_task_runner);
+ bool lost_resource);
static void ReturnTexture(base::WeakPtr<VideoResourceUpdater> updater,
const scoped_refptr<media::VideoFrame>& video_frame,
const gpu::SyncToken& sync_token,
- bool lost_resource,
- BlockingTaskRunner* main_thread_task_runner);
+ bool lost_resource);
viz::ContextProvider* context_provider_;
ResourceProvider* resource_provider_;
const bool use_stream_video_draw_quad_;
std::unique_ptr<media::SkCanvasVideoRenderer> video_renderer_;
std::vector<uint8_t> upload_pixels_;
+ bool use_r16_for_testing_ = false;
// Recycle resources so that we can reduce the number of allocations and
// data transfers.
diff --git a/chromium/cc/resources/video_resource_updater_unittest.cc b/chromium/cc/resources/video_resource_updater_unittest.cc
index 8c0f6ca6c16..238d6b81838 100644
--- a/chromium/cc/resources/video_resource_updater_unittest.cc
+++ b/chromium/cc/resources/video_resource_updater_unittest.cc
@@ -15,7 +15,6 @@
#include "cc/test/fake_resource_provider.h"
#include "cc/test/test_shared_bitmap_manager.h"
#include "cc/test/test_web_graphics_context_3d.h"
-#include "cc/trees/blocking_task_runner.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "media/base/video_frame.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -42,7 +41,6 @@ class WebGraphicsContext3DUploadCounter : public TestWebGraphicsContext3D {
GLuint internalformat,
GLint width,
GLint height) override {
- immutable_texture_created_ = true;
}
GLuint createTexture() override {
@@ -66,13 +64,9 @@ class WebGraphicsContext3DUploadCounter : public TestWebGraphicsContext3D {
int TextureCreationCount() { return created_texture_count_; }
void ResetTextureCreationCount() { created_texture_count_ = 0; }
- bool WasImmutableTextureCreated() { return immutable_texture_created_; }
- void ResetImmutableTextureCreated() { immutable_texture_created_ = false; }
-
private:
int upload_count_;
int created_texture_count_;
- bool immutable_texture_created_;
};
class SharedBitmapManagerAllocationCounter : public TestSharedBitmapManager {
@@ -105,12 +99,12 @@ class VideoResourceUpdaterTest : public testing::Test {
void SetUp() override {
testing::Test::SetUp();
-
shared_bitmap_manager_.reset(new SharedBitmapManagerAllocationCounter());
resource_provider3d_ = FakeResourceProvider::Create(
- context_provider_.get(), shared_bitmap_manager_.get());
- resource_provider_software_ =
- FakeResourceProvider::Create(nullptr, shared_bitmap_manager_.get());
+ context_provider_.get(), shared_bitmap_manager_.get(),
+ high_bit_for_testing_);
+ resource_provider_software_ = FakeResourceProvider::Create(
+ nullptr, shared_bitmap_manager_.get(), high_bit_for_testing_);
}
scoped_refptr<media::VideoFrame> CreateTestYUVVideoFrame() {
@@ -251,6 +245,7 @@ class VideoResourceUpdaterTest : public testing::Test {
std::unique_ptr<ResourceProvider> resource_provider3d_;
std::unique_ptr<ResourceProvider> resource_provider_software_;
gpu::SyncToken release_sync_token_;
+ bool high_bit_for_testing_ = false;
};
const gpu::SyncToken VideoResourceUpdaterTest::kMailboxSyncToken =
@@ -312,6 +307,40 @@ TEST_F(VideoResourceUpdaterTestWithF16, HighBitFrame) {
EXPECT_NEAR(resources2.offset, 0.5, 0.1);
}
+class VideoResourceUpdaterTestWithR16 : public VideoResourceUpdaterTest {
+ public:
+ VideoResourceUpdaterTestWithR16() : VideoResourceUpdaterTest() {
+ high_bit_for_testing_ = true;
+ context3d_->set_support_texture_norm16(true);
+ }
+};
+
+TEST_F(VideoResourceUpdaterTestWithR16, HighBitFrame) {
+ bool use_stream_video_draw_quad = false;
+ VideoResourceUpdater updater(context_provider_.get(),
+ resource_provider3d_.get(),
+ use_stream_video_draw_quad);
+ updater.SetUseR16ForTesting(true);
+ scoped_refptr<media::VideoFrame> video_frame = CreateTestHighBitFrame();
+
+ VideoFrameExternalResources resources =
+ updater.CreateExternalResourcesFromVideoFrame(video_frame);
+ EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type);
+
+ // Max 10-bit values as read by a sampler.
+ double max_10bit_value = ((1 << 10) - 1) / 65535.0;
+ EXPECT_NEAR(resources.multiplier * max_10bit_value, 1.0, 0.0001);
+ EXPECT_NEAR(resources.offset, 0.0, 0.1);
+
+ // Create the resource again, to test the path where the
+ // resources are cached.
+ VideoFrameExternalResources resources2 =
+ updater.CreateExternalResourcesFromVideoFrame(video_frame);
+ EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources2.type);
+ EXPECT_NEAR(resources2.multiplier * max_10bit_value, 1.0, 0.0001);
+ EXPECT_NEAR(resources2.offset, 0.0, 0.1);
+}
+
TEST_F(VideoResourceUpdaterTest, HighBitFrameSoftwareCompositor) {
bool use_stream_video_draw_quad = false;
VideoResourceUpdater updater(nullptr, resource_provider_software_.get(),
@@ -367,8 +396,8 @@ TEST_F(VideoResourceUpdaterTest, ReuseResource) {
// Simulate the ResourceProvider releasing the resources back to the video
// updater.
- for (ReleaseCallbackImpl& release_callback : resources.release_callbacks)
- release_callback.Run(gpu::SyncToken(), false, nullptr);
+ for (auto& release_callback : resources.release_callbacks)
+ release_callback.Run(gpu::SyncToken(), false);
// Allocate resources for the same frame.
context3d_->ResetUploadCount();
@@ -440,7 +469,7 @@ TEST_F(VideoResourceUpdaterTest, ReuseResourceSoftwareCompositor) {
// Simulate the ResourceProvider releasing the resource back to the video
// updater.
- resources.software_release_callback.Run(gpu::SyncToken(), false, nullptr);
+ resources.software_release_callback.Run(gpu::SyncToken(), false);
// Allocate resources for the same frame.
shared_bitmap_manager_->ResetAllocationCount();
@@ -541,7 +570,6 @@ TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_StreamTexture) {
// GL_TEXTURE_2D texture.
context3d_->ResetTextureCreationCount();
video_frame = CreateTestStreamTextureHardwareVideoFrame(true);
- context3d_->ResetImmutableTextureCreated();
resources = updater.CreateExternalResourcesFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameExternalResources::RGBA_PREMULTIPLIED_RESOURCE,
resources.type);
@@ -550,13 +578,6 @@ TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_StreamTexture) {
EXPECT_EQ(1u, resources.release_callbacks.size());
EXPECT_EQ(0u, resources.software_resources.size());
EXPECT_EQ(1, context3d_->TextureCreationCount());
-
- // The texture copy path requires the use of CopyTextureCHROMIUM, which
- // enforces that the target texture not be immutable, as it may need
- // to alter the storage of the texture. Therefore, this test asserts
- // that an immutable texture wasn't created by glTexStorage2DEXT, when
- // that extension is supported.
- EXPECT_FALSE(context3d_->WasImmutableTextureCreated());
}
TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_TextureQuad) {
@@ -598,7 +619,7 @@ TEST_F(VideoResourceUpdaterTest, PassReleaseSyncToken) {
updater.CreateExternalResourcesFromVideoFrame(video_frame);
ASSERT_EQ(resources.release_callbacks.size(), 1u);
- resources.release_callbacks[0].Run(sync_token, false, nullptr);
+ resources.release_callbacks[0].Run(sync_token, false);
}
EXPECT_EQ(release_sync_token_, sync_token);
@@ -626,8 +647,8 @@ TEST_F(VideoResourceUpdaterTest, GenerateReleaseSyncToken) {
updater.CreateExternalResourcesFromVideoFrame(video_frame);
ASSERT_EQ(resources.release_callbacks.size(), 1u);
- resources.release_callbacks[0].Run(sync_token1, false, nullptr);
- resources.release_callbacks[0].Run(sync_token2, false, nullptr);
+ resources.release_callbacks[0].Run(sync_token1, false);
+ resources.release_callbacks[0].Run(sync_token2, false);
}
EXPECT_TRUE(release_sync_token_.HasData());
diff --git a/chromium/cc/scheduler/begin_frame_tracker.cc b/chromium/cc/scheduler/begin_frame_tracker.cc
index 4c1ef9a0f45..c220552d2f3 100644
--- a/chromium/cc/scheduler/begin_frame_tracker.cc
+++ b/chromium/cc/scheduler/begin_frame_tracker.cc
@@ -6,7 +6,7 @@
namespace cc {
-BeginFrameTracker::BeginFrameTracker(const tracked_objects::Location& location)
+BeginFrameTracker::BeginFrameTracker(const base::Location& location)
: location_(location),
location_string_(location.ToString()),
current_finished_at_(base::TimeTicks() +
diff --git a/chromium/cc/scheduler/begin_frame_tracker.h b/chromium/cc/scheduler/begin_frame_tracker.h
index 4e237c70d8d..33d124ad7e5 100644
--- a/chromium/cc/scheduler/begin_frame_tracker.h
+++ b/chromium/cc/scheduler/begin_frame_tracker.h
@@ -35,7 +35,7 @@ namespace cc {
// TODO(mithro): Record stats about the viz::BeginFrameArgs
class CC_EXPORT BeginFrameTracker {
public:
- explicit BeginFrameTracker(const tracked_objects::Location& location);
+ explicit BeginFrameTracker(const base::Location& location);
~BeginFrameTracker();
// The Start and Finish methods manage the period that a BFA should be
@@ -85,7 +85,7 @@ class CC_EXPORT BeginFrameTracker {
// the BFA object. Can be called at any time.
bool HasFinished() const { return !current_finished_at_.is_null(); }
- const tracked_objects::Location location_;
+ const base::Location location_;
const std::string location_string_;
base::TimeTicks current_updated_at_;
diff --git a/chromium/cc/scheduler/compositor_timing_history.cc b/chromium/cc/scheduler/compositor_timing_history.cc
index d7e128c2791..2dd48bfdb43 100644
--- a/chromium/cc/scheduler/compositor_timing_history.cc
+++ b/chromium/cc/scheduler/compositor_timing_history.cc
@@ -801,7 +801,6 @@ void CompositorTimingHistory::DrawAborted() {
}
void CompositorTimingHistory::DidDraw(bool used_new_active_tree,
- bool main_thread_missed_last_deadline,
base::TimeTicks impl_frame_time) {
DCHECK_NE(base::TimeTicks(), draw_start_time_);
base::TimeTicks draw_end_time = Now();
diff --git a/chromium/cc/scheduler/compositor_timing_history.h b/chromium/cc/scheduler/compositor_timing_history.h
index 5e97dcb2486..40c3133df20 100644
--- a/chromium/cc/scheduler/compositor_timing_history.h
+++ b/chromium/cc/scheduler/compositor_timing_history.h
@@ -75,7 +75,6 @@ class CC_EXPORT CompositorTimingHistory {
void DrawAborted();
void WillDraw();
void DidDraw(bool used_new_active_tree,
- bool main_thread_missed_last_deadline,
base::TimeTicks impl_frame_time);
void DidSubmitCompositorFrame();
void DidReceiveCompositorFrameAck();
diff --git a/chromium/cc/scheduler/compositor_timing_history_unittest.cc b/chromium/cc/scheduler/compositor_timing_history_unittest.cc
index 08e9c006047..a6fac32f8f0 100644
--- a/chromium/cc/scheduler/compositor_timing_history_unittest.cc
+++ b/chromium/cc/scheduler/compositor_timing_history_unittest.cc
@@ -88,7 +88,7 @@ TEST_F(CompositorTimingHistoryTest, AllSequential_Commit) {
AdvanceNowBy(one_second);
timing_history_.WillDraw();
AdvanceNowBy(draw_duration);
- timing_history_.DidDraw(true, true, Now());
+ timing_history_.DidDraw(true, Now());
EXPECT_EQ(begin_main_frame_queue_duration,
timing_history_.BeginMainFrameQueueDurationCriticalEstimate());
@@ -138,7 +138,7 @@ TEST_F(CompositorTimingHistoryTest, AllSequential_BeginMainFrameAborted) {
AdvanceNowBy(one_second);
timing_history_.WillDraw();
AdvanceNowBy(draw_duration);
- timing_history_.DidDraw(false, false, Now());
+ timing_history_.DidDraw(false, Now());
EXPECT_EQ(base::TimeDelta(),
timing_history_.BeginMainFrameQueueDurationCriticalEstimate());
diff --git a/chromium/cc/scheduler/scheduler.cc b/chromium/cc/scheduler/scheduler.cc
index a3331aa3b70..d53df70e95c 100644
--- a/chromium/cc/scheduler/scheduler.cc
+++ b/chromium/cc/scheduler/scheduler.cc
@@ -9,7 +9,6 @@
#include "base/auto_reset.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
-#include "base/profiler/scoped_tracker.h"
#include "base/single_thread_task_runner.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_event_argument.h"
@@ -573,14 +572,12 @@ void Scheduler::DrawIfPossible() {
bool drawing_with_new_active_tree =
state_machine_.active_tree_needs_first_draw() &&
!state_machine_.previous_pending_tree_was_impl_side();
- bool main_thread_missed_last_deadline =
- state_machine_.main_thread_missed_last_deadline();
compositor_timing_history_->WillDraw();
state_machine_.WillDraw();
DrawResult result = client_->ScheduledActionDrawIfPossible();
state_machine_.DidDraw(result);
compositor_timing_history_->DidDraw(
- drawing_with_new_active_tree, main_thread_missed_last_deadline,
+ drawing_with_new_active_tree,
begin_impl_frame_tracker_.DangerousMethodCurrentOrLast().frame_time);
}
@@ -588,14 +585,12 @@ void Scheduler::DrawForced() {
bool drawing_with_new_active_tree =
state_machine_.active_tree_needs_first_draw() &&
!state_machine_.previous_pending_tree_was_impl_side();
- bool main_thread_missed_last_deadline =
- state_machine_.main_thread_missed_last_deadline();
compositor_timing_history_->WillDraw();
state_machine_.WillDraw();
DrawResult result = client_->ScheduledActionDrawForced();
state_machine_.DidDraw(result);
compositor_timing_history_->DidDraw(
- drawing_with_new_active_tree, main_thread_missed_last_deadline,
+ drawing_with_new_active_tree,
begin_impl_frame_tracker_.DangerousMethodCurrentOrLast().frame_time);
}
diff --git a/chromium/cc/scheduler/scheduler.h b/chromium/cc/scheduler/scheduler.h
index fb354cdee63..2fa0e7114b7 100644
--- a/chromium/cc/scheduler/scheduler.h
+++ b/chromium/cc/scheduler/scheduler.h
@@ -5,7 +5,6 @@
#ifndef CC_SCHEDULER_SCHEDULER_H_
#define CC_SCHEDULER_SCHEDULER_H_
-#include <deque>
#include <memory>
#include <string>
diff --git a/chromium/cc/scheduler/scheduler_state_machine.cc b/chromium/cc/scheduler/scheduler_state_machine.cc
index f75966b4ebc..d2f6b201ea2 100644
--- a/chromium/cc/scheduler/scheduler_state_machine.cc
+++ b/chromium/cc/scheduler/scheduler_state_machine.cc
@@ -246,34 +246,35 @@ bool SchedulerStateMachine::PendingDrawsShouldBeAborted() const {
if (resourceless_draw_)
return is_layer_tree_frame_sink_lost || !can_draw_;
- // These are all the cases where we normally cannot or do not want to draw
- // but, if needs_redraw_ is true and we do not draw to make forward progress,
- // we might deadlock with the main thread.
- // This should be a superset of PendingActivationsShouldBeForced() since
- // activation of the pending tree is blocked by drawing of the active tree and
- // the main thread might be blocked on activation of the most recent commit.
+ // These are all the cases where we normally cannot or do not want
+ // to draw but, if |needs_redraw_| is true and we do not draw to
+ // make forward progress, we might deadlock with the main
+ // thread. This should be a superset of ShouldAbortCurrentFrame()
+ // since activation of the pending tree is blocked by drawing of the
+ // active tree and the main thread might be blocked on activation of
+ // the most recent commit.
return is_layer_tree_frame_sink_lost || !can_draw_ || !visible_ ||
begin_frame_source_paused_;
}
-bool SchedulerStateMachine::PendingActivationsShouldBeForced() const {
- // There is no output surface to trigger our activations.
- // If we do not force activations to make forward progress, we might deadlock
- // with the main thread.
+bool SchedulerStateMachine::ShouldAbortCurrentFrame() const {
+ // Abort the frame if there is no output surface to trigger our
+ // activations, avoiding deadlock with the main thread.
if (layer_tree_frame_sink_state_ == LAYER_TREE_FRAME_SINK_NONE)
return true;
- // If we're not visible, we should force activation.
- // Since we set RequiresHighResToDraw when becoming visible, we ensure that we
- // don't checkerboard until all visible resources are done. Furthermore, if we
- // do keep the pending tree around, when becoming visible we might activate
- // prematurely causing RequiresHighResToDraw flag to be reset. In all cases,
- // we can simply activate on becoming invisible since we don't need to draw
+ // If we're not visible, we should just abort the frame. Since we
+ // set RequiresHighResToDraw when becoming visible, we ensure that
+ // we don't checkerboard until all visible resources are
+ // done. Furthermore, if we do keep the pending tree around, when
+ // becoming visible we might activate prematurely causing
+ // RequiresHighResToDraw flag to be reset. In all cases, we can
+ // simply activate on becoming invisible since we don't need to draw
// the active tree when we're in this state.
if (!visible_)
return true;
- // Force pending activations when viz::BeginFrameSource is paused to avoid
+ // Abort the frame when viz::BeginFrameSource is paused to avoid
// deadlocking the main thread.
if (begin_frame_source_paused_)
return true;
@@ -366,8 +367,7 @@ bool SchedulerStateMachine::ShouldActivateSyncTree() const {
if (active_tree_needs_first_draw_)
return false;
- // If we want to force activation, do so ASAP.
- if (PendingActivationsShouldBeForced())
+ if (ShouldAbortCurrentFrame())
return true;
// At this point, only activate if we are ready to activate.
@@ -526,6 +526,11 @@ bool SchedulerStateMachine::ShouldCommit() const {
}
bool SchedulerStateMachine::ShouldPrepareTiles() const {
+ // In full-pipeline mode, we need to prepare tiles ASAP to ensure that we
+ // don't get stuck.
+ if (settings_.wait_for_all_pipeline_stages_before_draw)
+ return needs_prepare_tiles_;
+
// Do not prepare tiles if we've already done so in commit or impl side
// invalidation.
if (did_prepare_tiles_)
@@ -592,6 +597,8 @@ bool SchedulerStateMachine::ShouldPerformImplSideInvalidation() const {
// Only perform impl side invalidation after the frame ends so that we wait
// for any commit to happen before invalidating.
+ // TODO(khushalsagar): Invalidate at the beginning of the frame if there is no
+ // commit request from the main thread.
if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE)
return false;
@@ -1014,8 +1021,8 @@ SchedulerStateMachine::CurrentBeginImplFrameDeadlineMode() const {
bool SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately()
const {
- // If we just forced activation, we should end the deadline right now.
- if (PendingActivationsShouldBeForced() && !has_pending_tree_)
+ // If we aborted the current frame we should end the deadline right now.
+ if (ShouldAbortCurrentFrame() && !has_pending_tree_)
return true;
// Throttle the deadline on CompositorFrameAck since we wont draw and submit
@@ -1055,21 +1062,39 @@ bool SchedulerStateMachine::ShouldBlockDeadlineIndefinitely() const {
return false;
}
- // Avoid blocking when invisible / frame sink lost / can't draw, i.e. when
- // PendingDrawsShouldBeAborted is true.
- if (PendingDrawsShouldBeAborted())
+ // Avoid blocking for any reason if we don't have a layer tree frame sink or
+ // are invisible.
+ if (layer_tree_frame_sink_state_ == LAYER_TREE_FRAME_SINK_NONE)
return false;
- // Wait for all pipeline stages.
+ if (!visible_)
+ return false;
+
+ // Wait for main frame to be ready for commits if in full-pipe mode, so that
+ // we ensure we block during renderer initialization. In commit_to_active_tree
+ // mode, we cannot block for defer_commits_, as this may negatively affect
+ // animation smoothness during resize or orientation changes.
+ if (defer_commits_ && settings_.wait_for_all_pipeline_stages_before_draw)
+ return true;
+
+ // Wait for main frame if one is in progress or about to be started.
if (ShouldSendBeginMainFrame())
return true;
if (begin_main_frame_state_ != BEGIN_MAIN_FRAME_STATE_IDLE)
return true;
+ // Wait for tiles and activation.
if (has_pending_tree_)
return true;
+ // Avoid blocking for draw when we can't draw. We block in the above cases
+ // even if we cannot draw, because we may still be waiting for the first
+ // active tree.
+ if (!can_draw_)
+ return false;
+
+ // Wait for remaining tiles and draw.
if (!active_tree_is_ready_to_draw_)
return true;
diff --git a/chromium/cc/scheduler/scheduler_state_machine.h b/chromium/cc/scheduler/scheduler_state_machine.h
index 3370c63e616..9985bfe6a40 100644
--- a/chromium/cc/scheduler/scheduler_state_machine.h
+++ b/chromium/cc/scheduler/scheduler_state_machine.h
@@ -305,9 +305,7 @@ class CC_EXPORT SchedulerStateMachine {
bool ShouldTriggerBeginImplFrameDeadlineImmediately() const;
bool ShouldBlockDeadlineIndefinitely() const;
- // True if we need to force activations to make forward progress.
- // TODO(sunnyps): Rename this to ShouldAbortCurrentFrame or similar.
- bool PendingActivationsShouldBeForced() const;
+ bool ShouldAbortCurrentFrame() const;
bool ShouldBeginLayerTreeFrameSinkCreation() const;
bool ShouldDraw() const;
diff --git a/chromium/cc/scheduler/scheduler_state_machine_unittest.cc b/chromium/cc/scheduler/scheduler_state_machine_unittest.cc
index 86516f56b9c..9e77c27c73f 100644
--- a/chromium/cc/scheduler/scheduler_state_machine_unittest.cc
+++ b/chromium/cc/scheduler/scheduler_state_machine_unittest.cc
@@ -146,8 +146,8 @@ class StateMachine : public SchedulerStateMachine {
bool CanDraw() const { return can_draw_; }
bool Visible() const { return visible_; }
- bool PendingActivationsShouldBeForced() const {
- return SchedulerStateMachine::PendingActivationsShouldBeForced();
+ bool ShouldAbortCurrentFrame() const {
+ return SchedulerStateMachine::ShouldAbortCurrentFrame();
}
bool has_pending_tree() const { return has_pending_tree_; }
@@ -159,6 +159,7 @@ class StateMachine : public SchedulerStateMachine {
return needs_impl_side_invalidation_;
}
+ using SchedulerStateMachine::ShouldPrepareTiles;
using SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately;
using SchedulerStateMachine::ProactiveBeginFrameWanted;
using SchedulerStateMachine::WillCommit;
@@ -1181,6 +1182,12 @@ TEST(SchedulerStateMachineTest, TestFullCycleWithCommitToActive) {
state.OnBeginImplFrameDeadline();
EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
+
+ // When commits are deferred, we don't block the deadline.
+ state.SetDeferCommits(true);
+ state.OnBeginImplFrame(0, 13);
+ EXPECT_NE(SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED,
+ state.CurrentBeginImplFrameDeadlineMode());
}
TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
@@ -1711,7 +1718,7 @@ TEST(SchedulerStateMachineTest,
}
TEST(SchedulerStateMachineTest,
- TestPendingActivationsShouldBeForcedAfterLostLayerTreeFrameSink) {
+ TestShouldAbortCurrentFrameAfterLostLayerTreeFrameSink) {
SchedulerSettings default_scheduler_settings;
StateMachine state(default_scheduler_settings);
SET_UP_STATE(state)
@@ -1726,7 +1733,7 @@ TEST(SchedulerStateMachineTest,
state.NotifyReadyToCommit();
EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
- EXPECT_TRUE(state.PendingActivationsShouldBeForced());
+ EXPECT_TRUE(state.ShouldAbortCurrentFrame());
EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
EXPECT_TRUE(state.PendingDrawsShouldBeAborted());
@@ -1816,7 +1823,7 @@ TEST(SchedulerStateMachineTest,
// because we are not visible.
state.NotifyBeginMainFrameStarted();
state.NotifyReadyToCommit();
- EXPECT_TRUE(state.PendingActivationsShouldBeForced());
+ EXPECT_TRUE(state.ShouldAbortCurrentFrame());
EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
EXPECT_TRUE(state.active_tree_needs_first_draw());
@@ -2066,7 +2073,7 @@ TEST(SchedulerStateMachineTest, TestTriggerDeadlineImmediatelyWhenInvisible) {
state.SetVisible(false);
EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
- EXPECT_TRUE(state.PendingActivationsShouldBeForced());
+ EXPECT_TRUE(state.ShouldAbortCurrentFrame());
EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
}
@@ -2086,7 +2093,7 @@ TEST(SchedulerStateMachineTest,
state.SetBeginFrameSourcePaused(true);
EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
- EXPECT_TRUE(state.PendingActivationsShouldBeForced());
+ EXPECT_TRUE(state.ShouldAbortCurrentFrame());
EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
}
@@ -2432,11 +2439,22 @@ TEST(SchedulerStateMachineTest, TestFullPipelineMode) {
// Start clean and set commit.
state.SetNeedsBeginMainFrame();
+ // While we are waiting for an main frame or pending tree activation, we
+ // should even block while we can't draw.
+ state.SetCanDraw(false);
+
// Begin the frame.
state.OnBeginImplFrame(0, 10);
- // Deadline immediately enters blocking mode, because we need a main frame.
+ // We are blocking because we need a main frame.
EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED,
state.CurrentBeginImplFrameDeadlineMode());
+
+ // Even if main thread defers commits, we still need to wait for it.
+ state.SetDeferCommits(true);
+ EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED,
+ state.CurrentBeginImplFrameDeadlineMode());
+ state.SetDeferCommits(false);
+
EXPECT_ACTION_UPDATE_STATE(
SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
@@ -2459,14 +2477,28 @@ TEST(SchedulerStateMachineTest, TestFullPipelineMode) {
// We are blocking on activation.
EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED,
state.CurrentBeginImplFrameDeadlineMode());
+ EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
+
+ // We should prepare tiles even though we are not in the deadline, otherwise
+ // we would get stuck here.
+ EXPECT_FALSE(state.ShouldPrepareTiles());
+ state.SetNeedsPrepareTiles();
+ EXPECT_TRUE(state.ShouldPrepareTiles());
+ EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_PREPARE_TILES);
// Ready to activate, but not draw.
state.NotifyReadyToActivate();
EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
- EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
- // We are blocking on ready to draw.
+ // We should no longer block, because can_draw is still false, and we are no
+ // longer waiting for activation.
+ EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE,
+ state.CurrentBeginImplFrameDeadlineMode());
+
+ // However, we should continue to block on ready to draw if we can draw.
+ state.SetCanDraw(true);
EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED,
state.CurrentBeginImplFrameDeadlineMode());
+ EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
// Ready to draw triggers immediate deadline.
state.NotifyReadyToDraw();
diff --git a/chromium/cc/tiles/checker_image_tracker.cc b/chromium/cc/tiles/checker_image_tracker.cc
index ccdfd3f936e..ee5e756243d 100644
--- a/chromium/cc/tiles/checker_image_tracker.cc
+++ b/chromium/cc/tiles/checker_image_tracker.cc
@@ -36,10 +36,9 @@ enum class CheckerImagingDecision {
// Vetoed because checkering of images has been disabled.
kVetoedForceDisable = 9,
- // Vetoed because we only checker images on tiles required for activation.
- kVetoedNotRequiredForActivation = 10,
+ // 10 used to be kVetoedNotRequiredForActivation.
- kCheckerImagingDecisionCount,
+ kCheckerImagingDecisionCount = 11,
};
std::string ToString(PaintImage::Id paint_image_id,
@@ -261,8 +260,7 @@ void CheckerImageTracker::DidFinishImageDecode(
}
bool CheckerImageTracker::ShouldCheckerImage(const DrawImage& draw_image,
- WhichTree tree,
- bool required_for_activation) {
+ WhichTree tree) {
const PaintImage& image = draw_image.paint_image();
PaintImage::Id image_id = image.stable_id();
TRACE_EVENT1("cc", "CheckerImageTracker::ShouldCheckerImage", "image_id",
@@ -306,15 +304,11 @@ bool CheckerImageTracker::ShouldCheckerImage(const DrawImage& draw_image,
CheckerImagingDecision decision = GetCheckerImagingDecision(
image, draw_image.src_rect(), min_image_bytes_to_checker_,
image_controller_->image_cache_max_limit_bytes());
- if (decision == CheckerImagingDecision::kCanChecker) {
- if (force_disabled_) {
- // Get the decision for all the veto reasons first, so we can UMA the
- // images that were not checkered only because checker-imaging was force
- // disabled.
- decision = CheckerImagingDecision::kVetoedForceDisable;
- } else if (!required_for_activation) {
- decision = CheckerImagingDecision::kVetoedNotRequiredForActivation;
- }
+ if (decision == CheckerImagingDecision::kCanChecker && force_disabled_) {
+ // Get the decision for all the veto reasons first, so we can UMA the
+ // images that were not checkered only because checker-imaging was force
+ // disabled.
+ decision = CheckerImagingDecision::kVetoedForceDisable;
}
it->second.policy = decision == CheckerImagingDecision::kCanChecker
@@ -362,6 +356,7 @@ void CheckerImageTracker::UpdateDecodeState(const DrawImage& draw_image,
decode_state->filter_quality =
std::max(decode_state->filter_quality, draw_image.filter_quality());
decode_state->color_space = draw_image.target_color_space();
+ decode_state->frame_index = draw_image.frame_index();
}
void CheckerImageTracker::ScheduleNextImageDecode() {
@@ -400,7 +395,7 @@ void CheckerImageTracker::ScheduleNextImageDecode() {
it->second.filter_quality,
SkMatrix::MakeScale(it->second.scale.width(),
it->second.scale.height()),
- it->second.color_space);
+ it->second.frame_index, it->second.color_space);
outstanding_image_decode_.emplace(candidate);
break;
}
diff --git a/chromium/cc/tiles/checker_image_tracker.h b/chromium/cc/tiles/checker_image_tracker.h
index 095c868fb3d..9a1157a2e09 100644
--- a/chromium/cc/tiles/checker_image_tracker.h
+++ b/chromium/cc/tiles/checker_image_tracker.h
@@ -59,9 +59,7 @@ class CC_EXPORT CheckerImageTracker {
// Returns true if the decode for |image| will be deferred to the image decode
// service and it should be be skipped during raster.
- bool ShouldCheckerImage(const DrawImage& image,
- WhichTree tree,
- bool required_for_activation);
+ bool ShouldCheckerImage(const DrawImage& image, WhichTree tree);
// Provides a prioritized queue of images to decode.
using ImageDecodeQueue = std::vector<ImageDecodeRequest>;
@@ -130,6 +128,7 @@ class CC_EXPORT CheckerImageTracker {
SkFilterQuality filter_quality = kNone_SkFilterQuality;
SkSize scale = SkSize::MakeEmpty();
gfx::ColorSpace color_space;
+ size_t frame_index = PaintImage::kDefaultFrameIndex;
};
// Wrapper to unlock an image decode requested from the ImageController on
diff --git a/chromium/cc/tiles/checker_image_tracker_unittest.cc b/chromium/cc/tiles/checker_image_tracker_unittest.cc
index ef0fcdddafe..9872893575d 100644
--- a/chromium/cc/tiles/checker_image_tracker_unittest.cc
+++ b/chromium/cc/tiles/checker_image_tracker_unittest.cc
@@ -113,7 +113,7 @@ class CheckerImageTrackerTest : public testing::Test,
}
auto generator = CreatePaintImageGenerator(gfx::Size(dimension, dimension));
- return DrawImage(PaintImageBuilder()
+ return DrawImage(PaintImageBuilder::WithDefault()
.set_id(PaintImage::GetNextId())
.set_paint_image_generator(std::move(generator))
.set_animation_type(animation)
@@ -121,13 +121,12 @@ class CheckerImageTrackerTest : public testing::Test,
.set_is_multipart(is_multipart)
.TakePaintImage(),
SkIRect::MakeWH(dimension, dimension),
- kNone_SkFilterQuality, SkMatrix::I(), gfx::ColorSpace());
+ kNone_SkFilterQuality, SkMatrix::I(),
+ PaintImage::kDefaultFrameIndex, gfx::ColorSpace());
}
bool ShouldCheckerImage(const DrawImage& draw_image, WhichTree tree) {
- bool required_for_activation = true;
- return checker_image_tracker_->ShouldCheckerImage(draw_image, tree,
- required_for_activation);
+ return checker_image_tracker_->ShouldCheckerImage(draw_image, tree);
}
CheckerImageTracker::ImageDecodeQueue BuildImageDecodeQueue(
@@ -428,12 +427,13 @@ TEST_F(CheckerImageTrackerTest, CheckersOnlyStaticCompletedImages) {
gfx::Size image_size = gfx::Size(partial_image.paint_image().width(),
partial_image.paint_image().height());
DrawImage completed_paint_image = DrawImage(
- PaintImageBuilder()
+ PaintImageBuilder::WithDefault()
.set_id(partial_image.paint_image().stable_id())
.set_paint_image_generator(CreatePaintImageGenerator(image_size))
.TakePaintImage(),
SkIRect::MakeWH(image_size.width(), image_size.height()),
- kNone_SkFilterQuality, SkMatrix::I(), gfx::ColorSpace());
+ kNone_SkFilterQuality, SkMatrix::I(), PaintImage::kDefaultFrameIndex,
+ gfx::ColorSpace());
EXPECT_FALSE(
ShouldCheckerImage(completed_paint_image, WhichTree::PENDING_TREE));
}
@@ -460,10 +460,12 @@ TEST_F(CheckerImageTrackerTest, ChoosesMaxScaleAndQuality) {
SetUpTracker(true);
DrawImage image = CreateImage(ImageType::CHECKERABLE);
- DrawImage scaled_image1(image, 0.5f, gfx::ColorSpace());
+ DrawImage scaled_image1(image, 0.5f, PaintImage::kDefaultFrameIndex,
+ gfx::ColorSpace());
DrawImage scaled_image2 =
DrawImage(image.paint_image(), image.src_rect(), kHigh_SkFilterQuality,
- SkMatrix::MakeScale(1.8f), gfx::ColorSpace());
+ SkMatrix::MakeScale(1.8f), PaintImage::kDefaultFrameIndex,
+ gfx::ColorSpace());
std::vector<DrawImage> draw_images = {scaled_image1, scaled_image2};
CheckerImageTracker::ImageDecodeQueue image_decode_queue =
@@ -538,7 +540,7 @@ TEST_F(CheckerImageTrackerTest, UseSrcRectForSize) {
DrawImage image = CreateImage(ImageType::CHECKERABLE);
image = DrawImage(image.paint_image(), SkIRect::MakeWH(200, 200),
image.filter_quality(), SkMatrix::I(),
- image.target_color_space());
+ PaintImage::kDefaultFrameIndex, image.target_color_space());
EXPECT_FALSE(ShouldCheckerImage(image, WhichTree::PENDING_TREE));
}
@@ -560,26 +562,5 @@ TEST_F(CheckerImageTrackerTest, DisableForSoftwareRaster) {
EXPECT_FALSE(ShouldCheckerImage(image2, WhichTree::PENDING_TREE));
}
-TEST_F(CheckerImageTrackerTest, OnlyCheckerRequiredForActivation) {
- SetUpTracker(true);
-
- // Should checker when required for activation.
- DrawImage image1 = CreateImage(ImageType::CHECKERABLE);
- bool required_for_activation = true;
- EXPECT_TRUE(checker_image_tracker_->ShouldCheckerImage(
- image1, WhichTree::PENDING_TREE, required_for_activation));
-
- // Now the same image is not required for activation. We should still continue
- // checkering it.
- required_for_activation = false;
- EXPECT_TRUE(checker_image_tracker_->ShouldCheckerImage(
- image1, WhichTree::PENDING_TREE, required_for_activation));
-
- // New image should not be checkered if it is not required for activation.
- DrawImage image2 = CreateImage(ImageType::CHECKERABLE);
- EXPECT_FALSE(checker_image_tracker_->ShouldCheckerImage(
- image2, WhichTree::PENDING_TREE, required_for_activation));
-}
-
} // namespace
} // namespace cc
diff --git a/chromium/cc/tiles/decoded_image_tracker.cc b/chromium/cc/tiles/decoded_image_tracker.cc
index 00cf27ae598..ebe3cc0b4cb 100644
--- a/chromium/cc/tiles/decoded_image_tracker.cc
+++ b/chromium/cc/tiles/decoded_image_tracker.cc
@@ -29,10 +29,8 @@ void DecodedImageTracker::QueueImageDecode(
gfx::ColorSpace target_color_space;
auto image_bounds = SkIRect::MakeWH(image.width(), image.height());
- // TODO(khushalsagar): Eliminate the use of an incorrect id here and have all
- // call-sites provide PaintImage to the ImageController.
DrawImage draw_image(image, image_bounds, kNone_SkFilterQuality,
- SkMatrix::I(), target_color_space);
+ SkMatrix::I(), image.frame_index(), target_color_space);
image_controller_->QueueImageDecode(
draw_image, base::Bind(&DecodedImageTracker::ImageDecodeFinished,
base::Unretained(this), callback));
diff --git a/chromium/cc/tiles/gpu_image_decode_cache.cc b/chromium/cc/tiles/gpu_image_decode_cache.cc
index 168c6344191..47aa4261f6a 100644
--- a/chromium/cc/tiles/gpu_image_decode_cache.cc
+++ b/chromium/cc/tiles/gpu_image_decode_cache.cc
@@ -121,7 +121,8 @@ gfx::Size CalculateSizeForMipLevel(const DrawImage& draw_image, int mip_level) {
// if not, decodes to a compatible temporary pixmap and then converts that into
// the |target_pixmap|.
bool DrawAndScaleImage(const DrawImage& draw_image, SkPixmap* target_pixmap) {
- const SkImage* image = draw_image.paint_image().GetSkImage().get();
+ sk_sp<SkImage> image =
+ draw_image.paint_image().GetSkImageForFrame(draw_image.frame_index());
if (image->dimensions() == target_pixmap->bounds().size() ||
target_pixmap->info().colorType() == kN32_SkColorType) {
// If no scaling is occurring, or if the target colortype is already N32,
@@ -210,7 +211,7 @@ class ImageDecodeTaskImpl : public TileTask {
TRACE_EVENT2("cc", "ImageDecodeTaskImpl::RunOnWorkerThread", "mode", "gpu",
"source_prepare_tiles_id", tracing_info_.prepare_tiles_id);
devtools_instrumentation::ScopedImageDecodeTask image_decode_task(
- image_.paint_image().GetSkImage().get(),
+ &image_.paint_image(),
devtools_instrumentation::ScopedImageDecodeTask::kGpu,
ImageDecodeCache::ToScopedTaskType(tracing_info_.task_type));
cache_->DecodeImage(image_, tracing_info_.task_type);
@@ -442,33 +443,30 @@ GpuImageDecodeCache::~GpuImageDecodeCache() {
base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this);
}
-bool GpuImageDecodeCache::GetTaskForImageAndRef(const DrawImage& draw_image,
- const TracingInfo& tracing_info,
- scoped_refptr<TileTask>* task) {
+ImageDecodeCache::TaskResult GpuImageDecodeCache::GetTaskForImageAndRef(
+ const DrawImage& draw_image,
+ const TracingInfo& tracing_info) {
DCHECK_EQ(tracing_info.task_type, TaskType::kInRaster);
- return GetTaskForImageAndRefInternal(
- draw_image, tracing_info, DecodeTaskType::PART_OF_UPLOAD_TASK, task);
+ return GetTaskForImageAndRefInternal(draw_image, tracing_info,
+ DecodeTaskType::PART_OF_UPLOAD_TASK);
}
-bool GpuImageDecodeCache::GetOutOfRasterDecodeTaskForImageAndRef(
- const DrawImage& draw_image,
- scoped_refptr<TileTask>* task) {
+ImageDecodeCache::TaskResult
+GpuImageDecodeCache::GetOutOfRasterDecodeTaskForImageAndRef(
+ const DrawImage& draw_image) {
return GetTaskForImageAndRefInternal(
draw_image, TracingInfo(0, TilePriority::NOW, TaskType::kOutOfRaster),
- DecodeTaskType::STAND_ALONE_DECODE_TASK, task);
+ DecodeTaskType::STAND_ALONE_DECODE_TASK);
}
-bool GpuImageDecodeCache::GetTaskForImageAndRefInternal(
+ImageDecodeCache::TaskResult GpuImageDecodeCache::GetTaskForImageAndRefInternal(
const DrawImage& draw_image,
const TracingInfo& tracing_info,
- DecodeTaskType task_type,
- scoped_refptr<TileTask>* task) {
+ DecodeTaskType task_type) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
"GpuImageDecodeCache::GetTaskForImageAndRef");
- if (SkipImage(draw_image)) {
- *task = nullptr;
- return false;
- }
+ if (SkipImage(draw_image))
+ return TaskResult(false);
base::AutoLock lock(lock_);
const PaintImage::FrameKey frame_key = draw_image.frame_key();
@@ -480,36 +478,30 @@ bool GpuImageDecodeCache::GetTaskForImageAndRefInternal(
image_data = new_data.get();
} else if (image_data->is_at_raster) {
// Image is at-raster, just return, this usage will be at-raster as well.
- *task = nullptr;
- return false;
+ return TaskResult(false);
} else if (image_data->decode.decode_failure) {
// We have already tried and failed to decode this image, so just return.
- *task = nullptr;
- return false;
+ return TaskResult(false);
} else if (image_data->upload.image()) {
// The image is already uploaded, ref and return.
RefImage(draw_image);
- *task = nullptr;
- return true;
+ return TaskResult(true);
} else if (task_type == DecodeTaskType::PART_OF_UPLOAD_TASK &&
image_data->upload.task) {
// We had an existing upload task, ref the image and return the task.
RefImage(draw_image);
- *task = image_data->upload.task;
- return true;
+ return TaskResult(image_data->upload.task);
} else if (task_type == DecodeTaskType::STAND_ALONE_DECODE_TASK &&
image_data->decode.stand_alone_task) {
// We had an existing out of raster task, ref the image and return the task.
RefImage(draw_image);
- *task = image_data->decode.stand_alone_task;
- return true;
+ return TaskResult(image_data->decode.stand_alone_task);
}
// Ensure that the image we're about to decode/upload will fit in memory.
if (!EnsureCapacity(image_data->size)) {
// Image will not fit, do an at-raster decode.
- *task = nullptr;
- return false;
+ return TaskResult(false);
}
// If we had to create new image data, add it to our map now that we know it
@@ -521,20 +513,21 @@ bool GpuImageDecodeCache::GetTaskForImageAndRefInternal(
// it is their responsibility to release it by calling UnrefImage.
RefImage(draw_image);
+ scoped_refptr<TileTask> task;
if (task_type == DecodeTaskType::PART_OF_UPLOAD_TASK) {
// Ref image and create a upload and decode tasks. We will release this ref
// in UploadTaskCompleted.
RefImage(draw_image);
- *task = make_scoped_refptr(new ImageUploadTaskImpl(
+ task = base::MakeRefCounted<ImageUploadTaskImpl>(
this, draw_image,
GetImageDecodeTaskAndRef(draw_image, tracing_info, task_type),
- tracing_info));
- image_data->upload.task = *task;
+ tracing_info);
+ image_data->upload.task = task;
} else {
- *task = GetImageDecodeTaskAndRef(draw_image, tracing_info, task_type);
+ task = GetImageDecodeTaskAndRef(draw_image, tracing_info, task_type);
}
- return true;
+ return TaskResult(task);
}
void GpuImageDecodeCache::UnrefImage(const DrawImage& draw_image) {
@@ -858,8 +851,8 @@ scoped_refptr<TileTask> GpuImageDecodeCache::GetImageDecodeTaskAndRef(
// Ref image decode and create a decode task. This ref will be released in
// DecodeTaskCompleted.
RefImageDecode(draw_image);
- existing_task = make_scoped_refptr(
- new ImageDecodeTaskImpl(this, draw_image, tracing_info, task_type));
+ existing_task = base::MakeRefCounted<ImageDecodeTaskImpl>(
+ this, draw_image, tracing_info, task_type);
}
return existing_task;
}
@@ -1186,7 +1179,8 @@ void GpuImageDecodeCache::DecodeImageIfNecessary(const DrawImage& draw_image,
// TODO(crbug.com/649167): Params should not have changed since initial
// sizing. Somehow this still happens. We should investigate and re-add
// DCHECKs here to enforce this.
- SkImage* image = draw_image.paint_image().GetSkImage().get();
+ sk_sp<SkImage> image = draw_image.paint_image().GetSkImageForFrame(
+ draw_image.frame_index());
if (!image->getDeferredTextureImageData(
*context_threadsafe_proxy_.get(), &image_data->upload_params, 1,
backing_memory->data(), nullptr, color_type_)) {
@@ -1291,7 +1285,8 @@ GpuImageDecodeCache::CreateImageData(const DrawImage& draw_image) {
auto params = SkImage::DeferredTextureImageUsageParams(
SkMatrix::I(), CalculateDesiredFilterQuality(draw_image),
upload_scale_mip_level);
- SkImage* image = draw_image.paint_image().GetSkImage().get();
+ sk_sp<SkImage> image =
+ draw_image.paint_image().GetSkImageForFrame(draw_image.frame_index());
size_t data_size = image->getDeferredTextureImageData(
*context_threadsafe_proxy_.get(), &params, 1, nullptr, nullptr,
color_type_);
@@ -1300,14 +1295,14 @@ GpuImageDecodeCache::CreateImageData(const DrawImage& draw_image) {
// Can't upload image, too large or other failure. Try to use SW fallback.
SkImageInfo image_info =
CreateImageInfoForDrawImage(draw_image, upload_scale_mip_level);
- data_size = image_info.getSafeSize(image_info.minRowBytes());
+ data_size = image_info.computeMinByteSize();
mode = DecodedDataMode::CPU;
} else {
mode = DecodedDataMode::GPU;
}
- return make_scoped_refptr(
- new ImageData(mode, data_size, draw_image.target_color_space(), params));
+ return base::MakeRefCounted<ImageData>(
+ mode, data_size, draw_image.target_color_space(), params);
}
void GpuImageDecodeCache::DeletePendingImages() {
diff --git a/chromium/cc/tiles/gpu_image_decode_cache.h b/chromium/cc/tiles/gpu_image_decode_cache.h
index 4a845833f01..502d5c273f7 100644
--- a/chromium/cc/tiles/gpu_image_decode_cache.h
+++ b/chromium/cc/tiles/gpu_image_decode_cache.h
@@ -112,12 +112,10 @@ class CC_EXPORT GpuImageDecodeCache
// Finds the existing uploaded image for the provided DrawImage. Creates an
// upload task to upload the image if an exsiting image does not exist.
- bool GetTaskForImageAndRef(const DrawImage& image,
- const TracingInfo& tracing_info,
- scoped_refptr<TileTask>* task) override;
- bool GetOutOfRasterDecodeTaskForImageAndRef(
- const DrawImage& image,
- scoped_refptr<TileTask>* task) override;
+ TaskResult GetTaskForImageAndRef(const DrawImage& image,
+ const TracingInfo& tracing_info) override;
+ TaskResult GetOutOfRasterDecodeTaskForImageAndRef(
+ const DrawImage& image) override;
void UnrefImage(const DrawImage& image) override;
DecodedDrawImage GetDecodedImageForDraw(const DrawImage& draw_image) override;
void DrawWithImageFinished(const DrawImage& image,
@@ -304,10 +302,9 @@ class CC_EXPORT GpuImageDecodeCache
// Note that this function behaves as if it was public (all of the same locks
// need to be acquired).
- bool GetTaskForImageAndRefInternal(const DrawImage& image,
- const TracingInfo& tracing_info,
- DecodeTaskType task_type,
- scoped_refptr<TileTask>* task);
+ TaskResult GetTaskForImageAndRefInternal(const DrawImage& image,
+ const TracingInfo& tracing_info,
+ DecodeTaskType task_type);
void RefImageDecode(const DrawImage& draw_image);
void UnrefImageDecode(const DrawImage& draw_image);
diff --git a/chromium/cc/tiles/gpu_image_decode_cache_unittest.cc b/chromium/cc/tiles/gpu_image_decode_cache_unittest.cc
index e8ad3457833..dc2d245fff8 100644
--- a/chromium/cc/tiles/gpu_image_decode_cache_unittest.cc
+++ b/chromium/cc/tiles/gpu_image_decode_cache_unittest.cc
@@ -6,6 +6,7 @@
#include "cc/paint/draw_image.h"
#include "cc/paint/paint_image_builder.h"
+#include "cc/test/fake_paint_image_generator.h"
#include "cc/test/skia_common.h"
#include "cc/test/test_context_provider.h"
#include "cc/test/test_tile_task_runner.h"
@@ -56,25 +57,23 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageSameImage) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
DrawImage another_draw_image(
image, SkIRect::MakeWH(image.width(), image.height()), quality,
CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> another_task;
- need_unref = cache.GetTaskForImageAndRef(
- another_draw_image, ImageDecodeCache::TracingInfo(), &another_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task.get() == another_task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult another_result = cache.GetTaskForImageAndRef(
+ another_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(another_result.need_unref);
+ EXPECT_TRUE(result.task.get() == another_result.task.get());
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.UnrefImage(draw_image);
cache.UnrefImage(draw_image);
@@ -91,25 +90,23 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageSmallerScale) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
DrawImage another_draw_image(
image, SkIRect::MakeWH(image.width(), image.height()), quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> another_task;
- need_unref = cache.GetTaskForImageAndRef(
- another_draw_image, ImageDecodeCache::TracingInfo(), &another_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task.get() == another_task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult another_result = cache.GetTaskForImageAndRef(
+ another_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(another_result.need_unref);
+ EXPECT_TRUE(result.task.get() == another_result.task.get());
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.UnrefImage(draw_image);
cache.UnrefImage(another_draw_image);
@@ -124,24 +121,24 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageLowerQuality) {
SkMatrix matrix = CreateMatrix(SkSize::Make(0.4f, 0.4f), is_decomposable);
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
- kHigh_SkFilterQuality, matrix, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ kHigh_SkFilterQuality, matrix,
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
DrawImage another_draw_image(
image, SkIRect::MakeWH(image.width(), image.height()),
- kLow_SkFilterQuality, matrix, DefaultColorSpace());
- scoped_refptr<TileTask> another_task;
- need_unref = cache.GetTaskForImageAndRef(
- another_draw_image, ImageDecodeCache::TracingInfo(), &another_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task.get() == another_task.get());
+ kLow_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex,
+ DefaultColorSpace());
+ ImageDecodeCache::TaskResult another_result = cache.GetTaskForImageAndRef(
+ another_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(another_result.need_unref);
+ EXPECT_TRUE(result.task.get() == another_result.task.get());
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.UnrefImage(draw_image);
cache.UnrefImage(another_draw_image);
@@ -158,30 +155,28 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageDifferentImage) {
DrawImage first_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> first_task;
- bool need_unref = cache.GetTaskForImageAndRef(
- first_draw_image, ImageDecodeCache::TracingInfo(), &first_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(first_task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef(
+ first_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(first_result.need_unref);
+ EXPECT_TRUE(first_result.task);
PaintImage second_image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage second_draw_image(
second_image,
SkIRect::MakeWH(second_image.width(), second_image.height()), quality,
CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> second_task;
- need_unref = cache.GetTaskForImageAndRef(
- second_draw_image, ImageDecodeCache::TracingInfo(), &second_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(second_task);
- EXPECT_TRUE(first_task.get() != second_task.get());
-
- TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(first_task.get());
- TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(second_task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef(
+ second_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(second_result.need_unref);
+ EXPECT_TRUE(second_result.task);
+ EXPECT_TRUE(first_result.task.get() != second_result.task.get());
+
+ TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(first_result.task.get());
+ TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(second_result.task.get());
cache.UnrefImage(first_draw_image);
cache.UnrefImage(second_draw_image);
@@ -198,41 +193,38 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageLargerScale) {
DrawImage first_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> first_task;
- bool need_unref = cache.GetTaskForImageAndRef(
- first_draw_image, ImageDecodeCache::TracingInfo(), &first_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(first_task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef(
+ first_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(first_result.need_unref);
+ EXPECT_TRUE(first_result.task);
- TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(first_task.get());
+ TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(first_result.task.get());
cache.UnrefImage(first_draw_image);
DrawImage second_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> second_task;
- need_unref = cache.GetTaskForImageAndRef(
- second_draw_image, ImageDecodeCache::TracingInfo(), &second_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(second_task);
- EXPECT_TRUE(first_task.get() != second_task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef(
+ second_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(second_result.need_unref);
+ EXPECT_TRUE(second_result.task);
+ EXPECT_TRUE(first_result.task.get() != second_result.task.get());
DrawImage third_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> third_task;
- need_unref = cache.GetTaskForImageAndRef(
- third_draw_image, ImageDecodeCache::TracingInfo(), &third_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(third_task.get() == second_task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult third_result = cache.GetTaskForImageAndRef(
+ third_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(third_result.need_unref);
+ EXPECT_TRUE(third_result.task.get() == second_result.task.get());
- TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(second_task.get());
+ TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(second_result.task.get());
cache.UnrefImage(second_draw_image);
cache.UnrefImage(third_draw_image);
@@ -249,38 +241,35 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageLargerScaleNoReuse) {
DrawImage first_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> first_task;
- bool need_unref = cache.GetTaskForImageAndRef(
- first_draw_image, ImageDecodeCache::TracingInfo(), &first_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(first_task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef(
+ first_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(first_result.need_unref);
+ EXPECT_TRUE(first_result.task);
DrawImage second_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> second_task;
- need_unref = cache.GetTaskForImageAndRef(
- second_draw_image, ImageDecodeCache::TracingInfo(), &second_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(second_task);
- EXPECT_TRUE(first_task.get() != second_task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef(
+ second_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(second_result.need_unref);
+ EXPECT_TRUE(second_result.task);
+ EXPECT_TRUE(first_result.task.get() != second_result.task.get());
DrawImage third_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> third_task;
- need_unref = cache.GetTaskForImageAndRef(
- third_draw_image, ImageDecodeCache::TracingInfo(), &third_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(third_task.get() == first_task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult third_result = cache.GetTaskForImageAndRef(
+ third_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(third_result.need_unref);
+ EXPECT_TRUE(third_result.task.get() == first_result.task.get());
- TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(first_task.get());
- TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(second_task.get());
+ TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(first_result.task.get());
+ TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(second_result.task.get());
cache.UnrefImage(first_draw_image);
cache.UnrefImage(second_draw_image);
@@ -297,30 +286,30 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageHigherQuality) {
PaintImage first_image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage first_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
- kLow_SkFilterQuality, matrix, DefaultColorSpace());
- scoped_refptr<TileTask> first_task;
- bool need_unref = cache.GetTaskForImageAndRef(
- first_draw_image, ImageDecodeCache::TracingInfo(), &first_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(first_task);
+ kLow_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex,
+ DefaultColorSpace());
+ ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef(
+ first_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(first_result.need_unref);
+ EXPECT_TRUE(first_result.task);
- TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(first_task.get());
+ TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(first_result.task.get());
cache.UnrefImage(first_draw_image);
DrawImage second_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
- kHigh_SkFilterQuality, matrix, DefaultColorSpace());
- scoped_refptr<TileTask> second_task;
- need_unref = cache.GetTaskForImageAndRef(
- second_draw_image, ImageDecodeCache::TracingInfo(), &second_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(second_task);
- EXPECT_TRUE(first_task.get() != second_task.get());
+ kHigh_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex,
+ DefaultColorSpace());
+ ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef(
+ second_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(second_result.need_unref);
+ EXPECT_TRUE(second_result.task);
+ EXPECT_TRUE(first_result.task.get() != second_result.task.get());
- TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(second_task.get());
+ TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(second_result.task.get());
cache.UnrefImage(second_draw_image);
}
@@ -336,36 +325,34 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageAlreadyDecodedAndLocked) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
- EXPECT_EQ(task->dependencies().size(), 1u);
- EXPECT_TRUE(task->dependencies()[0]);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+ EXPECT_EQ(result.task->dependencies().size(), 1u);
+ EXPECT_TRUE(result.task->dependencies()[0]);
// Run the decode but don't complete it (this will keep the decode locked).
- TestTileTaskRunner::ScheduleTask(task->dependencies()[0].get());
- TestTileTaskRunner::RunTask(task->dependencies()[0].get());
+ TestTileTaskRunner::ScheduleTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::RunTask(result.task->dependencies()[0].get());
// Cancel the upload.
- TestTileTaskRunner::CancelTask(task.get());
- TestTileTaskRunner::CompleteTask(task.get());
+ TestTileTaskRunner::CancelTask(result.task.get());
+ TestTileTaskRunner::CompleteTask(result.task.get());
// Get the image again - we should have an upload task, but no dependent
// decode task, as the decode was already locked.
- scoped_refptr<TileTask> another_task;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &another_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(another_task);
- EXPECT_EQ(another_task->dependencies().size(), 0u);
+ ImageDecodeCache::TaskResult another_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(another_result.need_unref);
+ EXPECT_TRUE(another_result.task);
+ EXPECT_EQ(another_result.task->dependencies().size(), 0u);
- TestTileTaskRunner::ProcessTask(another_task.get());
+ TestTileTaskRunner::ProcessTask(another_result.task.get());
// Finally, complete the original decode task.
- TestTileTaskRunner::CompleteTask(task->dependencies()[0].get());
+ TestTileTaskRunner::CompleteTask(result.task->dependencies()[0].get());
cache.UnrefImage(draw_image);
cache.UnrefImage(draw_image);
@@ -382,37 +369,35 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageAlreadyDecodedNotLocked) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
- EXPECT_EQ(task->dependencies().size(), 1u);
- EXPECT_TRUE(task->dependencies()[0]);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+ EXPECT_EQ(result.task->dependencies().size(), 1u);
+ EXPECT_TRUE(result.task->dependencies()[0]);
// Run the decode.
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
// Cancel the upload.
- TestTileTaskRunner::CancelTask(task.get());
- TestTileTaskRunner::CompleteTask(task.get());
+ TestTileTaskRunner::CancelTask(result.task.get());
+ TestTileTaskRunner::CompleteTask(result.task.get());
// Unref the image.
cache.UnrefImage(draw_image);
// Get the image again - we should have an upload task and a dependent decode
// task - this dependent task will typically just re-lock the image.
- scoped_refptr<TileTask> another_task;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &another_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(another_task);
- EXPECT_EQ(another_task->dependencies().size(), 1u);
- EXPECT_TRUE(task->dependencies()[0]);
+ ImageDecodeCache::TaskResult another_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(another_result.need_unref);
+ EXPECT_TRUE(another_result.task);
+ EXPECT_EQ(another_result.task->dependencies().size(), 1u);
+ EXPECT_TRUE(result.task->dependencies()[0]);
- TestTileTaskRunner::ProcessTask(another_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(another_task.get());
+ TestTileTaskRunner::ProcessTask(another_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(another_result.task.get());
cache.UnrefImage(draw_image);
}
@@ -428,26 +413,24 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageAlreadyUploaded) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
- EXPECT_EQ(task->dependencies().size(), 1u);
- EXPECT_TRUE(task->dependencies()[0]);
-
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ScheduleTask(task.get());
- TestTileTaskRunner::RunTask(task.get());
-
- scoped_refptr<TileTask> another_task;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &another_task);
- EXPECT_TRUE(need_unref);
- EXPECT_FALSE(another_task);
-
- TestTileTaskRunner::CompleteTask(task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+ EXPECT_EQ(result.task->dependencies().size(), 1u);
+ EXPECT_TRUE(result.task->dependencies()[0]);
+
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ScheduleTask(result.task.get());
+ TestTileTaskRunner::RunTask(result.task.get());
+
+ ImageDecodeCache::TaskResult another_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(another_result.need_unref);
+ EXPECT_FALSE(another_result.task);
+
+ TestTileTaskRunner::CompleteTask(result.task.get());
cache.UnrefImage(draw_image);
cache.UnrefImage(draw_image);
@@ -464,39 +447,36 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageCanceledGetsNewTask) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
- scoped_refptr<TileTask> another_task;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &another_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(another_task.get() == task.get());
+ ImageDecodeCache::TaskResult another_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(another_result.task.get() == result.task.get());
// Didn't run the task, so cancel it.
- TestTileTaskRunner::CancelTask(task.get());
- TestTileTaskRunner::CompleteTask(task.get());
+ TestTileTaskRunner::CancelTask(result.task.get());
+ TestTileTaskRunner::CompleteTask(result.task.get());
// Fully cancel everything (so the raster would unref things).
cache.UnrefImage(draw_image);
cache.UnrefImage(draw_image);
// Here a new task is created.
- scoped_refptr<TileTask> third_task;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &third_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(third_task);
- EXPECT_FALSE(third_task.get() == task.get());
+ ImageDecodeCache::TaskResult third_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(third_result.need_unref);
+ EXPECT_TRUE(third_result.task);
+ EXPECT_FALSE(third_result.task.get() == result.task.get());
- TestTileTaskRunner::ProcessTask(third_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(third_task.get());
+ TestTileTaskRunner::ProcessTask(third_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(third_result.task.get());
cache.UnrefImage(draw_image);
}
@@ -512,25 +492,23 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageCanceledWhileReffedGetsNewTask) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
-
- ASSERT_GT(task->dependencies().size(), 0u);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
-
- scoped_refptr<TileTask> another_task;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &another_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(another_task.get() == task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+
+ ASSERT_GT(result.task->dependencies().size(), 0u);
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+
+ ImageDecodeCache::TaskResult another_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(another_result.need_unref);
+ EXPECT_TRUE(another_result.task.get() == result.task.get());
// Didn't run the task, so cancel it.
- TestTileTaskRunner::CancelTask(task.get());
- TestTileTaskRunner::CompleteTask(task.get());
+ TestTileTaskRunner::CancelTask(result.task.get());
+ TestTileTaskRunner::CompleteTask(result.task.get());
// 2 Unrefs, so that the decode is unlocked as well.
cache.UnrefImage(draw_image);
@@ -538,16 +516,15 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageCanceledWhileReffedGetsNewTask) {
// Note that here, everything is reffed, but a new task is created. This is
// possible with repeated schedule/cancel operations.
- scoped_refptr<TileTask> third_task;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &third_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(third_task);
- EXPECT_FALSE(third_task.get() == task.get());
+ ImageDecodeCache::TaskResult third_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(third_result.need_unref);
+ EXPECT_TRUE(third_result.task);
+ EXPECT_FALSE(third_result.task.get() == result.task.get());
- ASSERT_GT(third_task->dependencies().size(), 0u);
- TestTileTaskRunner::ProcessTask(third_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(third_task.get());
+ ASSERT_GT(third_result.task->dependencies().size(), 0u);
+ TestTileTaskRunner::ProcessTask(third_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(third_result.task.get());
// Unref!
cache.UnrefImage(draw_image);
@@ -564,25 +541,23 @@ TEST_P(GpuImageDecodeCacheTest, NoTaskForImageAlreadyFailedDecoding) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
-
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
// Didn't run the task, so cancel it.
- TestTileTaskRunner::CancelTask(task.get());
- TestTileTaskRunner::CompleteTask(task.get());
+ TestTileTaskRunner::CancelTask(result.task.get());
+ TestTileTaskRunner::CompleteTask(result.task.get());
cache.SetImageDecodingFailedForTesting(draw_image);
- scoped_refptr<TileTask> another_task;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &another_task);
- EXPECT_FALSE(need_unref);
- EXPECT_EQ(another_task.get(), nullptr);
+ ImageDecodeCache::TaskResult another_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_FALSE(another_result.need_unref);
+ EXPECT_EQ(another_result.task.get(), nullptr);
cache.UnrefImage(draw_image);
}
@@ -598,15 +573,14 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDraw) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -634,15 +608,14 @@ TEST_P(GpuImageDecodeCacheTest, GetLargeDecodedImageForDraw) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -673,13 +646,12 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawAtRasterDecode) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_FALSE(need_unref);
- EXPECT_FALSE(task);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_FALSE(result.need_unref);
+ EXPECT_FALSE(result.task);
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -706,28 +678,26 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawLargerScale) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
kLow_SkFilterQuality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DrawImage larger_draw_image(
image, SkIRect::MakeWH(image.width(), image.height()), quality,
CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> larger_task;
- bool larger_need_unref = cache.GetTaskForImageAndRef(
- larger_draw_image, ImageDecodeCache::TracingInfo(), &larger_task);
- EXPECT_TRUE(larger_need_unref);
- EXPECT_TRUE(larger_task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult larger_result = cache.GetTaskForImageAndRef(
+ larger_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(larger_result.need_unref);
+ EXPECT_TRUE(larger_result.task);
- TestTileTaskRunner::ProcessTask(larger_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(larger_task.get());
+ TestTileTaskRunner::ProcessTask(larger_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(larger_result.task.get());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -767,27 +737,27 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawHigherQuality) {
PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
- kLow_SkFilterQuality, matrix, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ kLow_SkFilterQuality, matrix,
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DrawImage higher_quality_draw_image(
image, SkIRect::MakeWH(image.width(), image.height()),
- kHigh_SkFilterQuality, matrix, DefaultColorSpace());
- scoped_refptr<TileTask> hq_task;
- bool hq_needs_unref = cache.GetTaskForImageAndRef(
- higher_quality_draw_image, ImageDecodeCache::TracingInfo(), &hq_task);
- EXPECT_TRUE(hq_needs_unref);
- EXPECT_TRUE(hq_task);
+ kHigh_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex,
+ DefaultColorSpace());
+ ImageDecodeCache::TaskResult hq_result = cache.GetTaskForImageAndRef(
+ higher_quality_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(hq_result.need_unref);
+ EXPECT_TRUE(hq_result.task);
- TestTileTaskRunner::ProcessTask(hq_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(hq_task.get());
+ TestTileTaskRunner::ProcessTask(hq_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(hq_result.task.get());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -829,15 +799,14 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawNegative) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(-0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -867,15 +836,14 @@ TEST_P(GpuImageDecodeCacheTest, GetLargeScaledDecodedImageForDraw) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -909,13 +877,12 @@ TEST_P(GpuImageDecodeCacheTest, AtRasterUsedDirectlyIfSpaceAllows) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_FALSE(need_unref);
- EXPECT_FALSE(task);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_FALSE(result.need_unref);
+ EXPECT_FALSE(result.task);
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -934,11 +901,10 @@ TEST_P(GpuImageDecodeCacheTest, AtRasterUsedDirectlyIfSpaceAllows) {
// cache.
cache.DrawWithImageFinished(draw_image, decoded_draw_image);
- scoped_refptr<TileTask> another_task;
- bool another_task_needs_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(another_task_needs_unref);
- EXPECT_FALSE(another_task);
+ ImageDecodeCache::TaskResult another_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(another_result.need_unref);
+ EXPECT_FALSE(another_result.task);
cache.UnrefImage(draw_image);
}
@@ -956,7 +922,7 @@ TEST_P(GpuImageDecodeCacheTest,
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -990,7 +956,7 @@ TEST_P(GpuImageDecodeCacheTest,
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -1030,13 +996,12 @@ TEST_P(GpuImageDecodeCacheTest, ZeroSizedImagesAreSkipped) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.f, 0.f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_FALSE(task);
- EXPECT_FALSE(need_unref);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_FALSE(result.task);
+ EXPECT_FALSE(result.need_unref);
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -1059,13 +1024,12 @@ TEST_P(GpuImageDecodeCacheTest, NonOverlappingSrcRectImagesAreSkipped) {
DrawImage draw_image(
image, SkIRect::MakeXYWH(150, 150, image.width(), image.height()),
quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_FALSE(task);
- EXPECT_FALSE(need_unref);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_FALSE(result.task);
+ EXPECT_FALSE(result.need_unref);
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -1088,19 +1052,18 @@ TEST_P(GpuImageDecodeCacheTest, CanceledTasksDoNotCountAgainstBudget) {
DrawImage draw_image(
image, SkIRect::MakeXYWH(0, 0, image.width(), image.height()), quality,
CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
EXPECT_NE(0u, cache.GetBytesUsedForTesting());
- EXPECT_TRUE(task);
- EXPECT_TRUE(need_unref);
+ EXPECT_TRUE(result.task);
+ EXPECT_TRUE(result.need_unref);
- TestTileTaskRunner::CancelTask(task->dependencies()[0].get());
- TestTileTaskRunner::CompleteTask(task->dependencies()[0].get());
- TestTileTaskRunner::CancelTask(task.get());
- TestTileTaskRunner::CompleteTask(task.get());
+ TestTileTaskRunner::CancelTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::CompleteTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::CancelTask(result.task.get());
+ TestTileTaskRunner::CompleteTask(result.task.get());
cache.UnrefImage(draw_image);
EXPECT_EQ(0u, cache.GetBytesUsedForTesting());
@@ -1117,37 +1080,36 @@ TEST_P(GpuImageDecodeCacheTest, ShouldAggressivelyFreeResources) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
{
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
- }
+ ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(
+ draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
- cache.UnrefImage(draw_image);
+ cache.UnrefImage(draw_image);
- // We should now have data image in our cache.
- EXPECT_GT(cache.GetBytesUsedForTesting(), 0u);
+ // We should now have data image in our cache.
+ EXPECT_GT(cache.GetBytesUsedForTesting(), 0u);
- // Tell our cache to aggressively free resources.
- cache.SetShouldAggressivelyFreeResources(true);
- EXPECT_EQ(0u, cache.GetBytesUsedForTesting());
+ // Tell our cache to aggressively free resources.
+ cache.SetShouldAggressivelyFreeResources(true);
+ EXPECT_EQ(0u, cache.GetBytesUsedForTesting());
+ }
// Attempting to upload a new image should succeed, but the image should not
// be cached past its use.
{
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(
+ draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.UnrefImage(draw_image);
EXPECT_EQ(cache.GetBytesUsedForTesting(), 0u);
@@ -1157,13 +1119,13 @@ TEST_P(GpuImageDecodeCacheTest, ShouldAggressivelyFreeResources) {
// now be cached past its use.
cache.SetShouldAggressivelyFreeResources(false);
{
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(
+ draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.UnrefImage(draw_image);
EXPECT_GT(cache.GetBytesUsedForTesting(), 0u);
@@ -1182,12 +1144,11 @@ TEST_P(GpuImageDecodeCacheTest, OrphanedImagesFreeOnReachingZeroRefs) {
DrawImage first_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> first_task;
- bool need_unref = cache.GetTaskForImageAndRef(
- first_draw_image, ImageDecodeCache::TracingInfo(), &first_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(first_task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef(
+ first_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(first_result.need_unref);
+ EXPECT_TRUE(first_result.task);
// The budget should account for exactly one image.
EXPECT_EQ(cache.GetBytesUsedForTesting(),
@@ -1198,16 +1159,15 @@ TEST_P(GpuImageDecodeCacheTest, OrphanedImagesFreeOnReachingZeroRefs) {
DrawImage second_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> second_task;
- need_unref = cache.GetTaskForImageAndRef(
- second_draw_image, ImageDecodeCache::TracingInfo(), &second_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(second_task);
- EXPECT_TRUE(first_task.get() != second_task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef(
+ second_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(second_result.need_unref);
+ EXPECT_TRUE(second_result.task);
+ EXPECT_TRUE(first_result.task.get() != second_result.task.get());
- TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(second_task.get());
+ TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(second_result.task.get());
cache.UnrefImage(second_draw_image);
@@ -1218,8 +1178,8 @@ TEST_P(GpuImageDecodeCacheTest, OrphanedImagesFreeOnReachingZeroRefs) {
// Unref the first image, it was orphaned, so it should be immediately
// deleted.
- TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(first_task.get());
+ TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(first_result.task.get());
cache.UnrefImage(first_draw_image);
// The budget should account for exactly one image.
@@ -1239,15 +1199,14 @@ TEST_P(GpuImageDecodeCacheTest, OrphanedZeroRefImagesImmediatelyDeleted) {
DrawImage first_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> first_task;
- bool need_unref = cache.GetTaskForImageAndRef(
- first_draw_image, ImageDecodeCache::TracingInfo(), &first_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(first_task);
-
- TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(first_task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef(
+ first_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(first_result.need_unref);
+ EXPECT_TRUE(first_result.task);
+
+ TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(first_result.task.get());
cache.UnrefImage(first_draw_image);
// The budget should account for exactly one image.
@@ -1259,16 +1218,15 @@ TEST_P(GpuImageDecodeCacheTest, OrphanedZeroRefImagesImmediatelyDeleted) {
DrawImage second_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> second_task;
- need_unref = cache.GetTaskForImageAndRef(
- second_draw_image, ImageDecodeCache::TracingInfo(), &second_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(second_task);
- EXPECT_TRUE(first_task.get() != second_task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef(
+ second_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(second_result.need_unref);
+ EXPECT_TRUE(second_result.task);
+ EXPECT_TRUE(first_result.task.get() != second_result.task.get());
- TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(second_task.get());
+ TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(second_result.task.get());
cache.UnrefImage(second_draw_image);
@@ -1288,39 +1246,39 @@ TEST_P(GpuImageDecodeCacheTest, QualityCappedAtMedium) {
// Create an image with kLow_FilterQuality.
DrawImage low_draw_image(image,
SkIRect::MakeWH(image.width(), image.height()),
- kLow_SkFilterQuality, matrix, DefaultColorSpace());
- scoped_refptr<TileTask> low_task;
- bool need_unref = cache.GetTaskForImageAndRef(
- low_draw_image, ImageDecodeCache::TracingInfo(), &low_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(low_task);
+ kLow_SkFilterQuality, matrix,
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult low_result = cache.GetTaskForImageAndRef(
+ low_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(low_result.need_unref);
+ EXPECT_TRUE(low_result.task);
// Get the same image at kMedium_SkFilterQuality. We can't re-use low, so we
// should get a new task/ref.
DrawImage medium_draw_image(
image, SkIRect::MakeWH(image.width(), image.height()),
- kMedium_SkFilterQuality, matrix, DefaultColorSpace());
- scoped_refptr<TileTask> medium_task;
- need_unref = cache.GetTaskForImageAndRef(
- medium_draw_image, ImageDecodeCache::TracingInfo(), &medium_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(medium_task.get());
- EXPECT_FALSE(low_task.get() == medium_task.get());
+ kMedium_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex,
+ DefaultColorSpace());
+ ImageDecodeCache::TaskResult medium_result = cache.GetTaskForImageAndRef(
+ medium_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(medium_result.need_unref);
+ EXPECT_TRUE(medium_result.task.get());
+ EXPECT_FALSE(low_result.task.get() == medium_result.task.get());
// Get the same image at kHigh_FilterQuality. We should re-use medium.
DrawImage large_draw_image(
image, SkIRect::MakeWH(image.width(), image.height()),
- kHigh_SkFilterQuality, matrix, DefaultColorSpace());
- scoped_refptr<TileTask> large_task;
- need_unref = cache.GetTaskForImageAndRef(
- large_draw_image, ImageDecodeCache::TracingInfo(), &large_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(medium_task.get() == large_task.get());
-
- TestTileTaskRunner::ProcessTask(low_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(low_task.get());
- TestTileTaskRunner::ProcessTask(medium_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(medium_task.get());
+ kHigh_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex,
+ DefaultColorSpace());
+ ImageDecodeCache::TaskResult large_result = cache.GetTaskForImageAndRef(
+ large_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(large_result.need_unref);
+ EXPECT_TRUE(medium_result.task.get() == large_result.task.get());
+
+ TestTileTaskRunner::ProcessTask(low_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(low_result.task.get());
+ TestTileTaskRunner::ProcessTask(medium_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(medium_result.task.get());
cache.UnrefImage(low_draw_image);
cache.UnrefImage(medium_draw_image);
@@ -1341,18 +1299,17 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawMipUsageChange) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
// Cancel the task without ever using it.
- TestTileTaskRunner::CancelTask(task->dependencies()[0].get());
- TestTileTaskRunner::CompleteTask(task->dependencies()[0].get());
- TestTileTaskRunner::CancelTask(task.get());
- TestTileTaskRunner::CompleteTask(task.get());
+ TestTileTaskRunner::CancelTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::CompleteTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::CancelTask(result.task.get());
+ TestTileTaskRunner::CompleteTask(result.task.get());
cache.UnrefImage(draw_image);
@@ -1364,7 +1321,7 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawMipUsageChange) {
DrawImage draw_image_mips(
image, SkIRect::MakeWH(image.width(), image.height()), quality,
CreateMatrix(SkSize::Make(0.6f, 0.6f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image_mips);
cache.DrawWithImageFinished(draw_image_mips, decoded_draw_image);
@@ -1380,15 +1337,15 @@ TEST_P(GpuImageDecodeCacheTest, MemoryStateSuspended) {
bool is_decomposable = true;
SkMatrix matrix = CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable);
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
- kLow_SkFilterQuality, matrix, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
-
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ kLow_SkFilterQuality, matrix,
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.UnrefImage(draw_image);
// The image should be cached.
@@ -1412,13 +1369,13 @@ TEST_P(GpuImageDecodeCacheTest, MemoryStateSuspended) {
// Attempts to get a task for the image will still succeed, as SUSPENDED
// doesn't impact working set size.
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.UnrefImage(draw_image);
// Nothing should be cached.
@@ -1430,13 +1387,13 @@ TEST_P(GpuImageDecodeCacheTest, MemoryStateSuspended) {
cache.SetShouldAggressivelyFreeResources(false);
// We should now be able to create a task again (space available).
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.UnrefImage(draw_image);
}
@@ -1449,17 +1406,17 @@ TEST_P(GpuImageDecodeCacheTest, OutOfRasterDecodeTask) {
bool is_decomposable = true;
SkMatrix matrix = CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable);
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
- kLow_SkFilterQuality, matrix, DefaultColorSpace());
+ kLow_SkFilterQuality, matrix,
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref =
- cache.GetOutOfRasterDecodeTaskForImageAndRef(draw_image, &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ ImageDecodeCache::TaskResult result =
+ cache.GetOutOfRasterDecodeTaskForImageAndRef(draw_image);
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
EXPECT_TRUE(cache.IsInInUseCacheForTesting(draw_image));
// Run the decode task.
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
// The image should remain in the cache till we unref it.
EXPECT_TRUE(cache.IsInInUseCacheForTesting(draw_image));
@@ -1481,25 +1438,23 @@ TEST_P(GpuImageDecodeCacheTest, ZeroCacheNormalWorkingSet) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
- EXPECT_EQ(task->dependencies().size(), 1u);
- EXPECT_TRUE(task->dependencies()[0]);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+ EXPECT_EQ(result.task->dependencies().size(), 1u);
+ EXPECT_TRUE(result.task->dependencies()[0]);
// Run the task.
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
// Request the same image - it should be cached.
- scoped_refptr<TileTask> task2;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task2);
- EXPECT_TRUE(need_unref);
- EXPECT_FALSE(task2);
+ ImageDecodeCache::TaskResult second_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(second_result.need_unref);
+ EXPECT_FALSE(second_result.task);
// Unref both images.
cache.UnrefImage(draw_image);
@@ -1507,16 +1462,15 @@ TEST_P(GpuImageDecodeCacheTest, ZeroCacheNormalWorkingSet) {
// Get the image again. As it was fully unreffed, it is no longer in the
// working set and will be evicted due to 0 cache size.
- scoped_refptr<TileTask> task3;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task3);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task3);
- EXPECT_EQ(task3->dependencies().size(), 1u);
- EXPECT_TRUE(task->dependencies()[0]);
+ ImageDecodeCache::TaskResult third_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(third_result.need_unref);
+ EXPECT_TRUE(third_result.task);
+ EXPECT_EQ(third_result.task->dependencies().size(), 1u);
+ EXPECT_TRUE(third_result.task->dependencies()[0]);
- TestTileTaskRunner::ProcessTask(task3->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task3.get());
+ TestTileTaskRunner::ProcessTask(third_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(third_result.task.get());
cache.UnrefImage(draw_image);
}
@@ -1536,80 +1490,75 @@ TEST_P(GpuImageDecodeCacheTest, SmallCacheNormalWorkingSet) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
PaintImage image2 = CreateDiscardablePaintImage(gfx::Size(100, 100));
DrawImage draw_image2(
image2, SkIRect::MakeWH(image2.width(), image2.height()), quality,
CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
// Add an image to the cache and un-ref it.
{
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
- EXPECT_EQ(task->dependencies().size(), 1u);
- EXPECT_TRUE(task->dependencies()[0]);
+ ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(
+ draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+ EXPECT_EQ(result.task->dependencies().size(), 1u);
+ EXPECT_TRUE(result.task->dependencies()[0]);
// Run the task and unref the image.
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.UnrefImage(draw_image);
}
// Request the same image - it should be cached.
{
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_FALSE(task);
+ ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(
+ draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_FALSE(result.task);
cache.UnrefImage(draw_image);
}
// Add a new image to the cache. It should push out the old one.
{
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image2, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
- EXPECT_EQ(task->dependencies().size(), 1u);
- EXPECT_TRUE(task->dependencies()[0]);
+ ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(
+ draw_image2, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+ EXPECT_EQ(result.task->dependencies().size(), 1u);
+ EXPECT_TRUE(result.task->dependencies()[0]);
// Run the task and unref the image.
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.UnrefImage(draw_image2);
}
// Request the second image - it should be cached.
{
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image2, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_FALSE(task);
+ ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(
+ draw_image2, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_FALSE(result.task);
cache.UnrefImage(draw_image2);
}
// Request the first image - it should have been evicted and return a new
// task.
{
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
- EXPECT_EQ(task->dependencies().size(), 1u);
- EXPECT_TRUE(task->dependencies()[0]);
+ ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(
+ draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+ EXPECT_EQ(result.task->dependencies().size(), 1u);
+ EXPECT_TRUE(result.task->dependencies()[0]);
// Run the task and unref the image.
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.UnrefImage(draw_image);
}
}
@@ -1626,14 +1575,13 @@ TEST_P(GpuImageDecodeCacheTest, ClearCache) {
DrawImage draw_image(
image, SkIRect::MakeWH(image.width(), image.height()), quality,
CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(
+ draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.UnrefImage(draw_image);
}
@@ -1661,14 +1609,13 @@ TEST_P(GpuImageDecodeCacheTest, ClearCacheInUse) {
DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
quality,
CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
// We should now have data image in our cache.
EXPECT_GT(cache.GetBytesUsedForTesting(), 0u);
@@ -1701,38 +1648,35 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageDifferentColorSpace) {
DrawImage first_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- color_space_a);
- scoped_refptr<TileTask> first_task;
- bool need_unref = cache.GetTaskForImageAndRef(
- first_draw_image, ImageDecodeCache::TracingInfo(), &first_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(first_task);
+ PaintImage::kDefaultFrameIndex, color_space_a);
+ ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef(
+ first_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(first_result.need_unref);
+ EXPECT_TRUE(first_result.task);
DrawImage second_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- color_space_b);
- scoped_refptr<TileTask> second_task;
- need_unref = cache.GetTaskForImageAndRef(
- second_draw_image, ImageDecodeCache::TracingInfo(), &second_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(second_task);
- EXPECT_TRUE(first_task.get() != second_task.get());
+ PaintImage::kDefaultFrameIndex, color_space_b);
+ ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef(
+ second_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(second_result.need_unref);
+ EXPECT_TRUE(second_result.task);
+ EXPECT_TRUE(first_result.task.get() != second_result.task.get());
DrawImage third_draw_image(
first_image, SkIRect::MakeWH(first_image.width(), first_image.height()),
quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- color_space_a);
- scoped_refptr<TileTask> third_task;
- need_unref = cache.GetTaskForImageAndRef(
- third_draw_image, ImageDecodeCache::TracingInfo(), &third_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(third_task.get() == first_task.get());
-
- TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(first_task.get());
- TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(second_task.get());
+ PaintImage::kDefaultFrameIndex, color_space_a);
+ ImageDecodeCache::TaskResult third_result = cache.GetTaskForImageAndRef(
+ third_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(third_result.need_unref);
+ EXPECT_TRUE(third_result.task.get() == first_result.task.get());
+
+ TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(first_result.task.get());
+ TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(second_result.task.get());
cache.UnrefImage(first_draw_image);
cache.UnrefImage(second_draw_image);
@@ -1752,15 +1696,14 @@ TEST_P(GpuImageDecodeCacheTest, RemoveUnusedImage) {
DrawImage draw_image(
image, SkIRect::MakeWH(image.width(), image.height()), quality,
CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
frame_keys.push_back(draw_image.frame_key());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
- TestTileTaskRunner::ProcessTask(task->dependencies()[0].get());
- TestTileTaskRunner::ProcessTask(task.get());
+ ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(
+ draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+ TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.UnrefImage(draw_image);
}
@@ -1775,6 +1718,64 @@ TEST_P(GpuImageDecodeCacheTest, RemoveUnusedImage) {
}
}
+TEST_P(GpuImageDecodeCacheTest, CacheDecodesExpectedFrames) {
+ auto context_provider = TestContextProvider::Create();
+ context_provider->BindToCurrentThread();
+ TestGpuImageDecodeCache cache(context_provider.get(), GetParam());
+
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(4)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(5)),
+ };
+ sk_sp<FakePaintImageGenerator> generator =
+ sk_make_sp<FakePaintImageGenerator>(SkImageInfo::MakeN32Premul(10, 10),
+ frames);
+ PaintImage image = PaintImageBuilder::WithDefault()
+ .set_id(PaintImage::GetNextId())
+ .set_paint_image_generator(generator)
+ .set_frame_index(0u)
+ .TakePaintImage();
+
+ viz::ContextProvider::ScopedContextLock context_lock(context_provider.get());
+
+ bool is_decomposable = true;
+ SkFilterQuality quality = kHigh_SkFilterQuality;
+ DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
+ quality,
+ CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
+ 1u, DefaultColorSpace());
+ auto decoded_image = cache.GetDecodedImageForDraw(draw_image);
+ ASSERT_TRUE(decoded_image.image());
+ ASSERT_EQ(generator->frames_decoded().size(), 1u);
+ EXPECT_EQ(generator->frames_decoded().count(1u), 1u);
+ generator->reset_frames_decoded();
+ cache.DrawWithImageFinished(draw_image, decoded_image);
+
+ // Scaled.
+ DrawImage scaled_draw_image(draw_image, 0.5f, 2u,
+ draw_image.target_color_space());
+ decoded_image = cache.GetDecodedImageForDraw(scaled_draw_image);
+ ASSERT_TRUE(decoded_image.image());
+ ASSERT_EQ(generator->frames_decoded().size(), 1u);
+ EXPECT_EQ(generator->frames_decoded().count(2u), 1u);
+ generator->reset_frames_decoded();
+ cache.DrawWithImageFinished(scaled_draw_image, decoded_image);
+
+ // Subset.
+ DrawImage subset_draw_image(
+ image, SkIRect::MakeWH(5, 5), quality,
+ CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), 3u,
+ DefaultColorSpace());
+ decoded_image = cache.GetDecodedImageForDraw(subset_draw_image);
+ ASSERT_TRUE(decoded_image.image());
+ ASSERT_EQ(generator->frames_decoded().size(), 1u);
+ EXPECT_EQ(generator->frames_decoded().count(3u), 1u);
+ generator->reset_frames_decoded();
+ cache.DrawWithImageFinished(subset_draw_image, decoded_image);
+}
+
INSTANTIATE_TEST_CASE_P(GpuImageDecodeCacheTests,
GpuImageDecodeCacheTest,
::testing::Values(kN32_SkColorType,
diff --git a/chromium/cc/tiles/image_controller.cc b/chromium/cc/tiles/image_controller.cc
index ec90039d852..c2d896cafe6 100644
--- a/chromium/cc/tiles/image_controller.cc
+++ b/chromium/cc/tiles/image_controller.cc
@@ -141,23 +141,24 @@ void ImageController::SetImageDecodeCache(ImageDecodeCache* cache) {
GenerateTasksForOrphanedRequests();
}
}
-
void ImageController::GetTasksForImagesAndRef(
- std::vector<DrawImage>* images,
+ std::vector<DrawImage>* sync_decoded_images,
+ std::vector<DrawImage>* at_raster_images,
std::vector<scoped_refptr<TileTask>>* tasks,
const ImageDecodeCache::TracingInfo& tracing_info) {
DCHECK(cache_);
- for (auto it = images->begin(); it != images->end();) {
- scoped_refptr<TileTask> task;
- bool need_to_unref_when_finished =
- cache_->GetTaskForImageAndRef(*it, tracing_info, &task);
- if (task)
- tasks->push_back(std::move(task));
-
- if (need_to_unref_when_finished)
+ for (auto it = sync_decoded_images->begin();
+ it != sync_decoded_images->end();) {
+ ImageDecodeCache::TaskResult result =
+ cache_->GetTaskForImageAndRef(*it, tracing_info);
+ if (result.task)
+ tasks->push_back(std::move(result.task));
+ if (at_raster_images && result.IsAtRaster())
+ at_raster_images->push_back(*it);
+ if (result.need_unref)
++it;
else
- it = images->erase(it);
+ it = sync_decoded_images->erase(it);
}
}
@@ -175,7 +176,7 @@ std::vector<scoped_refptr<TileTask>> ImageController::SetPredecodeImages(
std::vector<DrawImage> images,
const ImageDecodeCache::TracingInfo& tracing_info) {
std::vector<scoped_refptr<TileTask>> new_tasks;
- GetTasksForImagesAndRef(&images, &new_tasks, tracing_info);
+ GetTasksForImagesAndRef(&images, nullptr, &new_tasks, tracing_info);
UnrefImages(predecode_locked_images_);
predecode_locked_images_ = std::move(images);
return new_tasks;
@@ -194,19 +195,16 @@ ImageController::ImageDecodeRequestId ImageController::QueueImageDecode(
bool is_image_lazy = draw_image.paint_image().IsLazyGenerated();
// Get the tasks for this decode.
- scoped_refptr<TileTask> task;
- bool need_unref = false;
- if (is_image_lazy) {
- need_unref =
- cache_->GetOutOfRasterDecodeTaskForImageAndRef(draw_image, &task);
- }
+ ImageDecodeCache::TaskResult result(false);
+ if (is_image_lazy)
+ result = cache_->GetOutOfRasterDecodeTaskForImageAndRef(draw_image);
// If we don't need to unref this, we don't actually have a task.
- DCHECK(need_unref || !task);
+ DCHECK(result.need_unref || !result.task);
// Schedule the task and signal that there is more work.
base::AutoLock hold(lock_);
- image_decode_queue_[id] =
- ImageDecodeRequest(id, draw_image, callback, std::move(task), need_unref);
+ image_decode_queue_[id] = ImageDecodeRequest(
+ id, draw_image, callback, std::move(result.task), result.need_unref);
// If this is the only image decode request, schedule a task to run.
// Otherwise, the task will be scheduled in the previou task's completion.
@@ -336,8 +334,10 @@ void ImageController::GenerateTasksForOrphanedRequests() {
DCHECK(!request.need_unref);
if (request.draw_image.paint_image().IsLazyGenerated()) {
// Get the task for this decode.
- request.need_unref = cache_->GetOutOfRasterDecodeTaskForImageAndRef(
- request.draw_image, &request.task);
+ ImageDecodeCache::TaskResult result =
+ cache_->GetOutOfRasterDecodeTaskForImageAndRef(request.draw_image);
+ request.need_unref = result.need_unref;
+ request.task = result.task;
}
image_decode_queue_[request.id] = std::move(request);
}
diff --git a/chromium/cc/tiles/image_controller.h b/chromium/cc/tiles/image_controller.h
index 33b1400f27c..990b94949f8 100644
--- a/chromium/cc/tiles/image_controller.h
+++ b/chromium/cc/tiles/image_controller.h
@@ -37,7 +37,8 @@ class CC_EXPORT ImageController {
void SetImageDecodeCache(ImageDecodeCache* cache);
void GetTasksForImagesAndRef(
- std::vector<DrawImage>* images,
+ std::vector<DrawImage>* sync_decoded_images,
+ std::vector<DrawImage>* at_raster_images,
std::vector<scoped_refptr<TileTask>>* tasks,
const ImageDecodeCache::TracingInfo& tracing_info);
void UnrefImages(const std::vector<DrawImage>& images);
diff --git a/chromium/cc/tiles/image_controller_unittest.cc b/chromium/cc/tiles/image_controller_unittest.cc
index 631c3d77132..17e939d248c 100644
--- a/chromium/cc/tiles/image_controller_unittest.cc
+++ b/chromium/cc/tiles/image_controller_unittest.cc
@@ -69,13 +69,13 @@ class WorkerTaskRunner : public base::SequencedTaskRunner {
public:
WorkerTaskRunner() { thread_.Start(); }
- bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
+ bool PostNonNestableDelayedTask(const base::Location& from_here,
base::OnceClosure task,
base::TimeDelta delay) override {
return PostDelayedTask(from_here, std::move(task), delay);
}
- bool PostDelayedTask(const tracked_objects::Location& from_here,
+ bool PostDelayedTask(const base::Location& from_here,
base::OnceClosure task,
base::TimeDelta delay) override {
thread_.PostTask(std::move(task));
@@ -98,25 +98,22 @@ class TestableCache : public StubDecodeCache {
public:
~TestableCache() override { EXPECT_EQ(number_of_refs_, 0); }
- bool GetTaskForImageAndRef(const DrawImage& image,
- const TracingInfo& tracing_info,
- scoped_refptr<TileTask>* task) override {
+ TaskResult GetTaskForImageAndRef(const DrawImage& image,
+ const TracingInfo& tracing_info) override {
// Return false for large images to mimic "won't fit in memory"
// behavior.
if (image.paint_image() &&
image.paint_image().width() * image.paint_image().height() >=
1000 * 1000) {
- return false;
+ return TaskResult(false);
}
- *task = task_to_use_;
++number_of_refs_;
- return true;
+ return TaskResult(task_to_use_);
}
- bool GetOutOfRasterDecodeTaskForImageAndRef(
- const DrawImage& image,
- scoped_refptr<TileTask>* task) override {
- return GetTaskForImageAndRef(image, TracingInfo(), task);
+ TaskResult GetOutOfRasterDecodeTaskForImageAndRef(
+ const DrawImage& image) override {
+ return GetTaskForImageAndRef(image, TracingInfo());
}
void UnrefImage(const DrawImage& image) override {
@@ -231,7 +228,8 @@ int kDefaultTimeoutSeconds = 10;
DrawImage CreateDiscardableDrawImage(gfx::Size size) {
return DrawImage(CreateDiscardablePaintImage(size),
SkIRect::MakeWH(size.width(), size.height()),
- kNone_SkFilterQuality, SkMatrix::I(), gfx::ColorSpace());
+ kNone_SkFilterQuality, SkMatrix::I(),
+ PaintImage::kDefaultFrameIndex, gfx::ColorSpace());
}
class ImageControllerTest : public testing::Test {
@@ -242,7 +240,7 @@ class ImageControllerTest : public testing::Test {
~ImageControllerTest() override = default;
void SetUp() override {
- worker_task_runner_ = make_scoped_refptr(new WorkerTaskRunner);
+ worker_task_runner_ = base::MakeRefCounted<WorkerTaskRunner>();
controller_.reset(
new ImageController(task_runner_.get(), worker_task_runner_));
cache_ = TestableCache();
@@ -320,12 +318,13 @@ TEST_F(ImageControllerTest, QueueImageDecodeNonLazy) {
SkBitmap bitmap;
bitmap.allocN32Pixels(1, 1);
- DrawImage image = DrawImage(PaintImageBuilder()
- .set_id(PaintImage::GetNextId())
- .set_image(SkImage::MakeFromBitmap(bitmap))
- .TakePaintImage(),
- SkIRect::MakeWH(1, 1), kNone_SkFilterQuality,
- SkMatrix::I(), gfx::ColorSpace());
+ DrawImage image =
+ DrawImage(PaintImageBuilder::WithDefault()
+ .set_id(PaintImage::GetNextId())
+ .set_image(SkImage::MakeFromBitmap(bitmap))
+ .TakePaintImage(),
+ SkIRect::MakeWH(1, 1), kNone_SkFilterQuality, SkMatrix::I(),
+ PaintImage::kDefaultFrameIndex, gfx::ColorSpace());
ImageController::ImageDecodeRequestId expected_id =
controller()->QueueImageDecode(
diff --git a/chromium/cc/tiles/image_decode_cache.cc b/chromium/cc/tiles/image_decode_cache.cc
index 680264da26b..7c83ee45a15 100644
--- a/chromium/cc/tiles/image_decode_cache.cc
+++ b/chromium/cc/tiles/image_decode_cache.cc
@@ -5,9 +5,20 @@
#include "cc/tiles/image_decode_cache.h"
#include "base/metrics/histogram_macros.h"
+#include "cc/raster/tile_task.h"
namespace cc {
+ImageDecodeCache::TaskResult::TaskResult(bool need_unref)
+ : need_unref(need_unref) {}
+
+ImageDecodeCache::TaskResult::TaskResult(scoped_refptr<TileTask> task)
+ : task(std::move(task)), need_unref(true) {}
+
+ImageDecodeCache::TaskResult::TaskResult(const TaskResult& result) = default;
+
+ImageDecodeCache::TaskResult::~TaskResult() = default;
+
void ImageDecodeCache::RecordImageMipLevelUMA(int mip_level) {
DCHECK_GE(mip_level, 0);
DCHECK_LT(mip_level, 32);
diff --git a/chromium/cc/tiles/image_decode_cache.h b/chromium/cc/tiles/image_decode_cache.h
index 6994ba571a6..557059ca463 100644
--- a/chromium/cc/tiles/image_decode_cache.h
+++ b/chromium/cc/tiles/image_decode_cache.h
@@ -7,14 +7,14 @@
#include "base/memory/ref_counted.h"
#include "cc/base/devtools_instrumentation.h"
+#include "cc/cc_export.h"
#include "cc/paint/decoded_draw_image.h"
#include "cc/paint/draw_image.h"
+#include "cc/raster/tile_task.h"
#include "cc/tiles/tile_priority.h"
namespace cc {
-class TileTask;
-
// ImageDecodeCache is responsible for generating decode tasks, decoding
// images, storing images in cache, and being able to return the decoded images
// when requested.
@@ -74,23 +74,32 @@ class CC_EXPORT ImageDecodeCache {
virtual ~ImageDecodeCache() {}
+ struct CC_EXPORT TaskResult {
+ explicit TaskResult(bool need_unref);
+ explicit TaskResult(scoped_refptr<TileTask> task);
+ TaskResult(const TaskResult& result);
+ ~TaskResult();
+
+ bool IsAtRaster() const { return !task && !need_unref; }
+
+ scoped_refptr<TileTask> task;
+ bool need_unref = false;
+ };
// Fill in an TileTask which will decode the given image when run. In
// case the image is already cached, fills in nullptr. Returns true if the
// image needs to be unreffed when the caller is finished with it.
//
// This is called by the tile manager (on the compositor thread) when creating
// a raster task.
- virtual bool GetTaskForImageAndRef(const DrawImage& image,
- const TracingInfo& tracing_info,
- scoped_refptr<TileTask>* task) = 0;
+ virtual TaskResult GetTaskForImageAndRef(const DrawImage& image,
+ const TracingInfo& tracing_info) = 0;
// Similar to GetTaskForImageAndRef, except that it returns tasks that are not
// meant to be run as part of raster. That is, this is part of a predecode
// API. Note that this should only return a task responsible for decoding (and
// not uploading), since it will be run on a worker thread which may not have
// the right GPU context for upload.
- virtual bool GetOutOfRasterDecodeTaskForImageAndRef(
- const DrawImage& image,
- scoped_refptr<TileTask>* task) = 0;
+ virtual TaskResult GetOutOfRasterDecodeTaskForImageAndRef(
+ const DrawImage& image) = 0;
// Unrefs an image. When the tile is finished, this should be called for every
// GetTaskForImageAndRef call that returned true.
diff --git a/chromium/cc/tiles/picture_layer_tiling_set_unittest.cc b/chromium/cc/tiles/picture_layer_tiling_set_unittest.cc
index b485b7a2ede..d7e37b3dea2 100644
--- a/chromium/cc/tiles/picture_layer_tiling_set_unittest.cc
+++ b/chromium/cc/tiles/picture_layer_tiling_set_unittest.cc
@@ -250,7 +250,7 @@ class PictureLayerTilingSetTestWithResources : public testing::Test {
ASSERT_TRUE(context_provider->BindToCurrentThread());
auto shared_bitmap_manager = std::make_unique<TestSharedBitmapManager>();
std::unique_ptr<ResourceProvider> resource_provider =
- FakeResourceProvider::Create<LayerTreeResourceProvider>(
+ FakeResourceProvider::CreateLayerTreeResourceProvider(
context_provider.get(), shared_bitmap_manager.get());
FakePictureLayerTilingClient client(resource_provider.get());
diff --git a/chromium/cc/tiles/software_image_decode_cache.cc b/chromium/cc/tiles/software_image_decode_cache.cc
index b9e3f757e99..9d0bb6a6a0f 100644
--- a/chromium/cc/tiles/software_image_decode_cache.cc
+++ b/chromium/cc/tiles/software_image_decode_cache.cc
@@ -52,6 +52,9 @@ const size_t kMemoryThresholdToSubrect = 64 * 1024 * 1024;
const int kMinDimensionToSubrect = 4 * 1024;
const float kMemoryRatioToSubrect = 0.5f;
+// Tracing ID sequence for use in DecodedImage.
+base::AtomicSequenceNumber g_next_tracing_id_;
+
class AutoRemoveKeyFromTaskMap {
public:
AutoRemoveKeyFromTaskMap(
@@ -217,28 +220,27 @@ SoftwareImageDecodeCache::~SoftwareImageDecodeCache() {
base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this);
}
-bool SoftwareImageDecodeCache::GetTaskForImageAndRef(
+ImageDecodeCache::TaskResult SoftwareImageDecodeCache::GetTaskForImageAndRef(
const DrawImage& image,
- const TracingInfo& tracing_info,
- scoped_refptr<TileTask>* task) {
+ const TracingInfo& tracing_info) {
DCHECK_EQ(tracing_info.task_type, TaskType::kInRaster);
- return GetTaskForImageAndRefInternal(
- image, tracing_info, DecodeTaskType::USE_IN_RASTER_TASKS, task);
+ return GetTaskForImageAndRefInternal(image, tracing_info,
+ DecodeTaskType::USE_IN_RASTER_TASKS);
}
-bool SoftwareImageDecodeCache::GetOutOfRasterDecodeTaskForImageAndRef(
- const DrawImage& image,
- scoped_refptr<TileTask>* task) {
+ImageDecodeCache::TaskResult
+SoftwareImageDecodeCache::GetOutOfRasterDecodeTaskForImageAndRef(
+ const DrawImage& image) {
return GetTaskForImageAndRefInternal(
image, TracingInfo(0, TilePriority::NOW, TaskType::kOutOfRaster),
- DecodeTaskType::USE_OUT_OF_RASTER_TASKS, task);
+ DecodeTaskType::USE_OUT_OF_RASTER_TASKS);
}
-bool SoftwareImageDecodeCache::GetTaskForImageAndRefInternal(
+ImageDecodeCache::TaskResult
+SoftwareImageDecodeCache::GetTaskForImageAndRefInternal(
const DrawImage& image,
const TracingInfo& tracing_info,
- DecodeTaskType task_type,
- scoped_refptr<TileTask>* task) {
+ DecodeTaskType task_type) {
// If the image already exists or if we're going to create a task for it, then
// we'll likely need to ref this image (the exception is if we're prerolling
// the image only). That means the image is or will be in the cache. When the
@@ -254,8 +256,7 @@ bool SoftwareImageDecodeCache::GetTaskForImageAndRefInternal(
// If the target size is empty, we can skip this image during draw (and thus
// we don't need to decode it or ref it).
if (key.target_size().IsEmpty()) {
- *task = nullptr;
- return false;
+ return TaskResult(false);
}
base::AutoLock lock(lock_);
@@ -269,14 +270,13 @@ bool SoftwareImageDecodeCache::GetTaskForImageAndRefInternal(
if (image_was_locked ||
(new_image_fits_in_memory && decoded_it->second->Lock())) {
RefImage(key);
- *task = nullptr;
// If the image wasn't locked, then we just succeeded in locking it.
if (!image_was_locked) {
RecordLockExistingCachedImageHistogram(tracing_info.requesting_tile_bin,
true);
}
- return true;
+ return TaskResult(true);
}
// If the image fits in memory, then we at least tried to lock it and
@@ -299,8 +299,7 @@ bool SoftwareImageDecodeCache::GetTaskForImageAndRefInternal(
: pending_out_of_raster_image_tasks_[key];
if (existing_task) {
RefImage(key);
- *task = existing_task;
- return true;
+ return TaskResult(existing_task);
}
// At this point, we have to create a new image/task, so we need to abort if
@@ -310,17 +309,15 @@ bool SoftwareImageDecodeCache::GetTaskForImageAndRefInternal(
// ref to the image that is now being reffed for the new schedule.
if (!new_image_fits_in_memory && (decoded_images_ref_counts_.find(key) ==
decoded_images_ref_counts_.end())) {
- *task = nullptr;
- return false;
+ return TaskResult(false);
}
// Actually create the task. RefImage will account for memory on the first
// ref.
RefImage(key);
- existing_task = make_scoped_refptr(
- new ImageDecodeTaskImpl(this, key, image, task_type, tracing_info));
- *task = existing_task;
- return true;
+ existing_task = base::MakeRefCounted<ImageDecodeTaskImpl>(
+ this, key, image, task_type, tracing_info);
+ return TaskResult(existing_task);
}
void SoftwareImageDecodeCache::RefImage(const ImageKey& key) {
@@ -452,12 +449,15 @@ SoftwareImageDecodeCache::DecodeImageInternal(const ImageKey& key,
// that scale, or
// - If we're not doing a scale at all (which is supported by all decoders and
// subsetting is handled in the draw calls).
- // TODO(vmpstr): See if we can subrect thing decoded to native scale.
+ // TODO(vmpstr): See if we can subrect the result of decoded to scale.
SkIRect full_size_rect =
SkIRect::MakeWH(paint_image.width(), paint_image.height());
bool need_subset = (gfx::RectToSkIRect(key.src_rect()) != full_size_rect);
SkISize exact_size =
SkISize::Make(key.target_size().width(), key.target_size().height());
+ // TODO(vmpstr): If an image of a bigger size is already decoded and is
+ // lock-able then it might be faster to just scale that instead of redecoding
+ // to exact scale. We need to profile this.
if ((!need_subset &&
exact_size == paint_image.GetSupportedDecodeSize(exact_size)) ||
SkIRect::MakeSize(exact_size) == full_size_rect) {
@@ -599,7 +599,8 @@ SoftwareImageDecodeCache::GetExactSizeImageDecode(
"SoftwareImageDecodeCache::GetOriginalSizeImageDecode - "
"decode");
bool result = paint_image.Decode(decoded_pixels->data(), &decoded_info,
- key.target_color_space().ToSkColorSpace());
+ key.target_color_space().ToSkColorSpace(),
+ key.frame_key().frame_index());
if (!result) {
decoded_pixels->Unlock();
return nullptr;
@@ -607,8 +608,7 @@ SoftwareImageDecodeCache::GetExactSizeImageDecode(
}
return std::make_unique<DecodedImage>(decoded_info, std::move(decoded_pixels),
- SkSize::Make(0, 0),
- next_tracing_id_.GetNext());
+ SkSize::Make(0, 0));
}
std::unique_ptr<SoftwareImageDecodeCache::DecodedImage>
@@ -622,7 +622,8 @@ SoftwareImageDecodeCache::GetSubrectImageDecode(const ImageKey& key,
// so. We could also subrect scaled images.
SkIRect exact_size_rect = SkIRect::MakeWH(image.width(), image.height());
DrawImage exact_size_draw_image(image, exact_size_rect, kNone_SkFilterQuality,
- SkMatrix::I(), key.target_color_space());
+ SkMatrix::I(), key.frame_key().frame_index(),
+ key.target_color_space());
ImageKey exact_size_key =
ImageKey::FromDrawImage(exact_size_draw_image, color_type_);
@@ -672,11 +673,10 @@ SoftwareImageDecodeCache::GetSubrectImageDecode(const ImageKey& key,
DCHECK(result);
}
- return base::WrapUnique(new DecodedImage(
+ return std::make_unique<DecodedImage>(
subrect_info.makeColorSpace(decoded_draw_image.image()->refColorSpace()),
std::move(subrect_pixels),
- SkSize::Make(-key.src_rect().x(), -key.src_rect().y()),
- next_tracing_id_.GetNext()));
+ SkSize::Make(-key.src_rect().x(), -key.src_rect().y()));
}
std::unique_ptr<SoftwareImageDecodeCache::DecodedImage>
@@ -696,7 +696,8 @@ SoftwareImageDecodeCache::GetScaledImageDecode(const ImageKey& key,
key.target_size().width(), key.target_size().height())));
DrawImage exact_size_draw_image(image, exact_size_rect, kNone_SkFilterQuality,
- SkMatrix::I(), key.target_color_space());
+ SkMatrix::I(), key.frame_key().frame_index(),
+ key.target_color_space());
ImageKey exact_size_key =
ImageKey::FromDrawImage(exact_size_draw_image, color_type_);
@@ -755,8 +756,7 @@ SoftwareImageDecodeCache::GetScaledImageDecode(const ImageKey& key,
return std::make_unique<DecodedImage>(
scaled_info.makeColorSpace(decoded_draw_image.image()->refColorSpace()),
std::move(scaled_pixels),
- SkSize::Make(-key.src_rect().x(), -key.src_rect().y()),
- next_tracing_id_.GetNext());
+ SkSize::Make(-key.src_rect().x(), -key.src_rect().y()));
}
void SoftwareImageDecodeCache::DrawWithImageFinished(
@@ -994,6 +994,10 @@ ImageDecodeCacheKey ImageDecodeCacheKey::FromDrawImage(const DrawImage& image,
} else {
quality = kMedium_SkFilterQuality;
// Update the target size to be a mip level size.
+ // TODO(vmpstr): MipMapUtil and JPEG decoders disagree on what to do with
+ // odd sizes. If width = 2k + 1, and the mip level is 1, then this will
+ // return width = k; JPEG decoder, however, will support decoding to width =
+ // k + 1. We need to figure out what to do in this case.
SkSize mip_scale_adjustment =
MipMapUtil::GetScaleAdjustmentForLevel(src_rect.size(), mip_level);
target_size.set_width(src_rect.width() * mip_scale_adjustment.width());
@@ -1093,13 +1097,12 @@ std::string ImageDecodeCacheKey::ToString() const {
SoftwareImageDecodeCache::DecodedImage::DecodedImage(
const SkImageInfo& info,
std::unique_ptr<base::DiscardableMemory> memory,
- const SkSize& src_rect_offset,
- uint64_t tracing_id)
+ const SkSize& src_rect_offset)
: locked_(true),
image_info_(info),
memory_(std::move(memory)),
src_rect_offset_(src_rect_offset),
- tracing_id_(tracing_id) {
+ tracing_id_(g_next_tracing_id_.GetNext()) {
SkPixmap pixmap(image_info_, memory_->data(), image_info_.minRowBytes());
image_ = SkImage::MakeFromRaster(
pixmap, [](const void* pixels, void* context) {}, nullptr);
diff --git a/chromium/cc/tiles/software_image_decode_cache.h b/chromium/cc/tiles/software_image_decode_cache.h
index a59cdf2637c..222ad090578 100644
--- a/chromium/cc/tiles/software_image_decode_cache.h
+++ b/chromium/cc/tiles/software_image_decode_cache.h
@@ -124,12 +124,10 @@ class CC_EXPORT SoftwareImageDecodeCache
~SoftwareImageDecodeCache() override;
// ImageDecodeCache overrides.
- bool GetTaskForImageAndRef(const DrawImage& image,
- const TracingInfo& tracing_info,
- scoped_refptr<TileTask>* task) override;
- bool GetOutOfRasterDecodeTaskForImageAndRef(
- const DrawImage& image,
- scoped_refptr<TileTask>* task) override;
+ TaskResult GetTaskForImageAndRef(const DrawImage& image,
+ const TracingInfo& tracing_info) override;
+ TaskResult GetOutOfRasterDecodeTaskForImageAndRef(
+ const DrawImage& image) override;
void UnrefImage(const DrawImage& image) override;
DecodedDrawImage GetDecodedImageForDraw(const DrawImage& image) override;
void DrawWithImageFinished(const DrawImage& image,
@@ -163,8 +161,7 @@ class CC_EXPORT SoftwareImageDecodeCache
public:
DecodedImage(const SkImageInfo& info,
std::unique_ptr<base::DiscardableMemory> memory,
- const SkSize& src_rect_offset,
- uint64_t tracing_id);
+ const SkSize& src_rect_offset);
~DecodedImage();
const sk_sp<SkImage>& image() const {
@@ -295,10 +292,9 @@ class CC_EXPORT SoftwareImageDecodeCache
// Helper method to get the different tasks. Note that this should be used as
// if it was public (ie, all of the locks need to be properly acquired).
- bool GetTaskForImageAndRefInternal(const DrawImage& image,
- const TracingInfo& tracing_info,
- DecodeTaskType type,
- scoped_refptr<TileTask>* task);
+ TaskResult GetTaskForImageAndRefInternal(const DrawImage& image,
+ const TracingInfo& tracing_info,
+ DecodeTaskType type);
void CacheDecodedImages(const ImageKey& key,
std::unique_ptr<DecodedImage> decoded_image);
@@ -336,9 +332,6 @@ class CC_EXPORT SoftwareImageDecodeCache
SkColorType color_type_;
size_t max_items_in_cache_;
-
- // Used to uniquely identify DecodedImages for memory traces.
- base::AtomicSequenceNumber next_tracing_id_;
};
} // namespace cc
diff --git a/chromium/cc/tiles/software_image_decode_cache_perftest.cc b/chromium/cc/tiles/software_image_decode_cache_perftest.cc
index fd9f4e8dcff..24bae708790 100644
--- a/chromium/cc/tiles/software_image_decode_cache_perftest.cc
+++ b/chromium/cc/tiles/software_image_decode_cache_perftest.cc
@@ -57,12 +57,12 @@ class SoftwareImageDecodeCachePerfTest : public testing::Test {
auto& subrect = rect_subrect.second;
for (auto& scale : scales) {
images.emplace_back(
- PaintImageBuilder()
+ PaintImageBuilder::WithDefault()
.set_id(PaintImage::GetNextId())
.set_image(CreateImage(rect.width(), rect.height()))
.TakePaintImage(),
subrect, quality,
- CreateMatrix(SkSize::Make(scale.first, scale.second)),
+ CreateMatrix(SkSize::Make(scale.first, scale.second)), 0u,
gfx::ColorSpace());
}
}
diff --git a/chromium/cc/tiles/software_image_decode_cache_unittest.cc b/chromium/cc/tiles/software_image_decode_cache_unittest.cc
index 321bf021be2..c5e0ff9186f 100644
--- a/chromium/cc/tiles/software_image_decode_cache_unittest.cc
+++ b/chromium/cc/tiles/software_image_decode_cache_unittest.cc
@@ -6,6 +6,7 @@
#include "cc/paint/draw_image.h"
#include "cc/paint/paint_image_builder.h"
+#include "cc/test/fake_paint_image_generator.h"
#include "cc/test/skia_common.h"
#include "cc/test/test_tile_task_runner.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -51,7 +52,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyNoneQuality) {
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
kNone_SkFilterQuality,
CreateMatrix(SkSize::Make(0.5f, 1.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -72,7 +73,7 @@ TEST(SoftwareImageDecodeCacheTest,
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
kLow_SkFilterQuality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -90,7 +91,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityDropsToLowIfMipLevel0) {
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
kMedium_SkFilterQuality,
CreateMatrix(SkSize::Make(0.75f, 0.75f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -108,7 +109,7 @@ TEST(SoftwareImageDecodeCacheTest, LowUnscalableFormatStaysLow) {
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
kLow_SkFilterQuality,
CreateMatrix(SkSize::Make(0.5f, 1.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key =
ImageDecodeCacheKey::FromDrawImage(draw_image, kARGB_4444_SkColorType);
@@ -127,7 +128,7 @@ TEST(SoftwareImageDecodeCacheTest, HighUnscalableFormatBecomesLow) {
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
kHigh_SkFilterQuality,
CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key =
ImageDecodeCacheKey::FromDrawImage(draw_image, kARGB_4444_SkColorType);
@@ -146,7 +147,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyLowQualityKeptLowIfUpscale) {
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
kLow_SkFilterQuality,
CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -165,7 +166,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQuality) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.4f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -184,7 +185,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityDropToLowIfEnlarging) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -203,7 +204,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityDropToLowIfIdentity) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -223,7 +224,7 @@ TEST(SoftwareImageDecodeCacheTest,
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.001f, 1.001f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -243,7 +244,7 @@ TEST(SoftwareImageDecodeCacheTest,
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.999f, 0.999f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -263,7 +264,7 @@ TEST(SoftwareImageDecodeCacheTest,
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 1.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -283,7 +284,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityAt1_5Scale) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -302,7 +303,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityAt1_0cale) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -321,7 +322,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyLowQualityAt0_75Scale) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.75f, 0.75f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -340,7 +341,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityAt0_5Scale) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -359,7 +360,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityAt0_49Scale) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.49f, 0.49f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -378,7 +379,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityAt0_1Scale) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.1f, 0.1f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -397,7 +398,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityAt0_01Scale) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.01f, 0.01f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -417,7 +418,7 @@ TEST(SoftwareImageDecodeCacheTest,
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.2f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -436,7 +437,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyUpscaleIsLowQuality) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(2.5f, 1.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -458,7 +459,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyHighQualityDropToMediumIfTooLarge) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.45f, 0.45f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -478,7 +479,7 @@ TEST(SoftwareImageDecodeCacheTest,
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 1.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -497,7 +498,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyHighQualityDropToLowIfIdentity) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -517,7 +518,7 @@ TEST(SoftwareImageDecodeCacheTest,
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.001f, 1.001f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -537,7 +538,7 @@ TEST(SoftwareImageDecodeCacheTest,
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.999f, 0.999f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -556,7 +557,7 @@ TEST(SoftwareImageDecodeCacheTest, OriginalDecodesAreEqual) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -569,7 +570,7 @@ TEST(SoftwareImageDecodeCacheTest, OriginalDecodesAreEqual) {
DrawImage another_draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.5f, 1.5), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto another_key =
ImageDecodeCacheKey::FromDrawImage(another_draw_image, kN32_SkColorType);
@@ -592,7 +593,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageRectDoesNotContainSrcRect) {
paint_image,
SkIRect::MakeXYWH(25, 35, paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -612,7 +613,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageRectDoesNotContainSrcRectWithScale) {
paint_image,
SkIRect::MakeXYWH(20, 30, paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType);
EXPECT_EQ(draw_image.frame_key(), key.frame_key());
@@ -632,24 +633,22 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageSameImage) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
DrawImage another_draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> another_task;
- need_unref = cache.GetTaskForImageAndRef(
- another_draw_image, ImageDecodeCache::TracingInfo(), &another_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task.get() == another_task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult another_result = cache.GetTaskForImageAndRef(
+ another_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(another_result.need_unref);
+ EXPECT_TRUE(result.task.get() == another_result.task.get());
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.UnrefImage(draw_image);
cache.UnrefImage(draw_image);
@@ -664,29 +663,27 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageSameImageDifferentQuality) {
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
kHigh_SkFilterQuality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> high_quality_task;
- bool need_unref = cache.GetTaskForImageAndRef(high_quality_draw_image,
- ImageDecodeCache::TracingInfo(),
- &high_quality_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(high_quality_task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult high_quality_result =
+ cache.GetTaskForImageAndRef(high_quality_draw_image,
+ ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(high_quality_result.need_unref);
+ EXPECT_TRUE(high_quality_result.task);
DrawImage none_quality_draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
kNone_SkFilterQuality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> none_quality_task;
- need_unref = cache.GetTaskForImageAndRef(none_quality_draw_image,
- ImageDecodeCache::TracingInfo(),
- &none_quality_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(none_quality_task);
- EXPECT_TRUE(high_quality_task.get() != none_quality_task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult none_quality_result =
+ cache.GetTaskForImageAndRef(none_quality_draw_image,
+ ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(none_quality_result.need_unref);
+ EXPECT_TRUE(none_quality_result.task);
+ EXPECT_TRUE(high_quality_result.task.get() != none_quality_result.task.get());
- TestTileTaskRunner::ProcessTask(high_quality_task.get());
- TestTileTaskRunner::ProcessTask(none_quality_task.get());
+ TestTileTaskRunner::ProcessTask(high_quality_result.task.get());
+ TestTileTaskRunner::ProcessTask(none_quality_result.task.get());
cache.UnrefImage(high_quality_draw_image);
cache.UnrefImage(none_quality_draw_image);
@@ -701,27 +698,25 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageSameImageDifferentSize) {
DrawImage half_size_draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> half_size_task;
- bool need_unref = cache.GetTaskForImageAndRef(
- half_size_draw_image, ImageDecodeCache::TracingInfo(), &half_size_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(half_size_task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult half_size_result = cache.GetTaskForImageAndRef(
+ half_size_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(half_size_result.need_unref);
+ EXPECT_TRUE(half_size_result.task);
DrawImage quarter_size_draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> quarter_size_task;
- need_unref = cache.GetTaskForImageAndRef(quarter_size_draw_image,
- ImageDecodeCache::TracingInfo(),
- &quarter_size_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(quarter_size_task);
- EXPECT_TRUE(half_size_task.get() != quarter_size_task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult quarter_size_result =
+ cache.GetTaskForImageAndRef(quarter_size_draw_image,
+ ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(quarter_size_result.need_unref);
+ EXPECT_TRUE(quarter_size_result.task);
+ EXPECT_TRUE(half_size_result.task.get() != quarter_size_result.task.get());
- TestTileTaskRunner::ProcessTask(half_size_task.get());
- TestTileTaskRunner::ProcessTask(quarter_size_task.get());
+ TestTileTaskRunner::ProcessTask(half_size_result.task.get());
+ TestTileTaskRunner::ProcessTask(quarter_size_result.task.get());
cache.UnrefImage(half_size_draw_image);
cache.UnrefImage(quarter_size_draw_image);
@@ -737,28 +732,26 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageDifferentImage) {
first_paint_image,
SkIRect::MakeWH(first_paint_image.width(), first_paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> first_task;
- bool need_unref = cache.GetTaskForImageAndRef(
- first_draw_image, ImageDecodeCache::TracingInfo(), &first_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(first_task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef(
+ first_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(first_result.need_unref);
+ EXPECT_TRUE(first_result.task);
PaintImage second_paint_image = CreatePaintImage(100, 100);
DrawImage second_draw_image(
second_paint_image,
SkIRect::MakeWH(second_paint_image.width(), second_paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> second_task;
- need_unref = cache.GetTaskForImageAndRef(
- second_draw_image, ImageDecodeCache::TracingInfo(), &second_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(second_task);
- EXPECT_TRUE(first_task.get() != second_task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef(
+ second_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(second_result.need_unref);
+ EXPECT_TRUE(second_result.task);
+ EXPECT_TRUE(first_result.task.get() != second_result.task.get());
- TestTileTaskRunner::ProcessTask(first_task.get());
- TestTileTaskRunner::ProcessTask(second_task.get());
+ TestTileTaskRunner::ProcessTask(first_result.task.get());
+ TestTileTaskRunner::ProcessTask(second_result.task.get());
cache.UnrefImage(first_draw_image);
cache.UnrefImage(second_draw_image);
@@ -787,37 +780,34 @@ TEST(SoftwareImageDecodeCacheTest, MAYBE_GetTaskForImageDifferentColorSpace) {
DrawImage first_draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- color_space_b);
- scoped_refptr<TileTask> first_task;
- bool need_unref = cache.GetTaskForImageAndRef(
- first_draw_image, ImageDecodeCache::TracingInfo(), &first_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(first_task);
+ PaintImage::kDefaultFrameIndex, color_space_b);
+ ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef(
+ first_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(first_result.need_unref);
+ EXPECT_TRUE(first_result.task);
DrawImage second_draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- color_space_c);
- scoped_refptr<TileTask> second_task;
- need_unref = cache.GetTaskForImageAndRef(
- second_draw_image, ImageDecodeCache::TracingInfo(), &second_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(second_task);
- EXPECT_TRUE(first_task.get() != second_task.get());
+ PaintImage::kDefaultFrameIndex, color_space_c);
+ ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef(
+ second_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(second_result.need_unref);
+ EXPECT_TRUE(second_result.task);
+ EXPECT_TRUE(first_result.task.get() != second_result.task.get());
DrawImage third_draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- color_space_b);
- scoped_refptr<TileTask> third_task;
- need_unref = cache.GetTaskForImageAndRef(
- third_draw_image, ImageDecodeCache::TracingInfo(), &third_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(third_task);
- EXPECT_TRUE(first_task.get() == third_task.get());
+ PaintImage::kDefaultFrameIndex, color_space_b);
+ ImageDecodeCache::TaskResult third_result = cache.GetTaskForImageAndRef(
+ third_draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(third_result.need_unref);
+ EXPECT_TRUE(third_result.task);
+ EXPECT_TRUE(first_result.task.get() == third_result.task.get());
- TestTileTaskRunner::ProcessTask(first_task.get());
- TestTileTaskRunner::ProcessTask(second_task.get());
+ TestTileTaskRunner::ProcessTask(first_result.task.get());
+ TestTileTaskRunner::ProcessTask(second_result.task.get());
cache.UnrefImage(first_draw_image);
cache.UnrefImage(second_draw_image);
@@ -833,23 +823,21 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageAlreadyDecoded) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ScheduleTask(task.get());
- TestTileTaskRunner::RunTask(task.get());
+ TestTileTaskRunner::ScheduleTask(result.task.get());
+ TestTileTaskRunner::RunTask(result.task.get());
- scoped_refptr<TileTask> another_task;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &another_task);
- EXPECT_TRUE(need_unref);
- EXPECT_FALSE(another_task);
+ ImageDecodeCache::TaskResult another_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(another_result.need_unref);
+ EXPECT_FALSE(another_result.task);
- TestTileTaskRunner::CompleteTask(task.get());
+ TestTileTaskRunner::CompleteTask(result.task.get());
cache.UnrefImage(draw_image);
cache.UnrefImage(draw_image);
@@ -864,29 +852,26 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageAlreadyPrerolled) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ScheduleTask(task.get());
- TestTileTaskRunner::RunTask(task.get());
+ TestTileTaskRunner::ScheduleTask(result.task.get());
+ TestTileTaskRunner::RunTask(result.task.get());
- scoped_refptr<TileTask> another_task;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &another_task);
- EXPECT_TRUE(need_unref);
- EXPECT_FALSE(another_task);
+ ImageDecodeCache::TaskResult another_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(another_result.need_unref);
+ EXPECT_FALSE(another_result.task);
- TestTileTaskRunner::CompleteTask(task.get());
+ TestTileTaskRunner::CompleteTask(result.task.get());
- scoped_refptr<TileTask> third_task;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &third_task);
- EXPECT_TRUE(need_unref);
- EXPECT_FALSE(third_task);
+ ImageDecodeCache::TaskResult third_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(third_result.need_unref);
+ EXPECT_FALSE(third_result.task);
cache.UnrefImage(draw_image);
cache.UnrefImage(draw_image);
@@ -902,36 +887,33 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageCanceledGetsNewTask) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
-
- scoped_refptr<TileTask> another_task;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &another_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(another_task.get() == task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+
+ ImageDecodeCache::TaskResult another_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(another_result.need_unref);
+ EXPECT_TRUE(another_result.task.get() == result.task.get());
// Didn't run the task, complete it (it was canceled).
- TestTileTaskRunner::CancelTask(task.get());
- TestTileTaskRunner::CompleteTask(task.get());
+ TestTileTaskRunner::CancelTask(result.task.get());
+ TestTileTaskRunner::CompleteTask(result.task.get());
// Fully cancel everything (so the raster would unref things).
cache.UnrefImage(draw_image);
cache.UnrefImage(draw_image);
// Here a new task is created.
- scoped_refptr<TileTask> third_task;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &third_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(third_task);
- EXPECT_FALSE(third_task.get() == task.get());
+ ImageDecodeCache::TaskResult third_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(third_result.need_unref);
+ EXPECT_TRUE(third_result.task);
+ EXPECT_FALSE(third_result.task.get() == result.task.get());
- TestTileTaskRunner::ProcessTask(third_task.get());
+ TestTileTaskRunner::ProcessTask(third_result.task.get());
cache.UnrefImage(draw_image);
}
@@ -946,35 +928,32 @@ TEST(SoftwareImageDecodeCacheTest,
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
-
- scoped_refptr<TileTask> another_task;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &another_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(another_task.get() == task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+
+ ImageDecodeCache::TaskResult another_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(another_result.need_unref);
+ EXPECT_TRUE(another_result.task.get() == result.task.get());
// Didn't run the task, complete it (it was canceled).
- TestTileTaskRunner::CancelTask(task.get());
- TestTileTaskRunner::CompleteTask(task.get());
+ TestTileTaskRunner::CancelTask(result.task.get());
+ TestTileTaskRunner::CompleteTask(result.task.get());
// Note that here, everything is reffed, but a new task is created. This is
// possible with repeated schedule/cancel operations.
- scoped_refptr<TileTask> third_task;
- need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &third_task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(third_task);
- EXPECT_FALSE(third_task.get() == task.get());
+ ImageDecodeCache::TaskResult third_result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(third_result.need_unref);
+ EXPECT_TRUE(third_result.task);
+ EXPECT_FALSE(third_result.task.get() == result.task.get());
- TestTileTaskRunner::ProcessTask(third_task.get());
+ TestTileTaskRunner::ProcessTask(third_result.task.get());
- // 3 Unrefs!
+ // 3 Unrefs!!!
cache.UnrefImage(draw_image);
cache.UnrefImage(draw_image);
cache.UnrefImage(draw_image);
@@ -989,14 +968,13 @@ TEST(SoftwareImageDecodeCacheTest, GetDecodedImageForDraw) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1024,14 +1002,13 @@ TEST(SoftwareImageDecodeCacheTest,
paint_image,
SkIRect::MakeXYWH(20, 30, paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1057,7 +1034,7 @@ TEST(SoftwareImageDecodeCacheTest, GetDecodedImageForDrawAtRasterDecode) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1083,7 +1060,7 @@ TEST(SoftwareImageDecodeCacheTest,
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1115,7 +1092,7 @@ TEST(SoftwareImageDecodeCacheTest,
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1128,13 +1105,12 @@ TEST(SoftwareImageDecodeCacheTest,
EXPECT_FALSE(decoded_draw_image.is_scale_adjustment_identity());
EXPECT_TRUE(decoded_draw_image.is_at_raster_decode());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DecodedDrawImage another_decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1161,7 +1137,7 @@ TEST(SoftwareImageDecodeCacheTest,
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1174,17 +1150,16 @@ TEST(SoftwareImageDecodeCacheTest,
EXPECT_FALSE(decoded_draw_image.is_scale_adjustment_identity());
EXPECT_TRUE(decoded_draw_image.is_at_raster_decode());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
// If we finish the draw here, then we will use it for the locked decode
// instead of decoding again.
cache.DrawWithImageFinished(draw_image, decoded_draw_image);
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DecodedDrawImage another_decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1207,13 +1182,12 @@ TEST(SoftwareImageDecodeCacheTest, ZeroSizedImagesAreSkipped) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.f, 0.f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_FALSE(task);
- EXPECT_FALSE(need_unref);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_FALSE(result.task);
+ EXPECT_FALSE(result.need_unref);
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1232,13 +1206,12 @@ TEST(SoftwareImageDecodeCacheTest, NonOverlappingSrcRectImagesAreSkipped) {
paint_image,
SkIRect::MakeXYWH(150, 150, paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_FALSE(task);
- EXPECT_FALSE(need_unref);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_FALSE(result.task);
+ EXPECT_FALSE(result.need_unref);
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1256,15 +1229,14 @@ TEST(SoftwareImageDecodeCacheTest, LowQualityFilterIsHandled) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(task);
- EXPECT_TRUE(need_unref);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.task);
+ EXPECT_TRUE(result.need_unref);
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1285,15 +1257,14 @@ TEST(SoftwareImageDecodeCacheTest, LowQualityScaledSubrectIsHandled) {
PaintImage paint_image = CreatePaintImage(100, 100);
DrawImage draw_image(paint_image, SkIRect::MakeXYWH(10, 10, 80, 80), quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(task);
- EXPECT_TRUE(need_unref);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.task);
+ EXPECT_TRUE(result.need_unref);
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1319,15 +1290,14 @@ TEST(SoftwareImageDecodeCacheTest, NoneQualityScaledSubrectIsHandled) {
PaintImage paint_image = CreatePaintImage(100, 100);
DrawImage draw_image(paint_image, SkIRect::MakeXYWH(10, 10, 80, 80), quality,
CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(task);
- EXPECT_TRUE(need_unref);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.task);
+ EXPECT_TRUE(result.need_unref);
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1351,15 +1321,14 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt01_5ScaleIsHandled) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(task);
- EXPECT_TRUE(need_unref);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.task);
+ EXPECT_TRUE(result.need_unref);
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1383,15 +1352,14 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt1_0ScaleIsHandled) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(task);
- EXPECT_TRUE(need_unref);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.task);
+ EXPECT_TRUE(result.need_unref);
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1415,15 +1383,14 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt0_75ScaleIsHandled) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.75f, 0.75f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(task);
- EXPECT_TRUE(need_unref);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.task);
+ EXPECT_TRUE(result.need_unref);
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1447,15 +1414,14 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt0_5ScaleIsHandled) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(task);
- EXPECT_TRUE(need_unref);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.task);
+ EXPECT_TRUE(result.need_unref);
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1479,15 +1445,14 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt0_49ScaleIsHandled) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.49f, 0.49f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(task);
- EXPECT_TRUE(need_unref);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.task);
+ EXPECT_TRUE(result.need_unref);
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1511,15 +1476,14 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt0_1ScaleIsHandled) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.1f, 0.1f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(task);
- EXPECT_TRUE(need_unref);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.task);
+ EXPECT_TRUE(result.need_unref);
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1543,15 +1507,14 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt0_01ScaleIsHandled) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.01f, 0.01f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(task);
- EXPECT_TRUE(need_unref);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.task);
+ EXPECT_TRUE(result.need_unref);
- TestTileTaskRunner::ProcessTask(task.get());
+ TestTileTaskRunner::ProcessTask(result.task.get());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1575,13 +1538,12 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt0_001ScaleIsHandled) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.001f, 0.001f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_FALSE(task);
- EXPECT_FALSE(need_unref);
+ ImageDecodeCache::TaskResult result =
+ cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_FALSE(result.task);
+ EXPECT_FALSE(result.need_unref);
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
@@ -1600,24 +1562,22 @@ TEST(SoftwareImageDecodeCacheTest,
DrawImage draw_image_50(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
DrawImage draw_image_49(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(0.49f, 0.49f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
- scoped_refptr<TileTask> task_50;
- bool need_unref_50 = cache.GetTaskForImageAndRef(
- draw_image_50, ImageDecodeCache::TracingInfo(), &task_50);
- EXPECT_TRUE(task_50);
- EXPECT_TRUE(need_unref_50);
- scoped_refptr<TileTask> task_49;
- bool need_unref_49 = cache.GetTaskForImageAndRef(
- draw_image_49, ImageDecodeCache::TracingInfo(), &task_49);
- EXPECT_TRUE(task_49);
- EXPECT_TRUE(need_unref_49);
+ ImageDecodeCache::TaskResult result_50 = cache.GetTaskForImageAndRef(
+ draw_image_50, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result_50.task);
+ EXPECT_TRUE(result_50.need_unref);
+ ImageDecodeCache::TaskResult result_49 = cache.GetTaskForImageAndRef(
+ draw_image_49, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result_49.task);
+ EXPECT_TRUE(result_49.need_unref);
- TestTileTaskRunner::ProcessTask(task_49.get());
+ TestTileTaskRunner::ProcessTask(result_49.task.get());
DecodedDrawImage decoded_draw_image_50 =
cache.GetDecodedImageForDraw(draw_image_50);
@@ -1653,13 +1613,12 @@ TEST(SoftwareImageDecodeCacheTest, ClearCache) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
- TestTileTaskRunner::ProcessTask(task.get());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
+ ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(
+ draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.UnrefImage(draw_image);
}
@@ -1683,16 +1642,15 @@ TEST(SoftwareImageDecodeCacheTest, RemoveUnusedImage) {
DrawImage draw_image(
paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()),
quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
- DefaultColorSpace());
+ PaintImage::kDefaultFrameIndex, DefaultColorSpace());
frame_keys.push_back(draw_image.frame_key());
DecodedDrawImage decoded_draw_image =
cache.GetDecodedImageForDraw(draw_image);
- scoped_refptr<TileTask> task;
- bool need_unref = cache.GetTaskForImageAndRef(
- draw_image, ImageDecodeCache::TracingInfo(), &task);
- EXPECT_TRUE(need_unref);
- EXPECT_TRUE(task);
- TestTileTaskRunner::ProcessTask(task.get());
+ ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(
+ draw_image, ImageDecodeCache::TracingInfo());
+ EXPECT_TRUE(result.need_unref);
+ EXPECT_TRUE(result.task);
+ TestTileTaskRunner::ProcessTask(result.task.get());
cache.DrawWithImageFinished(draw_image, decoded_draw_image);
cache.UnrefImage(draw_image);
}
@@ -1707,5 +1665,58 @@ TEST(SoftwareImageDecodeCacheTest, RemoveUnusedImage) {
}
}
+TEST(SoftwareImageDecodeCacheTest, CacheDecodesExpectedFrames) {
+ TestSoftwareImageDecodeCache cache;
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(4)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(5)),
+ };
+ sk_sp<FakePaintImageGenerator> generator =
+ sk_make_sp<FakePaintImageGenerator>(
+ SkImageInfo::MakeN32Premul(10, 10, SkColorSpace::MakeSRGB()), frames);
+ PaintImage image = PaintImageBuilder::WithDefault()
+ .set_id(PaintImage::GetNextId())
+ .set_paint_image_generator(generator)
+ .set_frame_index(0u)
+ .TakePaintImage();
+
+ bool is_decomposable = true;
+ SkFilterQuality quality = kHigh_SkFilterQuality;
+ DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()),
+ quality,
+ CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable),
+ 1u, DefaultColorSpace());
+ auto decoded_image = cache.GetDecodedImageForDraw(draw_image);
+ ASSERT_TRUE(decoded_image.image());
+ ASSERT_EQ(generator->frames_decoded().size(), 1u);
+ EXPECT_EQ(generator->frames_decoded().count(1u), 1u);
+ generator->reset_frames_decoded();
+ cache.DrawWithImageFinished(draw_image, decoded_image);
+
+ // Scaled.
+ DrawImage scaled_draw_image(draw_image, 0.5f, 2u,
+ draw_image.target_color_space());
+ decoded_image = cache.GetDecodedImageForDraw(scaled_draw_image);
+ ASSERT_TRUE(decoded_image.image());
+ ASSERT_EQ(generator->frames_decoded().size(), 1u);
+ EXPECT_EQ(generator->frames_decoded().count(2u), 1u);
+ generator->reset_frames_decoded();
+ cache.DrawWithImageFinished(scaled_draw_image, decoded_image);
+
+ // Subset.
+ DrawImage subset_draw_image(
+ image, SkIRect::MakeWH(5, 5), quality,
+ CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), 3u,
+ DefaultColorSpace());
+ decoded_image = cache.GetDecodedImageForDraw(subset_draw_image);
+ ASSERT_TRUE(decoded_image.image());
+ ASSERT_EQ(generator->frames_decoded().size(), 1u);
+ EXPECT_EQ(generator->frames_decoded().count(3u), 1u);
+ generator->reset_frames_decoded();
+ cache.DrawWithImageFinished(subset_draw_image, decoded_image);
+}
+
} // namespace
} // namespace cc
diff --git a/chromium/cc/tiles/tile_manager.cc b/chromium/cc/tiles/tile_manager.cc
index 8b916dea259..007fff3b0fb 100644
--- a/chromium/cc/tiles/tile_manager.cc
+++ b/chromium/cc/tiles/tile_manager.cc
@@ -242,7 +242,7 @@ void InsertNodeForDecodeTask(TaskGraph* graph,
if (!dependency->HasCompleted()) {
InsertNodeForDecodeTask(graph, dependency, use_foreground_category,
priority);
- graph->edges.push_back(TaskGraph::Edge(dependency, task));
+ graph->edges.emplace_back(dependency, task);
dependency_count = 1u;
}
}
@@ -293,7 +293,7 @@ void InsertNodesForRasterTask(TaskGraph* graph,
priority);
}
- graph->edges.push_back(TaskGraph::Edge(decode_task, raster_task));
+ graph->edges.emplace_back(decode_task, raster_task);
}
InsertNodeForTask(
@@ -883,7 +883,8 @@ void TileManager::PartitionImagesForCheckering(
const PrioritizedTile& prioritized_tile,
const gfx::ColorSpace& raster_color_space,
std::vector<DrawImage>* sync_decoded_images,
- std::vector<PaintImage>* checkered_images) {
+ std::vector<PaintImage>* checkered_images,
+ base::flat_map<PaintImage::Id, size_t>* image_to_frame_index) {
Tile* tile = prioritized_tile.tile();
std::vector<const DrawImage*> images_in_tile;
prioritized_tile.raster_source()->GetDiscardableImagesInRect(
@@ -891,10 +892,18 @@ void TileManager::PartitionImagesForCheckering(
WhichTree tree = tile->tiling()->tree();
for (const auto* original_draw_image : images_in_tile) {
+ size_t frame_index = original_draw_image->paint_image().frame_index();
+ if (tile_manager_settings_.enable_image_animations) {
+ const auto& image = original_draw_image->paint_image();
+ frame_index = client_->GetFrameIndexForImage(image, tree);
+ if (image_to_frame_index) {
+ (*image_to_frame_index)[image.stable_id()] = frame_index;
+ }
+ }
+
DrawImage draw_image(*original_draw_image, tile->raster_transform().scale(),
- raster_color_space);
- if (checker_image_tracker_.ShouldCheckerImage(
- draw_image, tree, tile->required_for_activation()))
+ frame_index, raster_color_space);
+ if (checker_image_tracker_.ShouldCheckerImage(draw_image, tree))
checkered_images->push_back(draw_image.paint_image());
else
sync_decoded_images->push_back(std::move(draw_image));
@@ -913,12 +922,15 @@ void TileManager::AddCheckeredImagesToDecodeQueue(
WhichTree tree = tile->tiling()->tree();
for (const auto* original_draw_image : images_in_tile) {
+ size_t frame_index = original_draw_image->paint_image().frame_index();
+ if (tile_manager_settings_.enable_image_animations) {
+ frame_index = client_->GetFrameIndexForImage(
+ original_draw_image->paint_image(), tree);
+ }
DrawImage draw_image(*original_draw_image, tile->raster_transform().scale(),
- raster_color_space);
- if (checker_image_tracker_.ShouldCheckerImage(
- draw_image, tree, tile->required_for_activation())) {
- image_decode_queue->push_back(CheckerImageTracker::ImageDecodeRequest(
- draw_image.paint_image(), decode_type));
+ frame_index, raster_color_space);
+ if (checker_image_tracker_.ShouldCheckerImage(draw_image, tree)) {
+ image_decode_queue->emplace_back(draw_image.paint_image(), decode_type);
}
}
}
@@ -978,16 +990,14 @@ void TileManager::ScheduleTasks(PrioritizedWorkToSchedule work_to_schedule) {
if (tile->required_for_activation()) {
required_for_activate_count++;
- graph_.edges.push_back(
- TaskGraph::Edge(task, required_for_activation_done_task.get()));
+ graph_.edges.emplace_back(task, required_for_activation_done_task.get());
}
if (tile->required_for_draw()) {
required_for_draw_count++;
- graph_.edges.push_back(
- TaskGraph::Edge(task, required_for_draw_done_task.get()));
+ graph_.edges.emplace_back(task, required_for_draw_done_task.get());
}
all_count++;
- graph_.edges.push_back(TaskGraph::Edge(task, all_done_task.get()));
+ graph_.edges.emplace_back(task, all_done_task.get());
// A tile should use a foreground task cateogry if it is either blocking
// future compositing (required for draw or required for activation), or if
@@ -1017,9 +1027,8 @@ void TileManager::ScheduleTasks(PrioritizedWorkToSchedule work_to_schedule) {
// For checkered-images, send them to the decode service.
for (auto& image : checkered_images) {
- work_to_schedule.checker_image_decode_queue.push_back(
- CheckerImageTracker::ImageDecodeRequest(
- std::move(image), CheckerImageTracker::DecodeType::kPreDecode));
+ work_to_schedule.checker_image_decode_queue.emplace_back(
+ std::move(image), CheckerImageTracker::DecodeType::kPreDecode);
}
}
@@ -1043,7 +1052,7 @@ void TileManager::ScheduleTasks(PrioritizedWorkToSchedule work_to_schedule) {
InsertNodeForDecodeTask(&graph_, task.get(), false, priority++);
all_count++;
- graph_.edges.push_back(TaskGraph::Edge(task.get(), all_done_task.get()));
+ graph_.edges.emplace_back(task.get(), all_done_task.get());
}
// The old locked images tasks have to stay around until past the
@@ -1136,11 +1145,15 @@ scoped_refptr<TileTask> TileManager::CreateRasterTask(
scheduled_draw_images_[tile->id()];
sync_decoded_images.clear();
PaintImageIdFlatSet images_to_skip;
+ base::flat_map<PaintImage::Id, size_t> image_id_to_current_frame_index;
if (!skip_images) {
std::vector<PaintImage> checkered_images;
PartitionImagesForCheckering(prioritized_tile, color_space,
- &sync_decoded_images, &checkered_images);
+ &sync_decoded_images, &checkered_images,
+ &image_id_to_current_frame_index);
for (const auto& image : checkered_images) {
+ DCHECK(!image.ShouldAnimate());
+
images_to_skip.insert(image.stable_id());
// This can be the case for tiles on the active tree that will be replaced
@@ -1148,9 +1161,8 @@ scoped_refptr<TileTask> TileManager::CreateRasterTask(
// skipping images for these tiles, we don't need to decode them since
// they will not be required on the next active tree.
if (prioritized_tile.should_decode_checkered_images_for_tile()) {
- checker_image_decode_queue->push_back(
- CheckerImageTracker::ImageDecodeRequest(
- image, CheckerImageTracker::DecodeType::kRaster));
+ checker_image_decode_queue->emplace_back(
+ image, CheckerImageTracker::DecodeType::kRaster);
}
}
}
@@ -1164,25 +1176,37 @@ scoped_refptr<TileTask> TileManager::CreateRasterTask(
ImageDecodeCache::TracingInfo tracing_info(
prepare_tiles_count_, prioritized_tile.priority().priority_bin,
ImageDecodeCache::TaskType::kInRaster);
- image_controller_.GetTasksForImagesAndRef(&sync_decoded_images, &decode_tasks,
- tracing_info);
+ std::vector<DrawImage> at_raster_images;
+ image_controller_.GetTasksForImagesAndRef(
+ &sync_decoded_images, &at_raster_images, &decode_tasks, tracing_info);
std::unique_ptr<RasterBuffer> raster_buffer =
raster_buffer_provider_->AcquireBufferForRaster(
resource, resource_content_id, tile->invalidated_id());
base::Optional<PlaybackImageProvider> image_provider;
- const bool has_predecoded_images = !sync_decoded_images.empty();
- if (skip_images || has_checker_images || has_predecoded_images) {
- image_provider.emplace(skip_images, std::move(images_to_skip),
- image_controller_.cache(), color_space);
+ const bool has_sync_decoded_images = !sync_decoded_images.empty();
+ const bool has_at_raster_images = !at_raster_images.empty();
+ if (skip_images || has_checker_images || has_sync_decoded_images ||
+ has_at_raster_images) {
+ base::Optional<PlaybackImageProvider::Settings> settings;
+ if (!skip_images) {
+ settings.emplace();
+ settings->images_to_skip = std::move(images_to_skip);
+ settings->at_raster_images = std::move(at_raster_images);
+ settings->image_to_current_frame_index =
+ std::move(image_id_to_current_frame_index);
+ }
+
+ image_provider.emplace(image_controller_.cache(), color_space,
+ std::move(settings));
}
- return make_scoped_refptr(new RasterTaskImpl(
+ return base::MakeRefCounted<RasterTaskImpl>(
this, tile, resource, prioritized_tile.raster_source(), playback_settings,
prioritized_tile.priority().resolution, invalidated_rect,
prepare_tiles_count_, std::move(raster_buffer), &decode_tasks,
- use_gpu_rasterization_, std::move(image_provider)));
+ use_gpu_rasterization_, std::move(image_provider));
}
void TileManager::ResetSignalsForTesting() {
@@ -1211,6 +1235,11 @@ void TileManager::OnRasterTaskCompleted(
// Unref all the images.
auto images_it = scheduled_draw_images_.find(tile_id);
+ // Every raster task unconditionally creates sync_decoded_images_ entry in
+ // CreateRasterTask. This is the only place it's cleared. So we should have
+ // the images_it here that doesn't point to end. This check is here to debug
+ // crbug.com/757049.
+ CHECK(images_it != scheduled_draw_images_.end());
image_controller_.UnrefImages(images_it->second);
scheduled_draw_images_.erase(images_it);
@@ -1582,9 +1611,9 @@ void TileManager::CheckPendingGpuWorkTiles(bool issue_signals, bool flush) {
// posts |callback| to |task_runner| when run.
scoped_refptr<TileTask> TileManager::CreateTaskSetFinishedTask(
void (TileManager::*callback)()) {
- return make_scoped_refptr(new TaskSetFinishedTaskImpl(
+ return base::MakeRefCounted<TaskSetFinishedTaskImpl>(
task_runner_,
- base::Bind(callback, task_set_finished_weak_ptr_factory_.GetWeakPtr())));
+ base::Bind(callback, task_set_finished_weak_ptr_factory_.GetWeakPtr()));
}
std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
diff --git a/chromium/cc/tiles/tile_manager.h b/chromium/cc/tiles/tile_manager.h
index d9a7cbfdfef..58de5f05f0e 100644
--- a/chromium/cc/tiles/tile_manager.h
+++ b/chromium/cc/tiles/tile_manager.h
@@ -87,6 +87,9 @@ class CC_EXPORT TileManagerClient {
// rasterized with missing images need to be invalidated.
virtual void RequestImplSideInvalidationForCheckerImagedTiles() = 0;
+ virtual size_t GetFrameIndexForImage(const PaintImage& paint_image,
+ WhichTree tree) const = 0;
+
protected:
virtual ~TileManagerClient() {}
};
@@ -357,10 +360,12 @@ class CC_EXPORT TileManager : CheckerImageTrackerClient {
PrioritizedWorkToSchedule AssignGpuMemoryToTiles();
void ScheduleTasks(PrioritizedWorkToSchedule work_to_schedule);
- void PartitionImagesForCheckering(const PrioritizedTile& prioritized_tile,
- const gfx::ColorSpace& raster_color_space,
- std::vector<DrawImage>* sync_decoded_images,
- std::vector<PaintImage>* checkered_images);
+ void PartitionImagesForCheckering(
+ const PrioritizedTile& prioritized_tile,
+ const gfx::ColorSpace& raster_color_space,
+ std::vector<DrawImage>* sync_decoded_images,
+ std::vector<PaintImage>* checkered_images,
+ base::flat_map<PaintImage::Id, size_t>* image_to_frame_index = nullptr);
void AddCheckeredImagesToDecodeQueue(
const PrioritizedTile& prioritized_tile,
const gfx::ColorSpace& raster_color_space,
diff --git a/chromium/cc/tiles/tile_manager_settings.h b/chromium/cc/tiles/tile_manager_settings.h
index 6a7f7fb1f0c..7a3d158af07 100644
--- a/chromium/cc/tiles/tile_manager_settings.h
+++ b/chromium/cc/tiles/tile_manager_settings.h
@@ -13,6 +13,7 @@ struct CC_EXPORT TileManagerSettings {
bool use_partial_raster = false;
bool enable_checker_imaging = false;
size_t min_image_bytes_to_checker = 1 * 1024 * 1024;
+ bool enable_image_animations = false;
};
} // namespace cc
diff --git a/chromium/cc/tiles/tile_manager_unittest.cc b/chromium/cc/tiles/tile_manager_unittest.cc
index 3834ba3e48f..7c319683256 100644
--- a/chromium/cc/tiles/tile_manager_unittest.cc
+++ b/chromium/cc/tiles/tile_manager_unittest.cc
@@ -22,6 +22,7 @@
#include "cc/test/fake_layer_tree_frame_sink.h"
#include "cc/test/fake_layer_tree_frame_sink_client.h"
#include "cc/test/fake_layer_tree_host_impl.h"
+#include "cc/test/fake_paint_image_generator.h"
#include "cc/test/fake_picture_layer_impl.h"
#include "cc/test/fake_picture_layer_tiling_client.h"
#include "cc/test/fake_raster_source.h"
@@ -29,7 +30,6 @@
#include "cc/test/fake_tile_manager.h"
#include "cc/test/fake_tile_task_manager.h"
#include "cc/test/skia_common.h"
-#include "cc/test/stub_paint_image_generator.h"
#include "cc/test/test_layer_tree_host_base.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/test/test_tile_priorities.h"
@@ -58,7 +58,7 @@ namespace {
// posted should run synchronously.
class SynchronousSimpleTaskRunner : public base::TestSimpleTaskRunner {
public:
- bool PostDelayedTask(const tracked_objects::Location& from_here,
+ bool PostDelayedTask(const base::Location& from_here,
base::OnceClosure task,
base::TimeDelta delay) override {
TestSimpleTaskRunner::PostDelayedTask(from_here, std::move(task), delay);
@@ -67,7 +67,7 @@ class SynchronousSimpleTaskRunner : public base::TestSimpleTaskRunner {
return true;
}
- bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
+ bool PostNonNestableDelayedTask(const base::Location& from_here,
base::OnceClosure task,
base::TimeDelta delay) override {
return PostDelayedTask(from_here, std::move(task), delay);
@@ -2307,10 +2307,10 @@ TEST_F(TileManagerReadyToDrawTest, ReadyToDrawRespectsRequirementChange) {
class CheckerImagingTileManagerTest : public TestLayerTreeHostBase {
public:
- class MockImageGenerator : public StubPaintImageGenerator {
+ class MockImageGenerator : public FakePaintImageGenerator {
public:
explicit MockImageGenerator(const gfx::Size& size)
- : StubPaintImageGenerator(
+ : FakePaintImageGenerator(
SkImageInfo::MakeN32Premul(size.width(), size.height())) {}
MOCK_METHOD5(GetPixels,
@@ -2337,7 +2337,7 @@ class CheckerImagingTileManagerTest : public TestLayerTreeHostBase {
const LayerTreeSettings& settings,
TaskRunnerProvider* task_runner_provider,
TaskGraphRunner* task_graph_runner) override {
- task_runner_ = make_scoped_refptr(new SynchronousSimpleTaskRunner);
+ task_runner_ = base::MakeRefCounted<SynchronousSimpleTaskRunner>();
return std::make_unique<FakeLayerTreeHostImpl>(
settings, task_runner_provider, task_graph_runner, task_runner_);
}
@@ -2374,7 +2374,7 @@ TEST_F(CheckerImagingTileManagerTest,
auto generator =
sk_make_sp<testing::StrictMock<MockImageGenerator>>(gfx::Size(512, 512));
- PaintImage image = PaintImageBuilder()
+ PaintImage image = PaintImageBuilder::WithDefault()
.set_id(PaintImage::GetNextId())
.set_paint_image_generator(generator)
.TakePaintImage();
diff --git a/chromium/cc/trees/DEPS b/chromium/cc/trees/DEPS
deleted file mode 100644
index 5d5a5f6a7cf..00000000000
--- a/chromium/cc/trees/DEPS
+++ /dev/null
@@ -1,5 +0,0 @@
-specific_include_rules = {
- ".*_unittest\.cc": [
- "+components/viz/service/display",
- ]
-}
diff --git a/chromium/cc/trees/blocking_task_runner.cc b/chromium/cc/trees/blocking_task_runner.cc
deleted file mode 100644
index b6c8a49a3b8..00000000000
--- a/chromium/cc/trees/blocking_task_runner.cc
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/trees/blocking_task_runner.h"
-
-#include <stddef.h>
-
-#include <utility>
-
-#include "base/callback.h"
-#include "base/logging.h"
-#include "base/memory/ptr_util.h"
-
-namespace cc {
-
-// static
-std::unique_ptr<BlockingTaskRunner> BlockingTaskRunner::Create(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
- return base::WrapUnique(new BlockingTaskRunner(task_runner));
-}
-
-BlockingTaskRunner::BlockingTaskRunner(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner)
- : thread_id_(base::PlatformThread::CurrentId()),
- task_runner_(task_runner),
- capture_(0) {
-}
-
-BlockingTaskRunner::~BlockingTaskRunner() {}
-
-bool BlockingTaskRunner::BelongsToCurrentThread() {
- return base::PlatformThread::CurrentId() == thread_id_;
-}
-
-bool BlockingTaskRunner::PostTask(const tracked_objects::Location& from_here,
- base::OnceClosure task) {
- base::AutoLock lock(lock_);
- DCHECK(task_runner_.get() || capture_);
- if (!capture_)
- return task_runner_->PostTask(from_here, std::move(task));
- captured_tasks_.push_back(std::move(task));
- return true;
-}
-
-void BlockingTaskRunner::SetCapture(bool capture) {
- DCHECK(BelongsToCurrentThread());
-
- std::vector<base::OnceClosure> tasks;
-
- {
- base::AutoLock lock(lock_);
- capture_ += capture ? 1 : -1;
- DCHECK_GE(capture_, 0);
-
- if (capture_)
- return;
-
- // We're done capturing, so grab all the captured tasks and run them.
- tasks.swap(captured_tasks_);
- }
- for (size_t i = 0; i < tasks.size(); ++i)
- std::move(tasks[i]).Run();
-}
-
-BlockingTaskRunner::CapturePostTasks::CapturePostTasks(
- BlockingTaskRunner* blocking_runner)
- : blocking_runner_(blocking_runner) {
- blocking_runner_->SetCapture(true);
-}
-
-BlockingTaskRunner::CapturePostTasks::~CapturePostTasks() {
- blocking_runner_->SetCapture(false);
-}
-
-} // namespace cc
diff --git a/chromium/cc/trees/blocking_task_runner.h b/chromium/cc/trees/blocking_task_runner.h
deleted file mode 100644
index 25d227a6b15..00000000000
--- a/chromium/cc/trees/blocking_task_runner.h
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_TREES_BLOCKING_TASK_RUNNER_H_
-#define CC_TREES_BLOCKING_TASK_RUNNER_H_
-
-#include <memory>
-#include <vector>
-
-#include "base/location.h"
-#include "base/macros.h"
-#include "base/single_thread_task_runner.h"
-#include "base/synchronization/lock.h"
-#include "base/threading/platform_thread.h"
-#include "cc/cc_export.h"
-
-namespace cc {
-
-// This class wraps a SingleThreadTaskRunner but allows posted tasks to be
-// run without a round trip through the message loop. This shortcutting
-// removes guarantees about ordering. Tasks posted while the
-// BlockingTaskRunner is in a capturing state will run in order, and tasks
-// posted while the BlockingTaskRunner is /not/ in a capturing state will
-// run in order, but the two sets of tasks will *not* run in order relative
-// to when they were posted.
-//
-// To use this class, post tasks to the task runner returned by
-// BlockingTaskRunner::Create(). The thread it is created on identifies the
-// thread you want the tasks to run on. The SingleThreadTaskRunner which is
-// passed into Create() is used to run tasks that are posted when not in a
-// capturing state.
-//
-// Then, on the thread that the given task runner belongs to, you may
-// instantiate a BlockingTaskRunner::CapturePostTasks. While this object
-// exists, the task runner will collect any PostTasks called on it, posting
-// tasks to that thread from anywhere. This CapturePostTasks object provides
-// a window in time where tasks can shortcut past the MessageLoop. As soon
-// as the CapturePostTasks object is destroyed (goes out of scope), all
-// tasks that had been posted to the thread during the window will be executed
-// immediately.
-//
-// Beware of re-entrancy, make sure the CapturePostTasks object is destroyed at
-// a time when it makes sense for the embedder to call arbitrary things.
-class CC_EXPORT BlockingTaskRunner {
- public:
- // Creates a BlockingTaskRunner for a given SingleThreadTaskRunner.
- // |task_runner| will be used to run the tasks which are posted while we are
- // not capturing. |task_runner| should belong to same the thread on which
- // capturing is done.
- static std::unique_ptr<BlockingTaskRunner> Create(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner);
-
- ~BlockingTaskRunner();
-
- // While an object of this type is held alive on a thread, any tasks
- // posted to the thread will be captured and run as soon as the object
- // is destroyed, shortcutting past the task runner.
- class CC_EXPORT CapturePostTasks {
- public:
- explicit CapturePostTasks(BlockingTaskRunner* blocking_runner);
- ~CapturePostTasks();
-
- private:
- BlockingTaskRunner* blocking_runner_;
-
- DISALLOW_COPY_AND_ASSIGN(CapturePostTasks);
- };
-
- // True if tasks posted to the BlockingTaskRunner will run on the current
- // thread.
- bool BelongsToCurrentThread();
-
- // Posts a task using the contained SingleThreadTaskRunner unless |capture_|
- // is true. When |capture_| is true, tasks posted will be caught and stored
- // until the capturing stops. At that time the tasks will be run directly
- // instead of being posted to the SingleThreadTaskRunner.
- bool PostTask(const tracked_objects::Location& from_here,
- base::OnceClosure task);
-
- private:
- explicit BlockingTaskRunner(
- scoped_refptr<base::SingleThreadTaskRunner> task_runner);
-
- void SetCapture(bool capture);
-
- base::PlatformThreadId thread_id_;
- scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
-
- base::Lock lock_;
- int capture_;
- std::vector<base::OnceClosure> captured_tasks_;
-
- DISALLOW_COPY_AND_ASSIGN(BlockingTaskRunner);
-};
-
-} // namespace cc
-
-#endif // CC_TREES_BLOCKING_TASK_RUNNER_H_
diff --git a/chromium/cc/trees/blocking_task_runner_unittest.cc b/chromium/cc/trees/blocking_task_runner_unittest.cc
deleted file mode 100644
index 78a3707ba16..00000000000
--- a/chromium/cc/trees/blocking_task_runner_unittest.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "cc/trees/blocking_task_runner.h"
-
-#include "base/bind.h"
-#include "base/location.h"
-#include "base/run_loop.h"
-#include "base/single_thread_task_runner.h"
-#include "base/threading/thread_task_runner_handle.h"
-#include "components/viz/test/ordered_simple_task_runner.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace cc {
-namespace {
-
-void TestTask(bool* result) {
- *result = true;
-}
-
-TEST(BlockingTaskRunnerTest, NoCapture) {
- bool did_run = false;
- std::unique_ptr<BlockingTaskRunner> runner(
- BlockingTaskRunner::Create(base::ThreadTaskRunnerHandle::Get()));
- runner->PostTask(FROM_HERE, base::Bind(&TestTask, &did_run));
- EXPECT_FALSE(did_run);
- base::RunLoop().RunUntilIdle();
- EXPECT_TRUE(did_run);
-}
-
-TEST(BlockingTaskRunnerTest, Capture) {
- bool did_run = false;
- std::unique_ptr<BlockingTaskRunner> runner(
- BlockingTaskRunner::Create(base::ThreadTaskRunnerHandle::Get()));
- {
- BlockingTaskRunner::CapturePostTasks capture(runner.get());
- runner->PostTask(FROM_HERE, base::Bind(&TestTask, &did_run));
- EXPECT_FALSE(did_run);
- }
- EXPECT_TRUE(did_run);
-}
-
-} // namespace
-} // namespace cc
diff --git a/chromium/cc/trees/clip_node.cc b/chromium/cc/trees/clip_node.cc
index aed37464b99..a949dcb9728 100644
--- a/chromium/cc/trees/clip_node.cc
+++ b/chromium/cc/trees/clip_node.cc
@@ -18,51 +18,16 @@ ClipNode::ClipNode()
transform_id(TransformTree::kInvalidNodeId) {
}
-ClipNode::ClipNode(const ClipNode& other)
- : id(other.id),
- parent_id(other.parent_id),
- clip_type(other.clip_type),
- clip(other.clip),
- transform_id(other.transform_id) {
- if (other.clip_expander) {
- DCHECK_EQ(clip_type, ClipType::EXPANDS_CLIP);
- clip_expander = std::make_unique<ClipExpander>(*other.clip_expander);
- }
- cached_clip_rects = other.cached_clip_rects;
- cached_accumulated_rect_in_screen_space =
- other.cached_accumulated_rect_in_screen_space;
-}
-
-ClipNode& ClipNode::operator=(const ClipNode& other) {
- id = other.id;
- parent_id = other.parent_id;
- clip_type = other.clip_type;
- clip = other.clip;
- transform_id = other.transform_id;
+ClipNode::ClipNode(const ClipNode& other) = default;
- if (other.clip_expander) {
- DCHECK_EQ(clip_type, ClipType::EXPANDS_CLIP);
- clip_expander = std::make_unique<ClipExpander>(*other.clip_expander);
- } else {
- clip_expander.reset();
- }
- cached_clip_rects = other.cached_clip_rects;
- cached_accumulated_rect_in_screen_space =
- other.cached_accumulated_rect_in_screen_space;
- return *this;
-}
+ClipNode& ClipNode::operator=(const ClipNode& other) = default;
ClipNode::~ClipNode() {}
bool ClipNode::operator==(const ClipNode& other) const {
- if (clip_expander && other.clip_expander &&
- *clip_expander != *other.clip_expander)
- return false;
- if ((clip_expander && !other.clip_expander) ||
- (!clip_expander && other.clip_expander))
- return false;
return id == other.id && parent_id == other.parent_id &&
clip_type == other.clip_type && clip == other.clip &&
+ clip_expander == other.clip_expander &&
transform_id == other.transform_id;
}
diff --git a/chromium/cc/trees/clip_node.h b/chromium/cc/trees/clip_node.h
index 506b4932873..5620f9d020c 100644
--- a/chromium/cc/trees/clip_node.h
+++ b/chromium/cc/trees/clip_node.h
@@ -5,9 +5,8 @@
#ifndef CC_TREES_CLIP_NODE_H_
#define CC_TREES_CLIP_NODE_H_
-#include <memory>
-
#include "base/containers/stack_container.h"
+#include "base/optional.h"
#include "cc/cc_export.h"
#include "cc/trees/clip_expander.h"
#include "ui/gfx/geometry/rect_f.h"
@@ -66,7 +65,7 @@ struct CC_EXPORT ClipNode {
gfx::RectF cached_accumulated_rect_in_screen_space;
// For nodes that expand, this represents the amount of expansion.
- std::unique_ptr<ClipExpander> clip_expander;
+ base::Optional<ClipExpander> clip_expander;
// The id of the transform node that defines the clip node's local space.
int transform_id;
diff --git a/chromium/cc/trees/debug_rect_history.cc b/chromium/cc/trees/debug_rect_history.cc
index 41960510cac..aa99eb55db3 100644
--- a/chromium/cc/trees/debug_rect_history.cc
+++ b/chromium/cc/trees/debug_rect_history.cc
@@ -10,7 +10,6 @@
#include "cc/base/math_util.h"
#include "cc/layers/layer_impl.h"
#include "cc/layers/layer_list_iterator.h"
-#include "cc/layers/layer_utils.h"
#include "cc/layers/render_surface_impl.h"
#include "cc/trees/damage_tracker.h"
#include "cc/trees/layer_tree_host.h"
@@ -61,9 +60,6 @@ void DebugRectHistory::SaveDebugRectsForCurrentFrame(
if (debug_state.show_screen_space_rects)
SaveScreenSpaceRects(render_surface_list);
-
- if (debug_state.show_layer_animation_bounds_rects)
- SaveLayerAnimationBoundsRects(tree_impl);
}
void DebugRectHistory::SavePaintRects(LayerTreeImpl* tree_impl) {
@@ -200,23 +196,4 @@ void DebugRectHistory::SaveNonFastScrollableRectsCallback(LayerImpl* layer) {
}
}
-void DebugRectHistory::SaveLayerAnimationBoundsRects(LayerTreeImpl* tree_impl) {
- for (auto it = tree_impl->rbegin(); it != tree_impl->rend(); ++it) {
- if (!(*it)->contributes_to_drawn_render_surface())
- continue;
-
- // TODO(avallee): Figure out if we should show something for a layer who's
- // animating bounds but that we can't compute them.
- gfx::BoxF inflated_bounds;
- if (!LayerUtils::GetAnimationBounds(**it, &inflated_bounds))
- continue;
-
- debug_rects_.push_back(
- DebugRect(ANIMATION_BOUNDS_RECT_TYPE,
- gfx::ToEnclosingRect(gfx::RectF(
- inflated_bounds.x(), inflated_bounds.y(),
- inflated_bounds.width(), inflated_bounds.height()))));
- }
-}
-
} // namespace cc
diff --git a/chromium/cc/trees/debug_rect_history.h b/chromium/cc/trees/debug_rect_history.h
index 2e9c239b7a2..fb6b9021a69 100644
--- a/chromium/cc/trees/debug_rect_history.h
+++ b/chromium/cc/trees/debug_rect_history.h
@@ -97,7 +97,6 @@ class DebugRectHistory {
void SaveScrollEventHandlerRectsCallback(LayerImpl* layer);
void SaveNonFastScrollableRects(LayerTreeImpl* layer);
void SaveNonFastScrollableRectsCallback(LayerImpl* layer);
- void SaveLayerAnimationBoundsRects(LayerTreeImpl* tree_impl);
std::vector<DebugRect> debug_rects_;
diff --git a/chromium/cc/trees/draw_property_utils.cc b/chromium/cc/trees/draw_property_utils.cc
index e458ba70b0e..f4c64c06859 100644
--- a/chromium/cc/trees/draw_property_utils.cc
+++ b/chromium/cc/trees/draw_property_utils.cc
@@ -8,6 +8,7 @@
#include <vector>
+#include "base/containers/stack.h"
#include "cc/base/math_util.h"
#include "cc/layers/draw_properties.h"
#include "cc/layers/layer.h"
@@ -221,7 +222,7 @@ static ConditionalClip ComputeAccumulatedClip(PropertyTrees* property_trees,
ConditionalClip unclipped = ConditionalClip{false, gfx::RectF()};
// Collect all the clips that need to be accumulated.
- std::stack<const ClipNode*, std::vector<const ClipNode*>> parent_chain;
+ base::stack<const ClipNode*, std::vector<const ClipNode*>> parent_chain;
// If target is not direct ancestor of clip, this will find least common
// ancestor between the target and the clip. Or, if the target has a
@@ -1009,6 +1010,7 @@ void ComputeMaskDrawProperties(LayerImpl* mask_layer,
property_trees->transform_tree);
mask_layer->draw_properties().visible_layer_rect =
gfx::Rect(mask_layer->bounds());
+ mask_layer->draw_properties().opacity = 1;
}
void ComputeSurfaceDrawProperties(PropertyTrees* property_trees,
diff --git a/chromium/cc/trees/effect_node.cc b/chromium/cc/trees/effect_node.cc
index ce158903ba1..3a0669ea25c 100644
--- a/chromium/cc/trees/effect_node.cc
+++ b/chromium/cc/trees/effect_node.cc
@@ -21,12 +21,14 @@ EffectNode::EffectNode()
has_copy_request(false),
hidden_by_backface_visibility(false),
double_sided(false),
+ trilinear_filtering(false),
is_drawn(true),
subtree_hidden(false),
has_potential_filter_animation(false),
has_potential_opacity_animation(false),
is_currently_animating_filter(false),
is_currently_animating_opacity(false),
+ has_masking_child(false),
effect_changed(false),
subtree_has_copy_request(false),
transform_id(0),
@@ -52,8 +54,9 @@ bool EffectNode::operator==(const EffectNode& other) const {
surface_contents_scale == other.surface_contents_scale &&
unscaled_mask_target_size == other.unscaled_mask_target_size &&
hidden_by_backface_visibility == other.hidden_by_backface_visibility &&
- double_sided == other.double_sided && is_drawn == other.is_drawn &&
- subtree_hidden == other.subtree_hidden &&
+ double_sided == other.double_sided &&
+ trilinear_filtering == other.trilinear_filtering &&
+ is_drawn == other.is_drawn && subtree_hidden == other.subtree_hidden &&
has_potential_filter_animation ==
other.has_potential_filter_animation &&
has_potential_opacity_animation ==
@@ -61,6 +64,7 @@ bool EffectNode::operator==(const EffectNode& other) const {
is_currently_animating_filter == other.is_currently_animating_filter &&
is_currently_animating_opacity ==
other.is_currently_animating_opacity &&
+ has_masking_child == other.has_masking_child &&
effect_changed == other.effect_changed &&
subtree_has_copy_request == other.subtree_has_copy_request &&
transform_id == other.transform_id && clip_id == other.clip_id &&
@@ -80,6 +84,7 @@ void EffectNode::AsValueInto(base::trace_event::TracedValue* value) const {
value->SetBoolean("cache_render_surface", cache_render_surface);
value->SetBoolean("has_copy_request", has_copy_request);
value->SetBoolean("double_sided", double_sided);
+ value->SetBoolean("trilinear_filtering", trilinear_filtering);
value->SetBoolean("is_drawn", is_drawn);
value->SetBoolean("has_potential_filter_animation",
has_potential_filter_animation);
diff --git a/chromium/cc/trees/effect_node.h b/chromium/cc/trees/effect_node.h
index 48e25e9b209..ecf3c90438c 100644
--- a/chromium/cc/trees/effect_node.h
+++ b/chromium/cc/trees/effect_node.h
@@ -53,6 +53,7 @@ struct CC_EXPORT EffectNode {
bool has_copy_request : 1;
bool hidden_by_backface_visibility : 1;
bool double_sided : 1;
+ bool trilinear_filtering : 1;
bool is_drawn : 1;
// TODO(jaydasika) : Delete this after implementation of
// SetHideLayerAndSubtree is cleaned up. (crbug.com/595843)
@@ -67,6 +68,8 @@ struct CC_EXPORT EffectNode {
bool is_currently_animating_filter : 1;
// Whether this node has a currently running opacity animation.
bool is_currently_animating_opacity : 1;
+ // Whether this node has a child node with kDstIn blend mode.
+ bool has_masking_child : 1;
// Whether this node's effect has been changed since the last
// frame. Needed in order to compute damage rect.
bool effect_changed : 1;
diff --git a/chromium/cc/trees/image_animation_controller.cc b/chromium/cc/trees/image_animation_controller.cc
new file mode 100644
index 00000000000..a317cf5570c
--- /dev/null
+++ b/chromium/cc/trees/image_animation_controller.cc
@@ -0,0 +1,430 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/trees/image_animation_controller.h"
+
+#include "base/bind.h"
+#include "base/metrics/histogram_macros.h"
+#include "base/trace_event/trace_event.h"
+#include "cc/paint/image_animation_count.h"
+
+namespace cc {
+namespace {
+
+// The maximum number of time an animation can be delayed before it is reset to
+// start from the beginning, instead of fast-forwarding to catch up to the
+// desired frame.
+const base::TimeDelta kAnimationResyncCutoff = base::TimeDelta::FromMinutes(5);
+
+} // namespace
+
+ImageAnimationController::ImageAnimationController(
+ base::SingleThreadTaskRunner* task_runner,
+ base::Closure invalidation_callback)
+ : notifier_(task_runner, invalidation_callback) {}
+
+ImageAnimationController::~ImageAnimationController() = default;
+
+void ImageAnimationController::UpdateAnimatedImage(
+ const DiscardableImageMap::AnimatedImageMetadata& data) {
+ AnimationState& animation_state = animation_state_map_[data.paint_image_id];
+ animation_state.UpdateMetadata(data);
+}
+
+void ImageAnimationController::RegisterAnimationDriver(
+ PaintImage::Id paint_image_id,
+ AnimationDriver* driver) {
+ auto it = animation_state_map_.find(paint_image_id);
+ DCHECK(it != animation_state_map_.end());
+ it->second.AddDriver(driver);
+}
+
+void ImageAnimationController::UnregisterAnimationDriver(
+ PaintImage::Id paint_image_id,
+ AnimationDriver* driver) {
+ auto it = animation_state_map_.find(paint_image_id);
+ DCHECK(it != animation_state_map_.end());
+ it->second.RemoveDriver(driver);
+}
+
+const PaintImageIdFlatSet& ImageAnimationController::AnimateForSyncTree(
+ base::TimeTicks now) {
+ TRACE_EVENT0("cc", "ImageAnimationController::AnimateImagesForSyncTree");
+ DCHECK(images_animated_on_sync_tree_.empty());
+
+ notifier_.WillAnimate();
+ base::Optional<base::TimeTicks> next_invalidation_time;
+
+ for (auto id : active_animations_) {
+ auto it = animation_state_map_.find(id);
+ DCHECK(it != animation_state_map_.end());
+ AnimationState& state = it->second;
+
+ // Is anyone still interested in animating this image?
+ if (!state.ShouldAnimate())
+ continue;
+
+ // If we were able to advance this animation, invalidate it on the sync
+ // tree.
+ if (state.AdvanceFrame(now))
+ images_animated_on_sync_tree_.insert(id);
+
+ // Update the next invalidation time to the earliest time at which we need
+ // a frame to animate an image.
+ // Note its important to check ShouldAnimate() here again since advancing to
+ // a new frame on the sync tree means we might not need to animate this
+ // image any longer.
+ if (!state.ShouldAnimate())
+ continue;
+
+ DCHECK_GT(state.next_desired_frame_time(), now);
+ if (!next_invalidation_time.has_value()) {
+ next_invalidation_time.emplace(state.next_desired_frame_time());
+ } else {
+ next_invalidation_time = std::min(state.next_desired_frame_time(),
+ next_invalidation_time.value());
+ }
+ }
+
+ if (next_invalidation_time.has_value())
+ notifier_.Schedule(now, next_invalidation_time.value());
+ else
+ notifier_.Cancel();
+
+ return images_animated_on_sync_tree_;
+}
+
+void ImageAnimationController::UpdateStateFromDrivers(base::TimeTicks now) {
+ TRACE_EVENT0("cc", "UpdateStateFromAnimationDrivers");
+
+ base::Optional<base::TimeTicks> next_invalidation_time;
+ for (auto& it : animation_state_map_) {
+ AnimationState& state = it.second;
+ state.UpdateStateFromDrivers();
+
+ // If we don't need to animate this image anymore, remove it from the list
+ // of active animations.
+ // Note that by not updating the |next_invalidation_time| from this image
+ // here, we will cancel any pending invalidation scheduled for this image
+ // when updating the |notifier_| at the end of this loop.
+ if (!state.ShouldAnimate()) {
+ active_animations_.erase(it.first);
+ continue;
+ }
+
+ active_animations_.insert(it.first);
+ if (!next_invalidation_time.has_value()) {
+ next_invalidation_time.emplace(state.next_desired_frame_time());
+ } else {
+ next_invalidation_time = std::min(next_invalidation_time.value(),
+ state.next_desired_frame_time());
+ }
+ }
+
+ if (next_invalidation_time.has_value())
+ notifier_.Schedule(now, next_invalidation_time.value());
+ else
+ notifier_.Cancel();
+}
+
+void ImageAnimationController::DidActivate() {
+ TRACE_EVENT0("cc", "ImageAnimationController::WillActivate");
+
+ for (auto id : images_animated_on_sync_tree_) {
+ auto it = animation_state_map_.find(id);
+ DCHECK(it != animation_state_map_.end());
+ it->second.PushPendingToActive();
+ }
+
+ images_animated_on_sync_tree_.clear();
+}
+
+size_t ImageAnimationController::GetFrameIndexForImage(
+ PaintImage::Id paint_image_id,
+ WhichTree tree) const {
+ const auto& it = animation_state_map_.find(paint_image_id);
+ DCHECK(it != animation_state_map_.end());
+ return tree == WhichTree::PENDING_TREE ? it->second.pending_index()
+ : it->second.active_index();
+}
+
+const base::flat_set<ImageAnimationController::AnimationDriver*>&
+ImageAnimationController::GetDriversForTesting(
+ PaintImage::Id paint_image_id) const {
+ const auto& it = animation_state_map_.find(paint_image_id);
+ DCHECK(it != animation_state_map_.end());
+ return it->second.drivers_for_testing();
+}
+
+size_t ImageAnimationController::GetLastNumOfFramesSkippedForTesting(
+ PaintImage::Id paint_image_id) const {
+ const auto& it = animation_state_map_.find(paint_image_id);
+ DCHECK(it != animation_state_map_.end());
+ return it->second.last_num_frames_skipped_for_testing();
+}
+
+ImageAnimationController::AnimationState::AnimationState() = default;
+
+ImageAnimationController::AnimationState::AnimationState(
+ AnimationState&& other) = default;
+
+ImageAnimationController::AnimationState&
+ImageAnimationController::AnimationState::operator=(AnimationState&& other) =
+ default;
+
+ImageAnimationController::AnimationState::~AnimationState() {
+ DCHECK(drivers_.empty());
+}
+
+bool ImageAnimationController::AnimationState::ShouldAnimate() const {
+ DCHECK(repetitions_completed_ == 0 || is_complete());
+
+ // If we have no drivers for this image, no need to animate it.
+ if (!should_animate_from_drivers_)
+ return false;
+
+ switch (requested_repetitions_) {
+ case kAnimationLoopOnce:
+ if (repetitions_completed_ >= 1)
+ return false;
+ break;
+ case kAnimationNone:
+ NOTREACHED() << "We shouldn't be tracking kAnimationNone images";
+ break;
+ case kAnimationLoopInfinite:
+ break;
+ default:
+ if (requested_repetitions_ <= repetitions_completed_)
+ return false;
+ }
+
+ // If we have not yet received all data for this image, we can not advance to
+ // an incomplete frame.
+ if (!frames_[NextFrameIndex()].complete)
+ return false;
+
+ // If we don't have all data for this image, we can not trust the frame count
+ // and loop back to the first frame.
+ size_t last_frame_index = frames_.size() - 1;
+ if (completion_state_ != PaintImage::CompletionState::DONE &&
+ pending_index_ == last_frame_index)
+ return false;
+
+ return true;
+}
+
+bool ImageAnimationController::AnimationState::AdvanceFrame(
+ base::TimeTicks now) {
+ DCHECK(ShouldAnimate());
+
+ // Start the animation from the first frame, if not yet started. We don't need
+ // an invalidation here if the pending and active tree are both displaying the
+ // first frame. Its possible for the 2 to be different if the animation was
+ // reset, in which case we are starting again from the first frame on the
+ // pending tree.
+ if (!animation_started_) {
+ DCHECK_EQ(pending_index_, 0u);
+
+ next_desired_frame_time_ = now + frames_[0].duration;
+ animation_started_ = true;
+ return pending_index_ != active_index_;
+ }
+
+ // Don't advance the animation if its not time yet to move to the next frame.
+ if (now < next_desired_frame_time_)
+ return false;
+
+ // If the animation is more than 5 min out of date, we don't bother catching
+ // up and start again from the current frame.
+ // Note that we don't need to invalidate this image since the active tree
+ // is already displaying the current frame.
+ if (now - next_desired_frame_time_ > kAnimationResyncCutoff) {
+ DCHECK_EQ(pending_index_, active_index_);
+ next_desired_frame_time_ = now + frames_[pending_index_].duration;
+ return false;
+ }
+
+ // Keep catching up the animation until we reach the frame we should be
+ // displaying now.
+ // TODO(khushalsagar): Avoid unnecessary iterations for skipping whole loops
+ // in the animations.
+ size_t last_frame_index = frames_.size() - 1;
+ size_t num_of_frames_advanced = 0u;
+ while (next_desired_frame_time_ <= now && ShouldAnimate()) {
+ num_of_frames_advanced++;
+ size_t next_frame_index = NextFrameIndex();
+ base::TimeTicks next_desired_frame_time =
+ next_desired_frame_time_ + frames_[next_frame_index].duration;
+
+ // The image may load more slowly than it's supposed to animate, so that by
+ // the time we reach the end of the first repetition, we're well behind.
+ // Start the animation from the first frame in this case, so that we don't
+ // skip frames (or whole iterations) trying to "catch up". This is a
+ // tradeoff: It guarantees users see the whole animation the second time
+ // through and don't miss any repetitions, and is closer to what other
+ // browsers do; on the other hand, it makes animations "less accurate" for
+ // pages that try to sync an image and some other resource (e.g. audio),
+ // especially if users switch tabs (and thus stop drawing the animation,
+ // which will pause it) during that initial loop, then switch back later.
+ if (next_frame_index == 0u && repetitions_completed_ == 1 &&
+ next_desired_frame_time <= now) {
+ pending_index_ = 0u;
+ next_desired_frame_time_ = now + frames_[0].duration;
+ repetitions_completed_ = 0;
+ break;
+ }
+
+ pending_index_ = next_frame_index;
+ next_desired_frame_time_ = next_desired_frame_time;
+
+ // If we are advancing to the last frame and the image has been completely
+ // loaded (which means that the frame count is known to be accurate), we
+ // just finished a loop in the animation.
+ if (pending_index_ == last_frame_index && is_complete())
+ repetitions_completed_++;
+ }
+
+ // We should have advanced a single frame, anything more than that are frames
+ // skipped trying to catch up.
+ DCHECK_GT(num_of_frames_advanced, 0u);
+ last_num_frames_skipped_ = num_of_frames_advanced - 1u;
+ UMA_HISTOGRAM_COUNTS_100000("AnimatedImage.NumOfFramesSkipped.Compositor",
+ last_num_frames_skipped_);
+
+ return pending_index_ != active_index_;
+}
+
+void ImageAnimationController::AnimationState::UpdateMetadata(
+ const DiscardableImageMap::AnimatedImageMetadata& data) {
+ paint_image_id_ = data.paint_image_id;
+
+ DCHECK_NE(data.repetition_count, kAnimationNone);
+ requested_repetitions_ = data.repetition_count;
+
+ DCHECK(frames_.size() <= data.frames.size())
+ << "Updated recordings can only append frames";
+ frames_ = data.frames;
+ DCHECK_GT(frames_.size(), 1u);
+
+ DCHECK(completion_state_ != PaintImage::CompletionState::DONE ||
+ data.completion_state == PaintImage::CompletionState::DONE)
+ << "If the image was marked complete before, it can not be incomplete in "
+ "a new update";
+ completion_state_ = data.completion_state;
+
+ // Update the repetition count in case we have displayed the last frame and
+ // we now know the frame count to be accurate.
+ size_t last_frame_index = frames_.size() - 1;
+ if (pending_index_ == last_frame_index && is_complete() &&
+ repetitions_completed_ == 0)
+ repetitions_completed_++;
+
+ // Reset the animation if the sequence id received in this recording was
+ // incremented.
+ if (reset_animation_sequence_id_ < data.reset_animation_sequence_id) {
+ reset_animation_sequence_id_ = data.reset_animation_sequence_id;
+ ResetAnimation();
+ }
+}
+
+void ImageAnimationController::AnimationState::PushPendingToActive() {
+ active_index_ = pending_index_;
+}
+
+void ImageAnimationController::AnimationState::AddDriver(
+ AnimationDriver* driver) {
+ drivers_.insert(driver);
+}
+
+void ImageAnimationController::AnimationState::RemoveDriver(
+ AnimationDriver* driver) {
+ drivers_.erase(driver);
+}
+
+void ImageAnimationController::AnimationState::UpdateStateFromDrivers() {
+ should_animate_from_drivers_ = false;
+ for (auto* driver : drivers_) {
+ if (driver->ShouldAnimate(paint_image_id_)) {
+ should_animate_from_drivers_ = true;
+ break;
+ }
+ }
+}
+
+void ImageAnimationController::AnimationState::ResetAnimation() {
+ animation_started_ = false;
+ next_desired_frame_time_ = base::TimeTicks();
+ repetitions_completed_ = 0;
+ pending_index_ = 0u;
+ // Don't reset the |active_index_|, tiles on the active tree still need it.
+}
+
+size_t ImageAnimationController::AnimationState::NextFrameIndex() const {
+ if (!animation_started_)
+ return 0u;
+ return (pending_index_ + 1) % frames_.size();
+}
+
+ImageAnimationController::DelayedNotifier::DelayedNotifier(
+ base::SingleThreadTaskRunner* task_runner,
+ base::Closure closure)
+ : task_runner_(task_runner),
+ closure_(std::move(closure)),
+ weak_factory_(this) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+}
+
+ImageAnimationController::DelayedNotifier::~DelayedNotifier() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+}
+
+void ImageAnimationController::DelayedNotifier::Schedule(
+ base::TimeTicks now,
+ base::TimeTicks notification_time) {
+ // If an animation is already pending, don't schedule another invalidation.
+ // We will schedule the next invalidation based on the latest animation state
+ // during AnimateForSyncTree.
+ if (animation_pending_)
+ return;
+
+ // The requested notification time can be in the past. For instance, if an
+ // animation was paused because the image became invisible.
+ if (notification_time < now)
+ notification_time = now;
+
+ // If we already have a notification scheduled to run at this time, no need to
+ // Cancel it.
+ if (pending_notification_time_.has_value() &&
+ notification_time == pending_notification_time_.value())
+ return;
+
+ // Cancel the pending notification since we the requested notification time
+ // has changed.
+ Cancel();
+
+ TRACE_EVENT2("cc", "ScheduleInvalidationForImageAnimation",
+ "notification_time", notification_time, "now", now);
+ pending_notification_time_.emplace(notification_time);
+ task_runner_->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&DelayedNotifier::Notify, weak_factory_.GetWeakPtr()),
+ notification_time - now);
+}
+
+void ImageAnimationController::DelayedNotifier::Cancel() {
+ pending_notification_time_.reset();
+ weak_factory_.InvalidateWeakPtrs();
+}
+
+void ImageAnimationController::DelayedNotifier::Notify() {
+ pending_notification_time_.reset();
+ animation_pending_ = true;
+ closure_.Run();
+}
+
+void ImageAnimationController::DelayedNotifier::WillAnimate() {
+ animation_pending_ = false;
+}
+
+} // namespace cc
diff --git a/chromium/cc/trees/image_animation_controller.h b/chromium/cc/trees/image_animation_controller.h
new file mode 100644
index 00000000000..f9e2f0eea7d
--- /dev/null
+++ b/chromium/cc/trees/image_animation_controller.h
@@ -0,0 +1,237 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_TREES_IMAGE_ANIMATION_CONTROLLER_H_
+#define CC_TREES_IMAGE_ANIMATION_CONTROLLER_H_
+
+#include "base/cancelable_callback.h"
+#include "base/containers/flat_map.h"
+#include "base/containers/flat_set.h"
+#include "base/memory/weak_ptr.h"
+#include "base/optional.h"
+#include "base/time/time.h"
+#include "cc/cc_export.h"
+#include "cc/paint/discardable_image_map.h"
+#include "cc/paint/image_id.h"
+#include "cc/paint/paint_image.h"
+#include "cc/paint/paint_image_generator.h"
+#include "cc/tiles/tile_priority.h"
+
+namespace cc {
+class PaintImage;
+
+// ImageAnimationController is responsible for tracking state for ticking image
+// animations in the compositor.
+//
+// 1) It receives the updated metadata for these images from new recordings
+// received from the client using UpdateAnimatedImage. The controller tracks
+// the frame index of an image used on a tree, and advances the animation to
+// the desired frame each time a new sync tree is created.
+//
+// 2) An AnimationDriver can register itself for deciding whether the
+// controller animates an image. The animation is paused if there are no
+// registered drivers interested in animating it.
+//
+// 3) An animation is only advanced on the sync tree, which is requested to be
+// created using the |invalidation_callback|. This effectively means that
+// the frame of the image used remains consistent throughout the lifetime of
+// a tree, guaranteeing that the image update is atomic.
+class CC_EXPORT ImageAnimationController {
+ public:
+ // AnimationDrivers are clients interested in driving image animations. An
+ // animation is ticked if there is at least one driver registered for which
+ // ShouldAnimate returns true. Once
+ // no drivers are registered for an image, or none of the registered drivers
+ // want us to animate, the animation is no longer ticked.
+ class CC_EXPORT AnimationDriver {
+ public:
+ virtual ~AnimationDriver() {}
+
+ // Returns true if the image should be animated.
+ virtual bool ShouldAnimate(PaintImage::Id paint_image_id) const = 0;
+ };
+
+ // |invalidation_callback| is the callback to trigger an invalidation and
+ // create a sync tree for advancing an image animation. The controller is
+ // guaranteed to receive a call to AnimateForSyncTree when the sync tree is
+ // created.
+ // |task_runner| is the thread on which the controller is used. The
+ // invalidation_callback can only be run on this thread.
+ ImageAnimationController(base::SingleThreadTaskRunner* task_runner,
+ base::Closure invalidation_callback);
+ ~ImageAnimationController();
+
+ // Called to update the state for a PaintImage received in a new recording.
+ void UpdateAnimatedImage(
+ const DiscardableImageMap::AnimatedImageMetadata& data);
+
+ // Registers/Unregisters an animation driver interested in animating this
+ // image.
+ // Note that the state for this image must have been populated to the
+ // controller using UpdatePaintImage prior to registering any drivers.
+ void RegisterAnimationDriver(PaintImage::Id paint_image_id,
+ AnimationDriver* driver);
+ void UnregisterAnimationDriver(PaintImage::Id paint_image_id,
+ AnimationDriver* driver);
+
+ // Called to advance the animations to the frame to be used on the sync tree.
+ // This should be called only once for a sync tree and must be followed with
+ // a call to DidActivate when this tree is activated.
+ // Returns the set of images that were animated and should be invalidated on
+ // this sync tree.
+ const PaintImageIdFlatSet& AnimateForSyncTree(base::TimeTicks now);
+
+ // Called whenever the ShouldAnimate response for a driver could have changed.
+ // For instance on a change in the visibility of the image, we would pause
+ // off-screen animations.
+ // This is called after every DrawProperties update and commit.
+ void UpdateStateFromDrivers(base::TimeTicks now);
+
+ // Called when the sync tree was activated and the animations' associated
+ // state should be pushed to the active tree.
+ void DidActivate();
+
+ // Returns the frame index to use for the given PaintImage and tree.
+ size_t GetFrameIndexForImage(PaintImage::Id paint_image_id,
+ WhichTree tree) const;
+
+ const base::flat_set<AnimationDriver*>& GetDriversForTesting(
+ PaintImage::Id paint_image_id) const;
+ size_t GetLastNumOfFramesSkippedForTesting(
+ PaintImage::Id paint_image_id) const;
+
+ private:
+ class AnimationState {
+ public:
+ AnimationState();
+ AnimationState(AnimationState&& other);
+ AnimationState& operator=(AnimationState&& other);
+ ~AnimationState();
+
+ bool ShouldAnimate() const;
+ bool AdvanceFrame(base::TimeTicks now);
+ void UpdateMetadata(const DiscardableImageMap::AnimatedImageMetadata& data);
+ void PushPendingToActive();
+
+ void AddDriver(AnimationDriver* driver);
+ void RemoveDriver(AnimationDriver* driver);
+ void UpdateStateFromDrivers();
+
+ size_t pending_index() const { return pending_index_; }
+ size_t active_index() const { return active_index_; }
+ base::TimeTicks next_desired_frame_time() const {
+ return next_desired_frame_time_;
+ }
+ const base::flat_set<AnimationDriver*>& drivers_for_testing() const {
+ return drivers_;
+ }
+ size_t last_num_frames_skipped_for_testing() const {
+ return last_num_frames_skipped_;
+ }
+
+ private:
+ void ResetAnimation();
+ size_t NextFrameIndex() const;
+ bool is_complete() const {
+ return completion_state_ == PaintImage::CompletionState::DONE;
+ }
+
+ PaintImage::Id paint_image_id_ = PaintImage::kNonLazyStableId;
+
+ // The frame metadata received from the most updated recording with this
+ // PaintImage.
+ std::vector<FrameMetadata> frames_;
+
+ // The number of animation loops requested for this image. For a value > 0,
+ // this number represents the exact number of iterations requested. A few
+ // special cases are represented using constants defined in
+ // cc/paint/image_animation_count.h
+ int requested_repetitions_ = kAnimationNone;
+
+ // The number of loops the animation has finished so far.
+ int repetitions_completed_ = 0;
+
+ // A set of drivers interested in animating this image.
+ base::flat_set<AnimationDriver*> drivers_;
+
+ // The index being used on the active tree, if a recording with this image
+ // is still present.
+ size_t active_index_ = PaintImage::kDefaultFrameIndex;
+
+ // The index being displayed on the pending tree.
+ size_t pending_index_ = PaintImage::kDefaultFrameIndex;
+
+ // The time at which we would like to display the next frame. This can be in
+ // the past, for instance, if we pause the animation from the image becoming
+ // invisible.
+ base::TimeTicks next_desired_frame_time_;
+
+ // Set if there is at least one driver interested in animating this image,
+ // cached from the last update.
+ bool should_animate_from_drivers_ = false;
+
+ // Set if the animation has been started.
+ bool animation_started_ = false;
+
+ // The last synchronized sequence id for resetting this animation.
+ PaintImage::AnimationSequenceId reset_animation_sequence_id_ = 0;
+
+ // Whether the image is known to be completely loaded in the most recent
+ // recording received.
+ PaintImage::CompletionState completion_state_ =
+ PaintImage::CompletionState::PARTIALLY_DONE;
+
+ // The number of frames skipped during catch-up the last time this animation
+ // was advanced.
+ size_t last_num_frames_skipped_ = 0u;
+
+ DISALLOW_COPY_AND_ASSIGN(AnimationState);
+ };
+
+ class DelayedNotifier {
+ public:
+ DelayedNotifier(base::SingleThreadTaskRunner* task_runner,
+ base::Closure closure);
+ ~DelayedNotifier();
+
+ void Schedule(base::TimeTicks now, base::TimeTicks notification_time);
+ void Cancel();
+ void WillAnimate();
+
+ private:
+ void Notify();
+
+ base::SingleThreadTaskRunner* task_runner_;
+ base::Closure closure_;
+
+ // Set if a notification is currently pending.
+ base::Optional<base::TimeTicks> pending_notification_time_;
+
+ // Set if the notification was dispatched and the resulting animation on the
+ // next sync tree is pending.
+ bool animation_pending_ = false;
+
+ base::WeakPtrFactory<DelayedNotifier> weak_factory_;
+ };
+
+ // The AnimationState for images is persisted until they are cleared on
+ // navigation. This is because while an image might not be painted anymore, if
+ // it moves out of the interest rect for instance, the state retained is
+ // necessary to resume the animation.
+ // TODO(khushalsagar): Implement clearing of state on navigations.
+ using AnimationStateMap = base::flat_map<PaintImage::Id, AnimationState>;
+ AnimationStateMap animation_state_map_;
+
+ // The set of currently active animations.
+ PaintImageIdFlatSet active_animations_;
+
+ // The set of images that were animated and invalidated on the last sync tree.
+ PaintImageIdFlatSet images_animated_on_sync_tree_;
+
+ DelayedNotifier notifier_;
+};
+
+} // namespace cc
+
+#endif // CC_TREES_IMAGE_ANIMATION_CONTROLLER_H_
diff --git a/chromium/cc/trees/image_animation_controller_unittest.cc b/chromium/cc/trees/image_animation_controller_unittest.cc
new file mode 100644
index 00000000000..c4db878ba19
--- /dev/null
+++ b/chromium/cc/trees/image_animation_controller_unittest.cc
@@ -0,0 +1,736 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/trees/image_animation_controller.h"
+
+#include "base/memory/ptr_util.h"
+#include "base/run_loop.h"
+#include "base/test/gtest_util.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace cc {
+
+class FakeAnimationDriver : public ImageAnimationController::AnimationDriver {
+ public:
+ FakeAnimationDriver() {}
+ ~FakeAnimationDriver() override {}
+
+ void set_should_animate(bool should_animate) {
+ should_animate_ = should_animate;
+ }
+
+ // ImageAnimationController::AnimationDriver implementation.
+ bool ShouldAnimate(PaintImage::Id paint_image_id) const override {
+ return should_animate_;
+ }
+
+ private:
+ bool should_animate_ = true;
+};
+
+class DelayTrackingTaskRunner : public base::SingleThreadTaskRunner {
+ public:
+ explicit DelayTrackingTaskRunner(base::SingleThreadTaskRunner* task_runner)
+ : task_runner_(task_runner) {}
+
+ bool PostDelayedTask(const base::Location& from_here,
+ base::OnceClosure task,
+ base::TimeDelta delay) override {
+ last_delay_.emplace(delay);
+ return task_runner_->PostTask(from_here, std::move(task));
+ }
+
+ bool RunsTasksInCurrentSequence() const override {
+ return task_runner_->RunsTasksInCurrentSequence();
+ }
+
+ bool PostNonNestableDelayedTask(const base::Location& from_here,
+ base::OnceClosure task,
+ base::TimeDelta delay) override {
+ last_delay_.emplace(delay);
+ return task_runner_->PostTask(from_here, std::move(task));
+ }
+
+ void VerifyDelay(base::TimeDelta expected) {
+ DCHECK(last_delay_.has_value());
+ EXPECT_EQ(last_delay_.value(), expected);
+ last_delay_.reset();
+ }
+
+ bool has_delay() const { return last_delay_.has_value(); }
+
+ private:
+ ~DelayTrackingTaskRunner() override = default;
+
+ base::Optional<base::TimeDelta> last_delay_;
+ base::SingleThreadTaskRunner* task_runner_;
+};
+
+class ImageAnimationControllerTest : public testing::Test {
+ public:
+ void SetUp() override {
+ task_runner_ =
+ new DelayTrackingTaskRunner(base::ThreadTaskRunnerHandle::Get().get());
+ base::Closure invalidation_callback =
+ base::Bind(&ImageAnimationControllerTest::RequestInvalidation,
+ base::Unretained(this));
+ controller_ = base::MakeUnique<ImageAnimationController>(
+ task_runner_.get(), invalidation_callback);
+ now_ += base::TimeDelta::FromSeconds(10);
+ }
+
+ void TearDown() override { controller_.reset(); }
+
+ void LoopOnceNoDelay(PaintImage::Id paint_image_id,
+ const std::vector<FrameMetadata>& frames,
+ size_t num_of_frames_to_loop,
+ int repetitions_completed,
+ bool restarting = false) {
+ DCHECK_LE(num_of_frames_to_loop, frames.size());
+
+ invalidation_count_ = 0;
+ for (size_t i = 0; i < num_of_frames_to_loop; ++i) {
+ SCOPED_TRACE(i);
+
+ // Run the pending invalidation.
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, static_cast<int>(i + 1));
+
+ // Animate the image on the sync tree.
+ auto animated_images = controller_->AnimateForSyncTree(now_);
+
+ // No frames should have been skipped since we add no delay in advancing
+ // the animation.
+ EXPECT_EQ(
+ controller_->GetLastNumOfFramesSkippedForTesting(paint_image_id), 0u);
+
+ EXPECT_EQ(controller_->GetFrameIndexForImage(paint_image_id,
+ WhichTree::PENDING_TREE),
+ i);
+ if (i == 0u && !restarting) {
+ // If we are displaying the first frame on the pending tree, then the
+ // active tree has the first frame as well if this is the first loop,
+ // otherwise it should be the last frame since we are starting a new
+ // loop.
+ size_t active_index = 0u;
+ if (repetitions_completed != 0)
+ active_index = frames.size() - 1;
+ EXPECT_EQ(controller_->GetFrameIndexForImage(paint_image_id,
+ WhichTree::ACTIVE_TREE),
+ active_index);
+ } else if (i != 0u) {
+ EXPECT_EQ(controller_->GetFrameIndexForImage(paint_image_id,
+ WhichTree::ACTIVE_TREE),
+ i - 1);
+ }
+
+ if (i == 0u && repetitions_completed == 0 && !restarting) {
+ // Starting the animation does not perform any invalidation.
+ EXPECT_EQ(animated_images.size(), 0u);
+ } else {
+ EXPECT_EQ(animated_images.size(), 1u);
+ EXPECT_EQ(animated_images.count(paint_image_id), 1u);
+ }
+
+ // Animating should schedule an invalidation for the next frame, until we
+ // reach the last frame.
+ if (i != num_of_frames_to_loop - 1)
+ task_runner_->VerifyDelay(frames[i].duration);
+
+ // Activate and advance time to the next frame.
+ controller_->DidActivate();
+ AdvanceNow(frames[i].duration);
+ }
+ }
+
+ protected:
+ void RequestInvalidation() { invalidation_count_++; }
+
+ void AdvanceNow(base::TimeDelta delta) { now_ += delta; }
+
+ base::TimeTicks now_;
+ int invalidation_count_ = 0;
+ std::unique_ptr<ImageAnimationController> controller_;
+ scoped_refptr<DelayTrackingTaskRunner> task_runner_;
+};
+
+TEST_F(ImageAnimationControllerTest, AnimationWithDelays) {
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(5)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(4)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))};
+
+ DiscardableImageMap::AnimatedImageMetadata data(
+ PaintImage::GetNextId(), PaintImage::CompletionState::DONE, frames,
+ kAnimationLoopInfinite, 0);
+ controller_->UpdateAnimatedImage(data);
+ FakeAnimationDriver driver;
+ controller_->RegisterAnimationDriver(data.paint_image_id, &driver);
+ controller_->UpdateStateFromDrivers(now_);
+
+ // Display 2 loops in the animation.
+ LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), 0);
+ LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), 1);
+
+ // now_ is set to the time at which the first frame should be displayed for
+ // the third iteration. Add a delay that causes us to skip the first frame.
+ base::TimeDelta additional_delay = base::TimeDelta::FromMilliseconds(1);
+ AdvanceNow(data.frames[0].duration + additional_delay);
+ auto animated_images = controller_->AnimateForSyncTree(now_);
+ EXPECT_EQ(animated_images.size(), 1u);
+ EXPECT_EQ(animated_images.count(data.paint_image_id), 1u);
+ EXPECT_EQ(
+ controller_->GetLastNumOfFramesSkippedForTesting(data.paint_image_id),
+ 1u);
+
+ // The pending tree displays the second frame while the active tree has the
+ // last frame.
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::PENDING_TREE),
+ 1u);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::ACTIVE_TREE),
+ 3u);
+
+ // Invalidation delay is based on the duration of the second frame and the
+ // delay in creating this sync tree.
+ task_runner_->VerifyDelay(frames[1].duration - additional_delay);
+ invalidation_count_ = 0;
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 1);
+
+ // Activate and animate with a delay that causes us to skip another 2 frames.
+ controller_->DidActivate();
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::ACTIVE_TREE),
+ 1u);
+ AdvanceNow(data.frames[1].duration + data.frames[2].duration +
+ data.frames[3].duration);
+ animated_images = controller_->AnimateForSyncTree(now_);
+ EXPECT_EQ(animated_images.size(), 1u);
+ EXPECT_EQ(animated_images.count(data.paint_image_id), 1u);
+ EXPECT_EQ(
+ controller_->GetLastNumOfFramesSkippedForTesting(data.paint_image_id),
+ 2u);
+
+ // The pending tree displays the first frame, while the active tree has the
+ // second frame.
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::PENDING_TREE),
+ 0u);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::ACTIVE_TREE),
+ 1u);
+
+ // Invalidation delay is based on the duration of the first frame and the
+ // initial additionaly delay.
+ task_runner_->VerifyDelay(frames[0].duration - additional_delay);
+ invalidation_count_ = 0;
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 1);
+
+ controller_->UnregisterAnimationDriver(data.paint_image_id, &driver);
+}
+
+TEST_F(ImageAnimationControllerTest, DriversControlAnimationTicking) {
+ std::vector<FrameMetadata> first_image_frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))};
+ DiscardableImageMap::AnimatedImageMetadata first_data(
+ PaintImage::GetNextId(), PaintImage::CompletionState::DONE,
+ first_image_frames, kAnimationLoopOnce, 0);
+ controller_->UpdateAnimatedImage(first_data);
+ FakeAnimationDriver first_driver;
+ controller_->RegisterAnimationDriver(first_data.paint_image_id,
+ &first_driver);
+
+ std::vector<FrameMetadata> second_image_frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(5)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))};
+ DiscardableImageMap::AnimatedImageMetadata second_data(
+ PaintImage::GetNextId(), PaintImage::CompletionState::DONE,
+ second_image_frames, kAnimationLoopOnce, 0);
+ controller_->UpdateAnimatedImage(second_data);
+ FakeAnimationDriver second_driver;
+ controller_->RegisterAnimationDriver(second_data.paint_image_id,
+ &second_driver);
+
+ // Disable animating from all drivers, no invalidation request should be made.
+ first_driver.set_should_animate(false);
+ second_driver.set_should_animate(false);
+ controller_->UpdateStateFromDrivers(now_);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 0);
+
+ // Enable animating from the first driver, which should schedule an
+ // invalidation to advance this animation.
+ first_driver.set_should_animate(true);
+ controller_->UpdateStateFromDrivers(now_);
+ task_runner_->VerifyDelay(base::TimeDelta());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 1);
+
+ // Start animating the first image.
+ auto animated_images = controller_->AnimateForSyncTree(now_);
+ EXPECT_EQ(animated_images.size(), 0u);
+
+ // Invalidation should be scheduled for this image.
+ task_runner_->VerifyDelay(first_image_frames[0].duration);
+
+ // Now enable animating the second image instead.
+ second_driver.set_should_animate(true);
+ controller_->UpdateStateFromDrivers(now_);
+
+ // Invalidation is triggered to start with no delay since the second image has
+ // not started animating yet.
+ task_runner_->VerifyDelay(base::TimeDelta());
+
+ // Disable animating all images.
+ first_driver.set_should_animate(false);
+ second_driver.set_should_animate(false);
+ controller_->UpdateStateFromDrivers(now_);
+
+ // Any scheduled invalidation should be cancelled.
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 1);
+
+ controller_->UnregisterAnimationDriver(first_data.paint_image_id,
+ &first_driver);
+ controller_->UnregisterAnimationDriver(second_data.paint_image_id,
+ &second_driver);
+}
+
+TEST_F(ImageAnimationControllerTest, RepetitionsRequested) {
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(4))};
+
+ DiscardableImageMap::AnimatedImageMetadata data(
+ PaintImage::GetNextId(), PaintImage::CompletionState::DONE, frames,
+ kAnimationLoopOnce, 0);
+ controller_->UpdateAnimatedImage(data);
+ FakeAnimationDriver driver;
+ controller_->RegisterAnimationDriver(data.paint_image_id, &driver);
+ controller_->UpdateStateFromDrivers(now_);
+
+ // Finish a single loop in the animation.
+ LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), 0);
+
+ // No invalidation should be scheduled now, since the requested number of
+ // loops have been completed.
+ invalidation_count_ = 0;
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 0);
+ controller_->UnregisterAnimationDriver(data.paint_image_id, &driver);
+
+ // Now with a repetition count of 5.
+ data.paint_image_id = PaintImage::GetNextId();
+ data.repetition_count = 5;
+ controller_->UpdateAnimatedImage(data);
+ controller_->RegisterAnimationDriver(data.paint_image_id, &driver);
+ controller_->UpdateStateFromDrivers(now_);
+ for (int i = 0; i < data.repetition_count; ++i) {
+ LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), i);
+
+ // Since we will be looping back to the first frame, the invalidation should
+ // have the delay of the last frame. Until we reach the end of requested
+ // iterations.
+ if (i < data.repetition_count - 1)
+ task_runner_->VerifyDelay(frames.back().duration);
+ invalidation_count_ = 0;
+ }
+
+ // No invalidation should be scheduled now, since the requested number of
+ // loops have been completed.
+ invalidation_count_ = 0;
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 0);
+ controller_->UnregisterAnimationDriver(data.paint_image_id, &driver);
+
+ // Now with kAnimationLoopInfinite.
+ data.paint_image_id = PaintImage::GetNextId();
+ data.repetition_count = kAnimationLoopInfinite;
+ controller_->UpdateAnimatedImage(data);
+ controller_->RegisterAnimationDriver(data.paint_image_id, &driver);
+ controller_->UpdateStateFromDrivers(now_);
+ for (int i = 0; i < 7; ++i) {
+ LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), i);
+
+ // Since we will be looping back to the first frame, the invalidation should
+ // have the delay of the last frame. Until we reach the end of requested
+ // iterations.
+ if (i < data.repetition_count - 1)
+ task_runner_->VerifyDelay(frames.back().duration);
+ invalidation_count_ = 0;
+ }
+
+ // We still have an invalidation scheduled since the image will keep looping
+ // till the drivers keep the animation active.
+ invalidation_count_ = 0;
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 1);
+ controller_->UnregisterAnimationDriver(data.paint_image_id, &driver);
+
+ // Now try with a kAnimationNone image, which should result in a DCHECK
+ // failure.
+ data.paint_image_id = PaintImage::GetNextId();
+ data.repetition_count = kAnimationNone;
+ EXPECT_DCHECK_DEATH(controller_->UpdateAnimatedImage(data));
+}
+
+TEST_F(ImageAnimationControllerTest, DisplayCompleteFrameOnly) {
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3)),
+ FrameMetadata(false, base::TimeDelta::FromMilliseconds(4))};
+
+ DiscardableImageMap::AnimatedImageMetadata data(
+ PaintImage::GetNextId(), PaintImage::CompletionState::PARTIALLY_DONE,
+ frames, kAnimationLoopInfinite, 0);
+ controller_->UpdateAnimatedImage(data);
+ FakeAnimationDriver driver;
+ controller_->RegisterAnimationDriver(data.paint_image_id, &driver);
+ controller_->UpdateStateFromDrivers(now_);
+
+ // Advance until the second frame.
+ LoopOnceNoDelay(data.paint_image_id, frames, 2, 0);
+
+ // We have no invalidation scheduled since its not possible to animate the
+ // image further until the second frame is completed.
+ invalidation_count_ = 0;
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 0);
+
+ // Completely load the image but the frame is still incomplete. It should not
+ // be advanced.
+ data.completion_state = PaintImage::CompletionState::DONE;
+ controller_->UpdateAnimatedImage(data);
+ controller_->UpdateStateFromDrivers(now_);
+
+ // No invalidation is scheduled since the last frame is still incomplete.
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 0);
+
+ controller_->UnregisterAnimationDriver(data.paint_image_id, &driver);
+}
+
+TEST_F(ImageAnimationControllerTest, DontLoopPartiallyLoadedImages) {
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))};
+
+ DiscardableImageMap::AnimatedImageMetadata data(
+ PaintImage::GetNextId(), PaintImage::CompletionState::PARTIALLY_DONE,
+ frames, 2, 0);
+ controller_->UpdateAnimatedImage(data);
+ FakeAnimationDriver driver;
+ controller_->RegisterAnimationDriver(data.paint_image_id, &driver);
+ controller_->UpdateStateFromDrivers(now_);
+
+ // Finish the first loop.
+ LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), 0);
+
+ // We shouldn't be looping back to the first frame until the image is known to
+ // be completely loaded.
+ invalidation_count_ = 0;
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 0);
+
+ // Now add another frame and mark the image complete. The animation should
+ // advance and we should see another repetition. This verifies that we don't
+ // mark loops complete on reaching the last frame until the image is
+ // completely loaded and the frame count is known to be accurate.
+ frames.push_back(FrameMetadata(true, base::TimeDelta::FromMilliseconds(4)));
+ data.completion_state = PaintImage::CompletionState::DONE;
+ data.frames = frames;
+ controller_->UpdateAnimatedImage(data);
+ controller_->UpdateStateFromDrivers(now_);
+
+ // The animation advances to the last frame. We don't have a delay since we
+ // already advanced to the desired time in the loop above.
+ task_runner_->VerifyDelay(base::TimeDelta());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 1);
+ auto animated_images = controller_->AnimateForSyncTree(now_);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::PENDING_TREE),
+ 2u);
+ EXPECT_EQ(animated_images.size(), 1u);
+ EXPECT_EQ(animated_images.count(data.paint_image_id), 1u);
+ controller_->DidActivate();
+
+ // Advancing the animation scheduled an invalidation for the next iteration.
+ task_runner_->VerifyDelay(frames.back().duration);
+
+ // Perform another loop in the animation.
+ AdvanceNow(frames.back().duration);
+ LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), 1);
+
+ // No invalidation should have been requested at the end of the second loop.
+ invalidation_count_ = 0;
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 0);
+
+ controller_->UnregisterAnimationDriver(data.paint_image_id, &driver);
+}
+
+TEST_F(ImageAnimationControllerTest, DontAdvanceUntilDesiredTime) {
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))};
+
+ DiscardableImageMap::AnimatedImageMetadata data(
+ PaintImage::GetNextId(), PaintImage::CompletionState::DONE, frames,
+ kAnimationLoopOnce, 0);
+ controller_->UpdateAnimatedImage(data);
+ FakeAnimationDriver driver;
+ controller_->RegisterAnimationDriver(data.paint_image_id, &driver);
+ controller_->UpdateStateFromDrivers(now_);
+
+ // Advance the first frame.
+ task_runner_->VerifyDelay(base::TimeDelta());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 1);
+ auto animated_images = controller_->AnimateForSyncTree(now_);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::PENDING_TREE),
+ 0u);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::ACTIVE_TREE),
+ 0u);
+ EXPECT_EQ(animated_images.size(), 0u);
+ controller_->DidActivate();
+
+ // We have an invalidation request for the second frame.
+ task_runner_->VerifyDelay(frames[0].duration);
+
+ // While there is still time for the second frame, we get a new sync tree. The
+ // animation is not advanced.
+ base::TimeDelta time_remaining = base::TimeDelta::FromMilliseconds(1);
+ AdvanceNow(frames[0].duration - time_remaining);
+ animated_images = controller_->AnimateForSyncTree(now_);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::PENDING_TREE),
+ 0u);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::ACTIVE_TREE),
+ 0u);
+ EXPECT_EQ(animated_images.size(), 0u);
+ controller_->DidActivate();
+
+ // We did not get another invalidation request because there is no change in
+ // the desired time and the previous request is still pending.
+ EXPECT_FALSE(task_runner_->has_delay());
+
+ // We have a sync tree before the invalidation task could run.
+ AdvanceNow(time_remaining);
+ animated_images = controller_->AnimateForSyncTree(now_);
+ EXPECT_EQ(animated_images.size(), 1u);
+ EXPECT_EQ(animated_images.count(data.paint_image_id), 1u);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::PENDING_TREE),
+ 1u);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::ACTIVE_TREE),
+ 0u);
+ controller_->DidActivate();
+
+ // We shouldn't have an invalidation because the animation was already
+ // advanced to the last frame and the previous one should have been cancelled.
+ invalidation_count_ = 0;
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 0);
+
+ controller_->UnregisterAnimationDriver(data.paint_image_id, &driver);
+}
+
+TEST_F(ImageAnimationControllerTest, RestartAfterSyncCutoff) {
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))};
+
+ DiscardableImageMap::AnimatedImageMetadata data(
+ PaintImage::GetNextId(), PaintImage::CompletionState::DONE, frames,
+ kAnimationLoopOnce, 0);
+ controller_->UpdateAnimatedImage(data);
+ FakeAnimationDriver driver;
+ controller_->RegisterAnimationDriver(data.paint_image_id, &driver);
+ controller_->UpdateStateFromDrivers(now_);
+
+ // Advance the first frame.
+ task_runner_->VerifyDelay(base::TimeDelta());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 1);
+ auto animated_images = controller_->AnimateForSyncTree(now_);
+ EXPECT_EQ(animated_images.size(), 0u);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::PENDING_TREE),
+ 0u);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::ACTIVE_TREE),
+ 0u);
+ controller_->DidActivate();
+
+ // Invalidation request for the second frame.
+ task_runner_->VerifyDelay(frames[0].duration);
+
+ // Advance the time by 10 min.
+ AdvanceNow(base::TimeDelta::FromMinutes(10));
+
+ // Animate again, it starts from the first frame. We don't see an
+ // invalidation, because that's the frame we are already displaying.
+ animated_images = controller_->AnimateForSyncTree(now_);
+ EXPECT_EQ(animated_images.size(), 0u);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::PENDING_TREE),
+ 0u);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::ACTIVE_TREE),
+ 0u);
+ controller_->DidActivate();
+
+ // New invalidation request since the desired invalidation time changed.
+ task_runner_->VerifyDelay(frames[0].duration);
+ invalidation_count_ = 0;
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 1);
+
+ controller_->UnregisterAnimationDriver(data.paint_image_id, &driver);
+}
+
+TEST_F(ImageAnimationControllerTest, DontSkipLoopsToCatchUpAfterLoad) {
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(4)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(5))};
+
+ DiscardableImageMap::AnimatedImageMetadata data(
+ PaintImage::GetNextId(), PaintImage::CompletionState::PARTIALLY_DONE,
+ frames, kAnimationLoopInfinite, 0);
+ controller_->UpdateAnimatedImage(data);
+ FakeAnimationDriver driver;
+ controller_->RegisterAnimationDriver(data.paint_image_id, &driver);
+ controller_->UpdateStateFromDrivers(now_);
+
+ // Perform the first loop while the image is partially loaded, until the third
+ // frame.
+ LoopOnceNoDelay(data.paint_image_id, frames, 3u, 0);
+
+ // The invalidation has been scheduled with a delay for the third frame's
+ // duration.
+ task_runner_->VerifyDelay(frames[2].duration);
+
+ // |now_| is set to the desired time for the fourth frame. Advance further so
+ // we would reach the time for the second frame.
+ AdvanceNow(frames[3].duration + frames[0].duration);
+
+ // Finish the image load.
+ data.completion_state = PaintImage::CompletionState::DONE;
+ controller_->UpdateAnimatedImage(data);
+ controller_->UpdateStateFromDrivers(now_);
+
+ // Invalidation is scheduled immediately because we are way past the desired
+ // time. We should start from the first frame after the image is loaded
+ // instead of skipping frames.
+ task_runner_->VerifyDelay(base::TimeDelta());
+ auto animated_images = controller_->AnimateForSyncTree(now_);
+ EXPECT_EQ(animated_images.size(), 1u);
+ EXPECT_EQ(animated_images.count(data.paint_image_id), 1u);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::PENDING_TREE),
+ 0u);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::ACTIVE_TREE),
+ 2u);
+ controller_->UnregisterAnimationDriver(data.paint_image_id, &driver);
+}
+
+TEST_F(ImageAnimationControllerTest, FinishRepetitionsDuringCatchUp) {
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(4))};
+
+ // The animation wants 3 loops.
+ DiscardableImageMap::AnimatedImageMetadata data(
+ PaintImage::GetNextId(), PaintImage::CompletionState::DONE, frames, 3, 0);
+ controller_->UpdateAnimatedImage(data);
+ FakeAnimationDriver driver;
+ controller_->RegisterAnimationDriver(data.paint_image_id, &driver);
+ controller_->UpdateStateFromDrivers(now_);
+
+ // Finish 2 loops.
+ LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), 0);
+ LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), 1);
+
+ // now_ is set to the desired time for the first frame. Advance it so we would
+ // reach way beyond the third repeition.
+ AdvanceNow(base::TimeDelta::FromMinutes(1));
+
+ // Advance the animation, we should see the last frame since the desired
+ // repetition count will be reached during catch up.
+ invalidation_count_ = 0;
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 1);
+ auto animated_images = controller_->AnimateForSyncTree(now_);
+ // No invalidation since the active tree is already at the last frame.
+ EXPECT_EQ(animated_images.size(), 0u);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::PENDING_TREE),
+ frames.size() - 1);
+ EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id,
+ WhichTree::ACTIVE_TREE),
+ frames.size() - 1);
+
+ controller_->UnregisterAnimationDriver(data.paint_image_id, &driver);
+}
+
+TEST_F(ImageAnimationControllerTest, ResetAnimations) {
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(3)),
+ FrameMetadata(true, base::TimeDelta::FromMilliseconds(4))};
+ DiscardableImageMap::AnimatedImageMetadata data(
+ PaintImage::GetNextId(), PaintImage::CompletionState::DONE, frames, 3,
+ 0u);
+ controller_->UpdateAnimatedImage(data);
+ FakeAnimationDriver driver;
+ controller_->RegisterAnimationDriver(data.paint_image_id, &driver);
+ controller_->UpdateStateFromDrivers(now_);
+
+ // Go uptill the second frame during the second iteration.
+ LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), 0);
+ LoopOnceNoDelay(data.paint_image_id, frames, 2u, 1);
+
+ // Reset the animation.
+ data.reset_animation_sequence_id++;
+ controller_->UpdateAnimatedImage(data);
+ controller_->UpdateStateFromDrivers(now_);
+
+ // It should start again from the first frame and do 3 loops.
+ for (int i = 0; i < 3; ++i) {
+ bool restarting = i == 0;
+ LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), i, restarting);
+ }
+
+ // No invalidation should be pending.
+ invalidation_count_ = 0;
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 0);
+
+ // Same image used again in a recording. There shouldn't be an invalidation
+ // since the reset sequence has already been synchronized.
+ controller_->UpdateAnimatedImage(data);
+ controller_->UpdateStateFromDrivers(now_);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(invalidation_count_, 0);
+
+ controller_->UnregisterAnimationDriver(data.paint_image_id, &driver);
+}
+
+} // namespace cc
diff --git a/chromium/cc/output/latency_info_swap_promise.cc b/chromium/cc/trees/latency_info_swap_promise.cc
index 8cf78cb4caf..3dcaf1ecf4b 100644
--- a/chromium/cc/output/latency_info_swap_promise.cc
+++ b/chromium/cc/trees/latency_info_swap_promise.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "cc/output/latency_info_swap_promise.h"
+#include "cc/trees/latency_info_swap_promise.h"
#include <stdint.h>
@@ -29,13 +29,11 @@ ui::LatencyComponentType DidNotSwapReasonToLatencyComponentType(
namespace cc {
LatencyInfoSwapPromise::LatencyInfoSwapPromise(const ui::LatencyInfo& latency)
- : latency_(latency) {
-}
+ : latency_(latency) {}
-LatencyInfoSwapPromise::~LatencyInfoSwapPromise() {
-}
+LatencyInfoSwapPromise::~LatencyInfoSwapPromise() = default;
-void LatencyInfoSwapPromise::WillSwap(CompositorFrameMetadata* metadata) {
+void LatencyInfoSwapPromise::WillSwap(viz::CompositorFrameMetadata* metadata) {
DCHECK(!latency_.terminated());
metadata->latency_info.push_back(latency_);
}
@@ -58,8 +56,7 @@ int64_t LatencyInfoSwapPromise::TraceId() const {
// Trace the original LatencyInfo of a LatencyInfoSwapPromise
void LatencyInfoSwapPromise::OnCommit() {
- TRACE_EVENT_WITH_FLOW1("input,benchmark",
- "LatencyInfo.Flow",
+ TRACE_EVENT_WITH_FLOW1("input,benchmark", "LatencyInfo.Flow",
TRACE_ID_DONT_MANGLE(TraceId()),
TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
"step", "HandleInputEventMainCommit");
diff --git a/chromium/cc/output/latency_info_swap_promise.h b/chromium/cc/trees/latency_info_swap_promise.h
index 91abe7d687d..2b23d67dc80 100644
--- a/chromium/cc/output/latency_info_swap_promise.h
+++ b/chromium/cc/trees/latency_info_swap_promise.h
@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CC_OUTPUT_LATENCY_INFO_SWAP_PROMISE_H_
-#define CC_OUTPUT_LATENCY_INFO_SWAP_PROMISE_H_
+#ifndef CC_TREES_LATENCY_INFO_SWAP_PROMISE_H_
+#define CC_TREES_LATENCY_INFO_SWAP_PROMISE_H_
#include <stdint.h>
#include "base/compiler_specific.h"
-#include "cc/output/swap_promise.h"
+#include "cc/trees/swap_promise.h"
#include "ui/latency/latency_info.h"
namespace cc {
@@ -19,7 +19,7 @@ class CC_EXPORT LatencyInfoSwapPromise : public SwapPromise {
~LatencyInfoSwapPromise() override;
void DidActivate() override {}
- void WillSwap(CompositorFrameMetadata* metadata) override;
+ void WillSwap(viz::CompositorFrameMetadata* metadata) override;
void DidSwap() override;
DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override;
void OnCommit() override;
@@ -32,4 +32,4 @@ class CC_EXPORT LatencyInfoSwapPromise : public SwapPromise {
} // namespace cc
-#endif // CC_OUTPUT_LATENCY_INFO_SWAP_PROMISE_H_
+#endif // CC_TREES_LATENCY_INFO_SWAP_PROMISE_H_
diff --git a/chromium/cc/trees/latency_info_swap_promise_monitor.cc b/chromium/cc/trees/latency_info_swap_promise_monitor.cc
index ddd1a09eb37..dc25793046a 100644
--- a/chromium/cc/trees/latency_info_swap_promise_monitor.cc
+++ b/chromium/cc/trees/latency_info_swap_promise_monitor.cc
@@ -7,7 +7,7 @@
#include <stdint.h>
#include "base/threading/platform_thread.h"
-#include "cc/output/latency_info_swap_promise.h"
+#include "cc/trees/latency_info_swap_promise.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/swap_promise_manager.h"
diff --git a/chromium/cc/output/layer_tree_frame_sink.cc b/chromium/cc/trees/layer_tree_frame_sink.cc
index 9a50b1d552b..795476973c5 100644
--- a/chromium/cc/output/layer_tree_frame_sink.cc
+++ b/chromium/cc/trees/layer_tree_frame_sink.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "cc/output/layer_tree_frame_sink.h"
+#include "cc/trees/layer_tree_frame_sink.h"
#include <stdint.h>
@@ -11,7 +11,7 @@
#include "base/macros.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
-#include "cc/output/layer_tree_frame_sink_client.h"
+#include "cc/trees/layer_tree_frame_sink_client.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/context_support.h"
#include "gpu/command_buffer/client/gles2_interface.h"
diff --git a/chromium/cc/output/layer_tree_frame_sink.h b/chromium/cc/trees/layer_tree_frame_sink.h
index 9033e0cde6c..4792c667ccc 100644
--- a/chromium/cc/output/layer_tree_frame_sink.h
+++ b/chromium/cc/trees/layer_tree_frame_sink.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CC_OUTPUT_LAYER_TREE_FRAME_SINK_H_
-#define CC_OUTPUT_LAYER_TREE_FRAME_SINK_H_
+#ifndef CC_TREES_LAYER_TREE_FRAME_SINK_H_
+#define CC_TREES_LAYER_TREE_FRAME_SINK_H_
#include <deque>
#include <memory>
@@ -12,7 +12,6 @@
#include "base/memory/ref_counted.h"
#include "base/threading/thread_checker.h"
#include "cc/cc_export.h"
-#include "cc/output/overlay_candidate_validator.h"
#include "components/viz/common/gpu/context_provider.h"
#include "components/viz/common/gpu/vulkan_context_provider.h"
#include "components/viz/common/resources/returned_resource.h"
@@ -24,14 +23,13 @@ class GpuMemoryBufferManager;
}
namespace viz {
+class CompositorFrame;
class LocalSurfaceId;
class SharedBitmapManager;
struct BeginFrameAck;
-}
+} // namespace viz
namespace cc {
-
-class CompositorFrame;
class LayerTreeFrameSinkClient;
// An interface for submitting CompositorFrames to a display compositor
@@ -125,7 +123,7 @@ class CC_EXPORT LayerTreeFrameSink {
// For successful swaps, the implementation must call
// DidReceiveCompositorFrameAck() asynchronously when the frame has been
// processed in order to unthrottle the next frame.
- virtual void SubmitCompositorFrame(CompositorFrame frame) = 0;
+ virtual void SubmitCompositorFrame(viz::CompositorFrame frame) = 0;
// Signals that a BeginFrame issued by the viz::BeginFrameSource provided to
// the client did not lead to a CompositorFrame submission.
@@ -151,4 +149,4 @@ class CC_EXPORT LayerTreeFrameSink {
} // namespace cc
-#endif // CC_OUTPUT_LAYER_TREE_FRAME_SINK_H_
+#endif // CC_TREES_LAYER_TREE_FRAME_SINK_H_
diff --git a/chromium/cc/output/layer_tree_frame_sink_client.h b/chromium/cc/trees/layer_tree_frame_sink_client.h
index ff114a7549b..b1587eefa07 100644
--- a/chromium/cc/output/layer_tree_frame_sink_client.h
+++ b/chromium/cc/trees/layer_tree_frame_sink_client.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CC_OUTPUT_LAYER_TREE_FRAME_SINK_CLIENT_H_
-#define CC_OUTPUT_LAYER_TREE_FRAME_SINK_CLIENT_H_
+#ifndef CC_TREES_LAYER_TREE_FRAME_SINK_CLIENT_H_
+#define CC_TREES_LAYER_TREE_FRAME_SINK_CLIENT_H_
#include "base/callback.h"
#include "base/memory/ref_counted.h"
@@ -77,4 +77,4 @@ class CC_EXPORT LayerTreeFrameSinkClient {
} // namespace cc
-#endif // CC_OUTPUT_LAYER_TREE_FRAME_SINK_CLIENT_H_
+#endif // CC_TREES_LAYER_TREE_FRAME_SINK_CLIENT_H_
diff --git a/chromium/cc/output/layer_tree_frame_sink_unittest.cc b/chromium/cc/trees/layer_tree_frame_sink_unittest.cc
index 9eb669c55ae..9895cfad81f 100644
--- a/chromium/cc/output/layer_tree_frame_sink_unittest.cc
+++ b/chromium/cc/trees/layer_tree_frame_sink_unittest.cc
@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "cc/output/layer_tree_frame_sink.h"
+#include "cc/trees/layer_tree_frame_sink.h"
#include "base/memory/ptr_util.h"
-#include "cc/output/compositor_frame.h"
#include "cc/test/fake_layer_tree_frame_sink_client.h"
#include "cc/test/test_context_provider.h"
#include "cc/test/test_web_graphics_context_3d.h"
+#include "components/viz/common/quads/compositor_frame.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -25,7 +25,7 @@ class TestLayerTreeFrameSink : public LayerTreeFrameSink {
nullptr,
nullptr) {}
- void SubmitCompositorFrame(CompositorFrame frame) override {
+ void SubmitCompositorFrame(viz::CompositorFrame frame) override {
client_->DidReceiveCompositorFrameAck();
}
void DidNotProduceFrame(const viz::BeginFrameAck& ack) override {}
diff --git a/chromium/cc/trees/layer_tree_host.cc b/chromium/cc/trees/layer_tree_host.cc
index e1faf99f04b..686aeacf7cd 100644
--- a/chromium/cc/trees/layer_tree_host.cc
+++ b/chromium/cc/trees/layer_tree_host.cc
@@ -9,7 +9,6 @@
#include <algorithm>
#include <memory>
-#include <stack>
#include <string>
#include <unordered_map>
@@ -858,8 +857,8 @@ void LayerTreeHost::UpdateBrowserControlsState(
BrowserControlsState constraints,
BrowserControlsState current,
bool animate) {
- // Browser controls are only used in threaded mode.
- DCHECK(IsThreaded());
+ // Browser controls are only used in threaded mode but Blink layout tests may
+ // call into this. The single threaded version is a no-op.
proxy_->UpdateBrowserControlsState(constraints, current, animate);
}
@@ -1234,7 +1233,6 @@ void LayerTreeHost::PushLayerTreePropertiesTo(LayerTreeImpl* tree_impl) {
}
tree_impl->set_background_color(background_color_);
- tree_impl->set_has_transparent_background(has_transparent_background_);
tree_impl->set_have_scroll_event_handlers(have_scroll_event_handlers_);
tree_impl->set_event_listener_properties(
EventListenerClass::kTouchStartOrMove,
@@ -1458,9 +1456,7 @@ void LayerTreeHost::ElementIsAnimatingChanged(
gfx::ScrollOffset LayerTreeHost::GetScrollOffsetForAnimation(
ElementId element_id) const {
- Layer* layer = LayerByElementId(element_id);
- DCHECK(layer);
- return layer->ScrollOffsetForAnimation();
+ return property_trees()->scroll_tree.current_scroll_offset(element_id);
}
void LayerTreeHost::QueueImageDecode(
diff --git a/chromium/cc/trees/layer_tree_host.h b/chromium/cc/trees/layer_tree_host.h
index 61839e67954..96d2ff8f483 100644
--- a/chromium/cc/trees/layer_tree_host.h
+++ b/chromium/cc/trees/layer_tree_host.h
@@ -33,13 +33,13 @@
#include "cc/input/scrollbar.h"
#include "cc/layers/layer_collections.h"
#include "cc/layers/layer_list_iterator.h"
-#include "cc/output/layer_tree_frame_sink.h"
-#include "cc/output/swap_promise.h"
#include "cc/trees/compositor_mode.h"
+#include "cc/trees/layer_tree_frame_sink.h"
#include "cc/trees/layer_tree_host_client.h"
#include "cc/trees/layer_tree_settings.h"
#include "cc/trees/mutator_host.h"
#include "cc/trees/proxy.h"
+#include "cc/trees/swap_promise.h"
#include "cc/trees/swap_promise_manager.h"
#include "cc/trees/target_property.h"
#include "components/viz/common/resources/resource_format.h"
@@ -307,13 +307,6 @@ class CC_EXPORT LayerTreeHost : public viz::SurfaceReferenceOwner,
void set_background_color(SkColor color) { background_color_ = color; }
SkColor background_color() const { return background_color_; }
- void set_has_transparent_background(bool transparent) {
- has_transparent_background_ = transparent;
- }
- bool has_transparent_background() const {
- return has_transparent_background_;
- }
-
void StartPageScaleAnimation(const gfx::Vector2d& target_offset,
bool use_anchor,
float scale,
@@ -349,6 +342,7 @@ class CC_EXPORT LayerTreeHost : public viz::SurfaceReferenceOwner,
// UseLayerLists() is true, which also implies that Slimming Paint
// v2 is enabled.
PropertyTrees* property_trees() { return &property_trees_; }
+ const PropertyTrees* property_trees() const { return &property_trees_; }
void SetNeedsDisplayOnAllLayers();
@@ -626,7 +620,6 @@ class CC_EXPORT LayerTreeHost : public viz::SurfaceReferenceOwner,
bool defer_commits_ = false;
SkColor background_color_ = SK_ColorWHITE;
- bool has_transparent_background_ = false;
LayerSelection selection_;
diff --git a/chromium/cc/trees/layer_tree_host_client.h b/chromium/cc/trees/layer_tree_host_client.h
index 33cbb931e15..3c55d39e95e 100644
--- a/chromium/cc/trees/layer_tree_host_client.h
+++ b/chromium/cc/trees/layer_tree_host_client.h
@@ -20,27 +20,50 @@ struct BeginFrameArgs;
namespace cc {
+// A LayerTreeHost is bound to a LayerTreeHostClient. The main rendering
+// loop (in ProxyMain or SingleThreadProxy) calls methods on the
+// LayerTreeHost, which then handles them and also calls into the equivalent
+// methods on its LayerTreeHostClient when applicable.
+//
+// One important example of a LayerTreeHostClient is (via additional
+// indirections) Blink.
class LayerTreeHostClient {
public:
virtual void WillBeginMainFrame() = 0;
// Marks finishing compositing-related tasks on the main thread. In threaded
// mode, this corresponds to DidCommit().
+
+ // For a LayerTreeHostClient backed by Blink, BeginMainFrame will:
+ // -Dispatch BeginMainFrame-aligned input events.
+ // -Advance frame-synchronized animations and callbacks. These include
+ // gesture animations, autoscroll animations, declarative
+ // CSS animations (including both main-thread and compositor thread
+ // animations), and script-implemented requestAnimationFrame animations.
+ //
+ // Note: CSS animations which run on the main thread invalidate rendering
+ // phases as appropriate. CSS animations which run on the compositor
+ // invalidate styles, and then update transforms or opacity on the Layer tree.
+ // Compositor animations need to be updated here, because there is no
+ // other mechanism by which the compositor syncs animation state for these
+ // animations to Blink.
virtual void BeginMainFrame(const viz::BeginFrameArgs& args) = 0;
+
virtual void BeginMainFrameNotExpectedSoon() = 0;
virtual void BeginMainFrameNotExpectedUntil(base::TimeTicks time) = 0;
virtual void DidBeginMainFrame() = 0;
- // A LayerTreeHost is bound to a LayerTreeHostClient. Visual frame-based
- // updates to the state of the LayerTreeHost are expected to happen only in
- // calls to LayerTreeHostClient::UpdateLayerTreeHost, which should
- // mutate/invalidate the layer tree or other page parameters as appropriate.
+
+ // Visual frame-based updates to the state of the LayerTreeHost are expected
+ // to happen only in calls to LayerTreeHostClient::UpdateLayerTreeHost, which
+ // should mutate/invalidate the layer tree or other page parameters as
+ // appropriate.
//
- // An example of a LayerTreeHostClient is (via additional indirections) Blink,
- // which inside of LayerTreeHostClient::UpdateLayerTreeHost will update
+ // For a LayerTreeHostClient backed by Blink, this method will update
// (Blink's notions of) style, layout, paint invalidation and compositing
// state. (The "compositing state" will result in a mutated layer tree on the
// LayerTreeHost via additional interface indirections which lead back to
// mutations on the LayerTreeHost.)
virtual void UpdateLayerTreeHost() = 0;
+
virtual void ApplyViewportDeltas(
const gfx::Vector2dF& inner_delta,
const gfx::Vector2dF& outer_delta,
diff --git a/chromium/cc/trees/layer_tree_host_common.cc b/chromium/cc/trees/layer_tree_host_common.cc
index 75ea1df5610..54de02858c8 100644
--- a/chromium/cc/trees/layer_tree_host_common.cc
+++ b/chromium/cc/trees/layer_tree_host_common.cc
@@ -402,8 +402,7 @@ static void ComputeInitialRenderSurfaceList(
}
}
-static void ComputeSurfaceContentRects(LayerTreeImpl* layer_tree_impl,
- PropertyTrees* property_trees,
+static void ComputeSurfaceContentRects(PropertyTrees* property_trees,
RenderSurfaceList* render_surface_list,
int max_texture_size) {
// Walk the list backwards, accumulating each surface's content rect into its
@@ -480,8 +479,8 @@ static void CalculateRenderSurfaceLayerList(
// produce a final list that omits empty surfaces.
ComputeInitialRenderSurfaceList(layer_tree_impl, property_trees,
&initial_render_surface_list);
- ComputeSurfaceContentRects(layer_tree_impl, property_trees,
- &initial_render_surface_list, max_texture_size);
+ ComputeSurfaceContentRects(property_trees, &initial_render_surface_list,
+ max_texture_size);
ComputeListOfNonEmptySurfaces(layer_tree_impl, property_trees,
&initial_render_surface_list,
render_surface_list);
diff --git a/chromium/cc/trees/layer_tree_host_common_perftest.cc b/chromium/cc/trees/layer_tree_host_common_perftest.cc
index b20ceedc58f..c1f7908f3bd 100644
--- a/chromium/cc/trees/layer_tree_host_common_perftest.cc
+++ b/chromium/cc/trees/layer_tree_host_common_perftest.cc
@@ -4,7 +4,6 @@
#include <stddef.h>
-#include <deque>
#include <memory>
#include <sstream>
diff --git a/chromium/cc/trees/layer_tree_host_common_unittest.cc b/chromium/cc/trees/layer_tree_host_common_unittest.cc
index 48ae628c625..717ad4f6a6d 100644
--- a/chromium/cc/trees/layer_tree_host_common_unittest.cc
+++ b/chromium/cc/trees/layer_tree_host_common_unittest.cc
@@ -45,8 +45,8 @@
#include "cc/trees/single_thread_proxy.h"
#include "cc/trees/task_runner_provider.h"
#include "cc/trees/transform_node.h"
-#include "components/viz/common/quads/copy_output_request.h"
-#include "components/viz/common/quads/copy_output_result.h"
+#include "components/viz/common/frame_sinks/copy_output_request.h"
+#include "components/viz/common/frame_sinks/copy_output_result.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkImageFilter.h"
#include "third_party/skia/include/effects/SkOffsetImageFilter.h"
@@ -548,10 +548,9 @@ TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
nullptr, nullptr);
gfx::Transform expected_transform;
gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
- expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() *
- page_scale * kDeviceScale),
- MathUtil::Round(sub_layer_screen_position.y() *
- page_scale * kDeviceScale));
+ expected_transform.Translate(
+ std::round(sub_layer_screen_position.x() * page_scale * kDeviceScale),
+ std::round(sub_layer_screen_position.y() * page_scale * kDeviceScale));
expected_transform.Scale(page_scale * kDeviceScale,
page_scale * kDeviceScale);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
@@ -570,12 +569,10 @@ TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
nullptr, nullptr);
expected_transform.MakeIdentity();
expected_transform.Translate(
- MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
- sub_layer_screen_position.x() * page_scale *
- kDeviceScale),
- MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
- sub_layer_screen_position.y() * page_scale *
- kDeviceScale));
+ std::round(kTranslateX * page_scale * kDeviceScale +
+ sub_layer_screen_position.x() * page_scale * kDeviceScale),
+ std::round(kTranslateY * page_scale * kDeviceScale +
+ sub_layer_screen_position.y() * page_scale * kDeviceScale));
expected_transform.Scale(page_scale * kDeviceScale,
page_scale * kDeviceScale);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
@@ -595,12 +592,10 @@ TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
expected_transform.MakeIdentity();
expected_transform.Translate(
- MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
- sub_layer_screen_position.x() * page_scale *
- kDeviceScale),
- MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
- sub_layer_screen_position.y() * page_scale *
- kDeviceScale));
+ std::round(kTranslateX * page_scale * kDeviceScale +
+ sub_layer_screen_position.x() * page_scale * kDeviceScale),
+ std::round(kTranslateY * page_scale * kDeviceScale +
+ sub_layer_screen_position.y() * page_scale * kDeviceScale));
expected_transform.Scale(page_scale * kDeviceScale,
page_scale * kDeviceScale);
EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
@@ -1399,7 +1394,7 @@ TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
ASSERT_TRUE(GetRenderSurface(root));
EXPECT_EQ(0, GetRenderSurface(root)->num_contributors());
EXPECT_EQ(1U, render_surface_list.size());
- EXPECT_EQ(static_cast<RenderPassId>(root->id()),
+ EXPECT_EQ(static_cast<viz::RenderPassId>(root->id()),
render_surface_list.at(0)->id());
EXPECT_EQ(gfx::Rect(), root->drawable_content_rect());
}
@@ -4808,8 +4803,6 @@ TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
EXPECT_FALSE(grand_child_layer->contributes_to_drawn_render_surface());
}
-void EmptyCopyOutputCallback(std::unique_ptr<viz::CopyOutputResult> result) {}
-
TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
FakeImplTaskRunnerProvider task_runner_provider;
TestTaskGraphRunner task_graph_runner;
@@ -4889,8 +4882,7 @@ TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true;
copy_layer->test_properties()->copy_requests.push_back(
- viz::CopyOutputRequest::CreateRequest(
- base::BindOnce(&EmptyCopyOutputCallback)));
+ viz::CopyOutputRequest::CreateStubForTesting());
RenderSurfaceList render_surface_list;
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
@@ -4986,8 +4978,7 @@ TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
copy_child->SetDrawsContent(true);
copy_layer->test_properties()->copy_requests.push_back(
- viz::CopyOutputRequest::CreateRequest(
- base::BindOnce(&EmptyCopyOutputCallback)));
+ viz::CopyOutputRequest::CreateStubForTesting());
copy_layer->test_properties()->AddChild(std::move(copy_child));
copy_parent->test_properties()->AddChild(std::move(copy_layer));
@@ -5028,8 +5019,7 @@ TEST_F(LayerTreeHostCommonTest, SingularTransformAndCopyRequests) {
copy_layer->SetBounds(gfx::Size(100, 100));
copy_layer->SetDrawsContent(true);
copy_layer->test_properties()->copy_requests.push_back(
- viz::CopyOutputRequest::CreateRequest(
- base::BindOnce(&EmptyCopyOutputCallback)));
+ viz::CopyOutputRequest::CreateStubForTesting());
LayerImpl* copy_child = AddChild<LayerImpl>(copy_layer);
copy_child->SetBounds(gfx::Size(100, 100));
@@ -5089,8 +5079,7 @@ TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) {
copy_surface->test_properties()->force_render_surface = true;
copy_layer->test_properties()->copy_requests.push_back(
- viz::CopyOutputRequest::CreateRequest(
- base::BindOnce(&EmptyCopyOutputCallback)));
+ viz::CopyOutputRequest::CreateStubForTesting());
DCHECK(!copy_layer->test_properties()->copy_requests.empty());
ExecuteCalculateDrawProperties(root);
@@ -5105,8 +5094,7 @@ TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) {
copy_layer->SetBounds(gfx::Size(50, 50));
copy_layer->SetMasksToBounds(true);
copy_layer->test_properties()->copy_requests.push_back(
- viz::CopyOutputRequest::CreateRequest(
- base::BindOnce(&EmptyCopyOutputCallback)));
+ viz::CopyOutputRequest::CreateStubForTesting());
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
DCHECK(!copy_layer->test_properties()->copy_requests.empty());
@@ -5121,8 +5109,7 @@ TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCopyRequest) {
// Case 3: When there is device scale factor.
float device_scale_factor = 2.f;
copy_layer->test_properties()->copy_requests.push_back(
- viz::CopyOutputRequest::CreateRequest(
- base::BindOnce(&EmptyCopyOutputCallback)));
+ viz::CopyOutputRequest::CreateStubForTesting());
DCHECK(!copy_layer->test_properties()->copy_requests.empty());
ExecuteCalculateDrawProperties(root, device_scale_factor);
@@ -8584,8 +8571,6 @@ TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
EXPECT_EQ(gfx::Rect(0, 10, 25, 25), scroll_child->visible_layer_rect());
}
-static void CopyOutputCallback(std::unique_ptr<viz::CopyOutputResult> result) {}
-
TEST_F(LayerTreeHostCommonTest, HasCopyRequestsInTargetSubtree) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<Layer> child1 = Layer::Create();
@@ -8599,11 +8584,9 @@ TEST_F(LayerTreeHostCommonTest, HasCopyRequestsInTargetSubtree) {
grandchild->AddChild(greatgrandchild);
host()->SetRootLayer(root);
- child1->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest(
- base::BindOnce(&CopyOutputCallback)));
+ child1->RequestCopyOfOutput(viz::CopyOutputRequest::CreateStubForTesting());
greatgrandchild->RequestCopyOfOutput(
- viz::CopyOutputRequest::CreateBitmapRequest(
- base::BindOnce(&CopyOutputCallback)));
+ viz::CopyOutputRequest::CreateStubForTesting());
child2->SetOpacity(0.f);
ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
@@ -8619,9 +8602,9 @@ TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
FakeContentLayerClient client;
client.set_bounds(root->bounds());
scoped_refptr<LayerWithForcedDrawsContent> child =
- make_scoped_refptr(new LayerWithForcedDrawsContent());
+ base::MakeRefCounted<LayerWithForcedDrawsContent>();
scoped_refptr<LayerWithForcedDrawsContent> grandchild =
- make_scoped_refptr(new LayerWithForcedDrawsContent());
+ base::MakeRefCounted<LayerWithForcedDrawsContent>();
scoped_refptr<FakePictureLayer> greatgrandchild(
FakePictureLayer::Create(&client));
@@ -8678,7 +8661,7 @@ TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
update_list = GetUpdateLayerList();
EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
- RemoveAnimationFromElementWithExistingPlayer(child->element_id(), timeline(),
+ RemoveAnimationFromElementWithExistingTicker(child->element_id(), timeline(),
animation_id);
child->SetTransform(gfx::Transform());
child->SetOpacity(0.f);
@@ -8689,8 +8672,8 @@ TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
// Now, even though child has zero opacity, we will configure |grandchild| and
// |greatgrandchild| in several ways that should force the subtree to be
// processed anyhow.
- grandchild->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest(
- base::BindOnce(&CopyOutputCallback)));
+ grandchild->RequestCopyOfOutput(
+ viz::CopyOutputRequest::CreateStubForTesting());
ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
update_list = GetUpdateLayerList();
EXPECT_TRUE(VerifyLayerInList(grandchild, update_list));
@@ -8702,7 +8685,7 @@ TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
animation_id, 1, TargetProperty::OPACITY);
animation->set_fill_mode(Animation::FillMode::NONE);
animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
- AddAnimationToElementWithExistingPlayer(child->element_id(), timeline(),
+ AddAnimationToElementWithExistingTicker(child->element_id(), timeline(),
std::move(animation));
ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
update_list = GetUpdateLayerList();
@@ -8803,7 +8786,7 @@ TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) {
// |greatgrandchild| in several ways that should force the subtree to be
// processed anyhow.
grandchild_ptr->test_properties()->copy_requests.push_back(
- viz::CopyOutputRequest::CreateEmptyRequest());
+ viz::CopyOutputRequest::CreateStubForTesting());
root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr);
EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
@@ -8836,6 +8819,9 @@ TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) {
std::unique_ptr<Animation> transform_animation(
Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
+ timeline()->AttachPlayer(player);
+ // TODO(smcgruer): Should attach a timeline and element rather than call this
+ // directly. See http://crbug.com/771316
host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(),
player.get());
player->AddAnimation(std::move(transform_animation));
@@ -8848,6 +8834,7 @@ TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) {
host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(),
player.get());
+ timeline()->DetachPlayer(player);
}
TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) {
@@ -8883,6 +8870,9 @@ TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) {
std::unique_ptr<Animation> transform_animation(
Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
+ timeline()->AttachPlayer(player);
+ // TODO(smcgruer): Should attach a timeline and element rather than call this
+ // directly. See http://crbug.com/771316
host_impl()->animation_host()->RegisterPlayerForElement(
grand_child->element_id(), player.get());
player->AddAnimation(std::move(transform_animation));
@@ -8893,6 +8883,7 @@ TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) {
host_impl()->animation_host()->UnregisterPlayerForElement(
grand_child->element_id(), player.get());
+ timeline()->DetachPlayer(player);
}
TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) {
@@ -8943,6 +8934,9 @@ TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) {
std::unique_ptr<Animation> animation(
Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY));
scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
+ timeline()->AttachPlayer(player);
+ // TODO(smcgruer): Should attach a timeline and element rather than call this
+ // directly. See http://crbug.com/771316
host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(),
player.get());
player->AddAnimation(std::move(animation));
@@ -8954,6 +8948,7 @@ TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) {
host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(),
player.get());
+ timeline()->DetachPlayer(player);
}
TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
@@ -9012,8 +9007,7 @@ TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
parent->AddChild(child);
host()->SetRootLayer(root);
- child->RequestCopyOfOutput(viz::CopyOutputRequest::CreateRequest(
- base::BindOnce(&EmptyCopyOutputCallback)));
+ child->RequestCopyOfOutput(viz::CopyOutputRequest::CreateStubForTesting());
ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
EXPECT_TRUE(root->has_copy_requests_in_target_subtree());
@@ -9719,7 +9713,7 @@ TEST_F(LayerTreeHostCommonTest, LargeTransformTest) {
TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> child =
- make_scoped_refptr(new LayerWithForcedDrawsContent());
+ base::MakeRefCounted<LayerWithForcedDrawsContent>();
root->AddChild(child);
host()->SetRootLayer(root);
@@ -9761,7 +9755,7 @@ TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) {
TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> animated =
- make_scoped_refptr(new LayerWithForcedDrawsContent());
+ base::MakeRefCounted<LayerWithForcedDrawsContent>();
root->AddChild(animated);
host()->SetRootLayer(root);
host()->SetElementIdsForTesting();
@@ -9784,7 +9778,7 @@ TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) {
animation->set_fill_mode(Animation::FillMode::NONE);
animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
Animation* animation_ptr = animation.get();
- AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
+ AddAnimationToElementWithExistingTicker(animated->element_id(), timeline(),
std::move(animation));
ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
@@ -9809,7 +9803,7 @@ TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) {
TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) {
scoped_refptr<Layer> root = Layer::Create();
scoped_refptr<LayerWithForcedDrawsContent> animated =
- make_scoped_refptr(new LayerWithForcedDrawsContent());
+ base::MakeRefCounted<LayerWithForcedDrawsContent>();
root->AddChild(animated);
host()->SetRootLayer(root);
host()->SetElementIdsForTesting();
@@ -9840,7 +9834,7 @@ TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) {
animation->set_fill_mode(Animation::FillMode::NONE);
animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
Animation* animation_ptr = animation.get();
- AddAnimationToElementWithExistingPlayer(animated->element_id(), timeline(),
+ AddAnimationToElementWithExistingTicker(animated->element_id(), timeline(),
std::move(animation));
ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root.get());
@@ -10116,8 +10110,7 @@ TEST_F(LayerTreeHostCommonTest, SurfaceContentsScaleChangeWithCopyRequestTest) {
// Need to persist the render surface after copy request is cleared.
copy_layer->test_properties()->force_render_surface = true;
copy_layer->test_properties()->copy_requests.push_back(
- viz::CopyOutputRequest::CreateRequest(
- base::Bind(&EmptyCopyOutputCallback)));
+ viz::CopyOutputRequest::CreateStubForTesting());
clip_layer->SetDrawsContent(true);
clip_layer->SetMasksToBounds(true);
@@ -10367,8 +10360,7 @@ TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCacheRenderSurface) {
// Case 4: When the non root cache render surface layer is clipped and there
// is a copy request layer beneath it.
copy_layer->test_properties()->copy_requests.push_back(
- viz::CopyOutputRequest::CreateRequest(
- base::Bind(&EmptyCopyOutputCallback)));
+ viz::CopyOutputRequest::CreateStubForTesting());
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
DCHECK(!copy_layer->test_properties()->copy_requests.empty());
ExecuteCalculateDrawProperties(root);
@@ -10384,8 +10376,7 @@ TEST_F(LayerTreeHostCommonTest, VisibleRectInNonRootCacheRenderSurface) {
// request layer.
cache_surface->test_properties()->cache_render_surface = true;
copy_layer->test_properties()->copy_requests.push_back(
- viz::CopyOutputRequest::CreateRequest(
- base::Bind(&EmptyCopyOutputCallback)));
+ viz::CopyOutputRequest::CreateStubForTesting());
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
DCHECK(!copy_layer->test_properties()->copy_requests.empty());
ExecuteCalculateDrawProperties(root);
@@ -10444,5 +10435,41 @@ TEST_F(LayerTreeHostCommonTest, BuildPropertyNodesForScrollChildrenInOrder) {
}
}
+TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTrilinearFiltering) {
+ LayerImpl* root = root_layer_for_testing();
+ LayerImpl* parent = AddChild<LayerImpl>(root);
+ LayerImpl* child1 = AddChild<LayerImpl>(parent);
+ LayerImpl* child2 = AddChild<LayerImpl>(parent);
+
+ gfx::Transform scale_matrix;
+ scale_matrix.Scale(.25f, .25f);
+
+ root->SetBounds(gfx::Size(200, 200));
+ parent->test_properties()->transform = scale_matrix;
+ parent->test_properties()->trilinear_filtering = true;
+ child1->SetBounds(gfx::Size(50, 50));
+ child1->SetDrawsContent(true);
+ child1->test_properties()->force_render_surface = true;
+ child2->SetPosition(gfx::PointF(50, 50));
+ child2->SetBounds(gfx::Size(50, 50));
+ child2->SetDrawsContent(true);
+ child2->test_properties()->force_render_surface = true;
+
+ RenderSurfaceList render_surface_list;
+ LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
+ root, root->bounds(), &render_surface_list);
+ inputs.can_adjust_raster_scales = true;
+ LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
+
+ ASSERT_TRUE(GetRenderSurface(parent));
+ EXPECT_EQ(2, GetRenderSurface(parent)->num_contributors());
+ EXPECT_EQ(4U, render_surface_list.size());
+
+ // The rectangle enclosing child1 and child2 (0,0 100x100), scaled by the
+ // scale matrix to (0,0 25x25).
+ EXPECT_EQ(gfx::RectF(0, 0, 25, 25),
+ GetRenderSurface(parent)->DrawableContentRect());
+}
+
} // namespace
} // namespace cc
diff --git a/chromium/cc/trees/layer_tree_host_impl.cc b/chromium/cc/trees/layer_tree_host_impl.cc
index 8feb8a28f1f..bcdfe0a2c34 100644
--- a/chromium/cc/trees/layer_tree_host_impl.cc
+++ b/chromium/cc/trees/layer_tree_host_impl.cc
@@ -45,12 +45,6 @@
#include "cc/layers/scrollbar_layer_impl_base.h"
#include "cc/layers/surface_layer_impl.h"
#include "cc/layers/viewport.h"
-#include "cc/output/compositor_frame.h"
-#include "cc/output/compositor_frame_metadata.h"
-#include "cc/output/layer_tree_frame_sink.h"
-#include "cc/quads/render_pass_draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
#include "cc/raster/bitmap_raster_buffer_provider.h"
#include "cc/raster/gpu_raster_buffer_provider.h"
#include "cc/raster/one_copy_raster_buffer_provider.h"
@@ -71,7 +65,9 @@
#include "cc/trees/draw_property_utils.h"
#include "cc/trees/effect_node.h"
#include "cc/trees/frame_rate_counter.h"
+#include "cc/trees/image_animation_controller.h"
#include "cc/trees/latency_info_swap_promise_monitor.h"
+#include "cc/trees/layer_tree_frame_sink.h"
#include "cc/trees/layer_tree_host_common.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/mutator_host.h"
@@ -79,13 +75,19 @@
#include "cc/trees/single_thread_proxy.h"
#include "cc/trees/transform_node.h"
#include "cc/trees/tree_synchronizer.h"
+#include "components/viz/common/frame_sinks/copy_output_request.h"
#include "components/viz/common/frame_sinks/delay_based_time_source.h"
-#include "components/viz/common/quads/copy_output_request.h"
+#include "components/viz/common/quads/compositor_frame.h"
+#include "components/viz/common/quads/compositor_frame_metadata.h"
+#include "components/viz/common/quads/render_pass_draw_quad.h"
#include "components/viz/common/quads/shared_quad_state.h"
+#include "components/viz/common/quads/solid_color_draw_quad.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
#include "components/viz/common/traced_value.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/context_support.h"
#include "gpu/command_buffer/client/gles2_interface.h"
+#include "third_party/skia/include/gpu/GrContext.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/scroll_offset.h"
@@ -270,6 +272,16 @@ LayerTreeHostImpl::LayerTreeHostImpl(
settings.top_controls_hide_threshold);
tile_manager_.SetDecodedImageTracker(&decoded_image_tracker_);
+
+ if (settings_.enable_image_animations) {
+ // It is safe to use base::Unretained here since we will outlive the
+ // ImageAnimationController.
+ base::Closure invalidation_callback =
+ base::Bind(&LayerTreeHostImpl::RequestInvalidationForAnimatedImages,
+ base::Unretained(this));
+ image_animation_controller_.emplace(GetTaskRunner(),
+ std::move(invalidation_callback));
+ }
}
LayerTreeHostImpl::~LayerTreeHostImpl() {
@@ -344,9 +356,6 @@ void LayerTreeHostImpl::CommitComplete() {
}
void LayerTreeHostImpl::UpdateSyncTreeAfterCommitOrImplSideInvalidation() {
- sync_tree()->InvalidateRegionForImages(
- tile_manager_.TakeImagesToInvalidateOnSyncTree());
-
if (CommitToActiveTree()) {
active_tree_->HandleScrollbarShowRequestsFromMain();
@@ -382,6 +391,20 @@ void LayerTreeHostImpl::UpdateSyncTreeAfterCommitOrImplSideInvalidation() {
// layer can or cannot use lcd text. So, this is the cleanup pass to
// determine if lcd state needs to switch due to draw properties.
sync_tree()->UpdateCanUseLCDText();
+
+ // Defer invalidating images until UpdateDrawProperties is performed since
+ // that updates whether an image should be animated based on its visibility
+ // and the updated data for the image from the main frame.
+ PaintImageIdFlatSet images_to_invalidate =
+ tile_manager_.TakeImagesToInvalidateOnSyncTree();
+ if (image_animation_controller_.has_value()) {
+ const auto& animated_images =
+ image_animation_controller_.value().AnimateForSyncTree(
+ CurrentBeginFrameArgs().frame_time);
+ images_to_invalidate.insert(animated_images.begin(), animated_images.end());
+ }
+ sync_tree()->InvalidateRegionForImages(images_to_invalidate);
+
// Start working on newly created tiles immediately if needed.
// TODO(vmpstr): Investigate always having PrepareTiles issue
// NotifyReadyToActivate, instead of handling it here.
@@ -744,7 +767,7 @@ DrawMode LayerTreeHostImpl::GetDrawMode() const {
static void AppendQuadsToFillScreen(
const gfx::Rect& root_scroll_layer_rect,
- RenderPass* target_render_pass,
+ viz::RenderPass* target_render_pass,
const RenderSurfaceImpl* root_render_surface,
SkColor screen_background_color,
const Region& fill_region) {
@@ -761,11 +784,13 @@ static void AppendQuadsToFillScreen(
gfx::Rect root_target_rect = root_render_surface->content_rect();
float opacity = 1.f;
int sorting_context_id = 0;
+ bool are_contents_opaque = SkColorGetA(screen_background_color) == 0xFF;
viz::SharedQuadState* shared_quad_state =
target_render_pass->CreateAndAppendSharedQuadState();
shared_quad_state->SetAll(gfx::Transform(), root_target_rect,
- root_target_rect, root_target_rect, false, opacity,
- SkBlendMode::kSrcOver, sorting_context_id);
+ root_target_rect, root_target_rect, false,
+ are_contents_opaque, opacity, SkBlendMode::kSrcOver,
+ sorting_context_id);
for (Region::Iterator fill_rects(fill_region); fill_rects.has_rect();
fill_rects.next()) {
@@ -773,18 +798,18 @@ static void AppendQuadsToFillScreen(
gfx::Rect visible_screen_space_rect = screen_space_rect;
// Skip the quad culler and just append the quads directly to avoid
// occlusion checks.
- SolidColorDrawQuad* quad =
- target_render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ auto* quad =
+ target_render_pass->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
quad->SetNew(shared_quad_state, screen_space_rect,
visible_screen_space_rect, screen_background_color, false);
}
}
-static RenderPass* FindRenderPassById(const RenderPassList& list,
- RenderPassId id) {
+static viz::RenderPass* FindRenderPassById(const viz::RenderPassList& list,
+ viz::RenderPassId id) {
auto it = std::find_if(
list.begin(), list.end(),
- [id](const std::unique_ptr<RenderPass>& p) { return p->id == id; });
+ [id](const std::unique_ptr<viz::RenderPass>& p) { return p->id == id; });
return it == list.end() ? nullptr : it->get();
}
@@ -854,7 +879,7 @@ DrawResult LayerTreeHostImpl::CalculateRenderPasses(FrameData* frame) {
// Damage rects for non-root passes aren't meaningful, so set them to be
// equal to the output rect.
for (size_t i = 0; i + 1 < frame->render_passes.size(); ++i) {
- RenderPass* pass = frame->render_passes[i].get();
+ viz::RenderPass* pass = frame->render_passes[i].get();
pass->damage_rect = pass->output_rect;
}
@@ -865,7 +890,7 @@ DrawResult LayerTreeHostImpl::CalculateRenderPasses(FrameData* frame) {
// damage visualizations are done off the LayerImpls and RenderSurfaceImpls,
// changing the RenderPass does not affect them.
if (active_tree_->hud_layer()) {
- RenderPass* root_pass = frame->render_passes.back().get();
+ viz::RenderPass* root_pass = frame->render_passes.back().get();
root_pass->damage_rect = root_pass->output_rect;
}
@@ -899,7 +924,7 @@ DrawResult LayerTreeHostImpl::CalculateRenderPasses(FrameData* frame) {
for (EffectTreeLayerListIterator it(active_tree());
it.state() != EffectTreeLayerListIterator::State::END; ++it) {
auto target_render_pass_id = it.target_render_surface()->id();
- RenderPass* target_render_pass =
+ viz::RenderPass* target_render_pass =
FindRenderPassById(frame->render_passes, target_render_pass_id);
AppendQuadsData append_quads_data;
@@ -996,8 +1021,9 @@ DrawResult LayerTreeHostImpl::CalculateRenderPasses(FrameData* frame) {
}
DCHECK(frame->render_passes.back()->output_rect.origin().IsOrigin());
#endif
-
- if (!active_tree_->has_transparent_background()) {
+ bool has_transparent_background =
+ active_tree_->background_color() == SK_ColorTRANSPARENT;
+ if (!has_transparent_background) {
frame->render_passes.back()->has_transparent_background = false;
AppendQuadsToFillScreen(
active_tree_->RootScrollLayerDeviceViewportBounds(),
@@ -1168,23 +1194,24 @@ void LayerTreeHostImpl::RemoveRenderPasses(FrameData* frame) {
DCHECK_GE(frame->render_passes.size(), 1u);
// A set of RenderPasses that we have seen.
- base::flat_set<RenderPassId> pass_exists;
- // A set of RenderPassDrawQuads that we have seen (stored by the RenderPasses
- // they refer to).
- base::flat_map<RenderPassId, int> pass_references;
+ base::flat_set<viz::RenderPassId> pass_exists;
+ // A set of viz::RenderPassDrawQuads that we have seen (stored by the
+ // RenderPasses they refer to).
+ base::flat_map<viz::RenderPassId, int> pass_references;
// Iterate RenderPasses in draw order, removing empty render passes (except
// the root RenderPass).
for (size_t i = 0; i < frame->render_passes.size(); ++i) {
- RenderPass* pass = frame->render_passes[i].get();
+ viz::RenderPass* pass = frame->render_passes[i].get();
- // Remove orphan RenderPassDrawQuads.
+ // Remove orphan viz::RenderPassDrawQuads.
for (auto it = pass->quad_list.begin(); it != pass->quad_list.end();) {
- if (it->material != DrawQuad::RENDER_PASS) {
+ if (it->material != viz::DrawQuad::RENDER_PASS) {
++it;
continue;
}
- const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(*it);
+ const viz::RenderPassDrawQuad* quad =
+ viz::RenderPassDrawQuad::MaterialCast(*it);
// If the RenderPass doesn't exist, we can remove the quad.
if (pass_exists.count(quad->render_pass_id)) {
// Otherwise, save a reference to the RenderPass so we know there's a
@@ -1219,7 +1246,7 @@ void LayerTreeHostImpl::RemoveRenderPasses(FrameData* frame) {
// Iterating from the back of the list to the front, skipping over the
// back-most (root) pass, in order to remove each qualified RenderPass, and
// drop references to earlier RenderPasses allowing them to be removed to.
- RenderPass* pass =
+ viz::RenderPass* pass =
frame->render_passes[frame->render_passes.size() - 2 - i].get();
if (!pass->copy_requests.empty())
continue;
@@ -1227,9 +1254,10 @@ void LayerTreeHostImpl::RemoveRenderPasses(FrameData* frame) {
continue;
for (auto it = pass->quad_list.begin(); it != pass->quad_list.end(); ++it) {
- if (it->material != DrawQuad::RENDER_PASS)
+ if (it->material != viz::DrawQuad::RENDER_PASS)
continue;
- const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(*it);
+ const viz::RenderPassDrawQuad* quad =
+ viz::RenderPassDrawQuad::MaterialCast(*it);
pass_references[quad->render_pass_id]--;
}
@@ -1371,9 +1399,6 @@ void LayerTreeHostImpl::SetIsLikelyToRequireADraw(
gfx::ColorSpace LayerTreeHostImpl::GetRasterColorSpace() const {
gfx::ColorSpace result;
- if (!settings_.enable_color_correct_rasterization)
- return result;
-
// The pending tree will have the most recently updated color space, so
// prefer that.
if (pending_tree_)
@@ -1401,6 +1426,16 @@ void LayerTreeHostImpl::RequestImplSideInvalidationForCheckerImagedTiles() {
client_->NeedsImplSideInvalidation(needs_first_draw_on_activation);
}
+size_t LayerTreeHostImpl::GetFrameIndexForImage(const PaintImage& paint_image,
+ WhichTree tree) const {
+ DCHECK(image_animation_controller_.has_value());
+ if (!paint_image.ShouldAnimate())
+ return paint_image.frame_index();
+
+ return image_animation_controller_->GetFrameIndexForImage(
+ paint_image.stable_id(), tree);
+}
+
void LayerTreeHostImpl::NotifyReadyToActivate() {
pending_tree_raster_duration_timer_.reset();
client_->NotifyReadyToActivate();
@@ -1626,8 +1661,9 @@ void LayerTreeHostImpl::OnCanDrawStateChangedForTree() {
client_->OnCanDrawStateChanged(CanDraw());
}
-CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const {
- CompositorFrameMetadata metadata;
+viz::CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata()
+ const {
+ viz::CompositorFrameMetadata metadata;
metadata.device_scale_factor = active_tree_->painted_device_scale_factor() *
active_tree_->device_scale_factor();
@@ -1734,14 +1770,14 @@ bool LayerTreeHostImpl::DrawLayers(FrameData* frame) {
// drawn.
if (active_tree_->hud_layer()) {
TRACE_EVENT0("cc", "DrawLayers.UpdateHudTexture");
- // TODO(sohanjg): Temporarily do not pass context provider, so that SW
- // raster path is chosen till we fix the FPS drop issue with gpu raster
- // crbug.com/751732
active_tree_->hud_layer()->UpdateHudTexture(
- draw_mode, resource_provider_.get(), nullptr, frame->render_passes);
+ draw_mode, resource_provider_.get(),
+ use_gpu_rasterization_ ? layer_tree_frame_sink_->context_provider()
+ : nullptr,
+ frame->render_passes);
}
- CompositorFrameMetadata metadata = MakeCompositorFrameMetadata();
+ viz::CompositorFrameMetadata metadata = MakeCompositorFrameMetadata();
metadata.may_contain_video = frame->may_contain_video;
metadata.activation_dependencies = std::move(frame->activation_dependencies);
active_tree()->FinishSwapPromises(&metadata);
@@ -1772,7 +1808,7 @@ bool LayerTreeHostImpl::DrawLayers(FrameData* frame) {
frame->begin_frame_ack.sequence_number);
metadata.begin_frame_ack = frame->begin_frame_ack;
- CompositorFrame compositor_frame;
+ viz::CompositorFrame compositor_frame;
compositor_frame.metadata = std::move(metadata);
resource_provider_->PrepareSendToParent(resources,
&compositor_frame.resource_list);
@@ -1849,21 +1885,50 @@ void LayerTreeHostImpl::SetContentHasNonAAPaint(bool flag) {
}
}
-bool LayerTreeHostImpl::CanUseGpuRasterization() {
+void LayerTreeHostImpl::GetGpuRasterizationCapabilities(
+ bool* gpu_rasterization_enabled,
+ bool* gpu_rasterization_supported,
+ int* max_msaa_samples,
+ bool* supports_disable_msaa) {
+ *gpu_rasterization_enabled = false;
+ *gpu_rasterization_supported = false;
+ *max_msaa_samples = 0;
+ *supports_disable_msaa = false;
+
if (!(layer_tree_frame_sink_ && layer_tree_frame_sink_->context_provider() &&
layer_tree_frame_sink_->worker_context_provider()))
- return false;
+ return;
viz::ContextProvider* context_provider =
layer_tree_frame_sink_->worker_context_provider();
viz::ContextProvider::ScopedContextLock scoped_context(context_provider);
- if (!context_provider->GrContext())
- return false;
- return true;
+ const auto& caps = context_provider->ContextCapabilities();
+ *gpu_rasterization_enabled = caps.gpu_rasterization;
+ if (!*gpu_rasterization_enabled && !settings_.gpu_rasterization_forced)
+ return;
+
+ // Do not check GrContext above. It is lazy-created, and we only want to
+ // create it if it might be used.
+ GrContext* gr_context = context_provider->GrContext();
+ *gpu_rasterization_supported = !!gr_context;
+ if (!*gpu_rasterization_supported)
+ return;
+
+ *supports_disable_msaa = caps.multisample_compatibility;
+ if (!caps.msaa_is_slow && !caps.avoid_stencil_buffers) {
+ // Skia may blacklist MSAA independently of Chrome. Query skia for the
+ // requested sample count. This will return 0 if MSAA is unsupported.
+ *max_msaa_samples = gr_context->caps()->getSampleCount(
+ caps.max_samples, ToGrPixelConfig(settings_.preferred_tile_format));
+ }
}
bool LayerTreeHostImpl::UpdateGpuRasterizationStatus() {
+ if (!need_update_gpu_rasterization_status_)
+ return false;
+ need_update_gpu_rasterization_status_ = false;
+
// TODO(danakj): Can we avoid having this run when there's no
// LayerTreeFrameSink?
// For now just early out and leave things unchanged, we'll come back here
@@ -1873,17 +1938,12 @@ bool LayerTreeHostImpl::UpdateGpuRasterizationStatus() {
int requested_msaa_samples = RequestedMSAASampleCount();
int max_msaa_samples = 0;
- viz::ContextProvider* compositor_context_provider =
- layer_tree_frame_sink_->context_provider();
bool gpu_rasterization_enabled = false;
+ bool gpu_rasterization_supported = false;
bool supports_disable_msaa = false;
- if (compositor_context_provider) {
- const auto& caps = compositor_context_provider->ContextCapabilities();
- gpu_rasterization_enabled = caps.gpu_rasterization;
- supports_disable_msaa = caps.multisample_compatibility;
- if (!caps.msaa_is_slow && !caps.avoid_stencil_buffers)
- max_msaa_samples = caps.max_samples;
- }
+ GetGpuRasterizationCapabilities(&gpu_rasterization_enabled,
+ &gpu_rasterization_supported,
+ &max_msaa_samples, &supports_disable_msaa);
bool use_gpu = false;
bool use_msaa = false;
@@ -1911,7 +1971,7 @@ bool LayerTreeHostImpl::UpdateGpuRasterizationStatus() {
}
if (use_gpu && !use_gpu_rasterization_) {
- if (!CanUseGpuRasterization()) {
+ if (!gpu_rasterization_supported) {
// If GPU rasterization is unusable, e.g. if GlContext could not
// be created due to losing the GL context, force use of software
// raster.
@@ -1932,8 +1992,6 @@ bool LayerTreeHostImpl::UpdateGpuRasterizationStatus() {
}
void LayerTreeHostImpl::UpdateTreeResourcesForGpuRasterizationIfNeeded() {
- if (!need_update_gpu_rasterization_status_)
- return;
if (!UpdateGpuRasterizationStatus())
return;
@@ -2201,8 +2259,17 @@ void LayerTreeHostImpl::ActivateSyncTree() {
UpdateViewportContainerSizes();
+ // Inform the ImageAnimationController and TileManager before dirtying tile
+ // priorities. Since these components cache tree specific state, these should
+ // be updated before DidModifyTilePriorities which can synchronously issue a
+ // PrepareTiles.
+ if (image_animation_controller_)
+ image_animation_controller_->DidActivate();
+ tile_manager_.DidActivateSyncTree();
+
active_tree_->DidBecomeActive();
client_->RenewTreePriority();
+
// If we have any picture layers, then by activating we also modified tile
// priorities.
if (!active_tree_->picture_layers().empty())
@@ -2367,7 +2434,7 @@ void LayerTreeHostImpl::CreateResourceAndRasterBufferProvider(
if (!compositor_context_provider) {
*resource_pool =
ResourcePool::Create(resource_provider_.get(), GetTaskRunner(),
- ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ ResourceProvider::TEXTURE_HINT_DEFAULT,
ResourcePool::kDefaultExpirationDelay,
settings_.disallow_non_exact_resource_reuse);
@@ -2381,11 +2448,11 @@ void LayerTreeHostImpl::CreateResourceAndRasterBufferProvider(
if (use_gpu_rasterization_) {
DCHECK(worker_context_provider);
- *resource_pool = ResourcePool::Create(
- resource_provider_.get(), GetTaskRunner(),
- ResourceProvider::TEXTURE_HINT_IMMUTABLE_FRAMEBUFFER,
- ResourcePool::kDefaultExpirationDelay,
- settings_.disallow_non_exact_resource_reuse);
+ *resource_pool =
+ ResourcePool::Create(resource_provider_.get(), GetTaskRunner(),
+ ResourceProvider::TEXTURE_HINT_FRAMEBUFFER,
+ ResourcePool::kDefaultExpirationDelay,
+ settings_.disallow_non_exact_resource_reuse);
int msaa_sample_count = use_msaa_ ? RequestedMSAASampleCount() : 0;
@@ -2421,7 +2488,7 @@ void LayerTreeHostImpl::CreateResourceAndRasterBufferProvider(
*resource_pool =
ResourcePool::Create(resource_provider_.get(), GetTaskRunner(),
- ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ ResourceProvider::TEXTURE_HINT_DEFAULT,
ResourcePool::kDefaultExpirationDelay,
settings_.disallow_non_exact_resource_reuse);
@@ -2564,14 +2631,13 @@ bool LayerTreeHostImpl::InitializeRenderer(
layer_tree_frame_sink_->context_provider(),
layer_tree_frame_sink_->shared_bitmap_manager(),
layer_tree_frame_sink_->gpu_memory_buffer_manager(),
- task_runner_provider_->blocking_main_thread_task_runner(),
layer_tree_frame_sink_->capabilities().delegated_sync_points_required,
- settings_.enable_color_correct_rasterization,
settings_.resource_settings);
// Since the new context may be capable of MSAA, update status here. We don't
// need to check the return value since we are recreating all resources
// already.
+ SetNeedUpdateGpuRasterizationStatus();
UpdateGpuRasterizationStatus();
// See note in LayerTreeImpl::UpdateDrawProperties, new LayerTreeFrameSink
@@ -3771,15 +3837,6 @@ void LayerTreeHostImpl::PinchGestureEnd() {
SetNeedsRedraw();
}
-std::unique_ptr<BeginFrameCallbackList>
-LayerTreeHostImpl::ProcessLayerTreeMutations() {
- std::unique_ptr<BeginFrameCallbackList> callbacks(new BeginFrameCallbackList);
- const base::Closure& callback = mutator_host_->TakeMutations();
- if (!callback.is_null())
- callbacks->push_back(callback);
- return callbacks;
-}
-
static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info,
LayerTreeImpl* tree_impl) {
if (tree_impl->LayerListIsEmpty())
@@ -3930,6 +3987,17 @@ void LayerTreeHostImpl::ActivateAnimations() {
}
}
+std::string LayerTreeHostImpl::LayerListAsJson() const {
+ auto list = std::make_unique<base::ListValue>();
+ for (auto* layer : *active_tree_) {
+ list->Append(layer->LayerAsJson());
+ }
+ std::string str;
+ base::JSONWriter::WriteWithOptions(
+ *list, base::JSONWriter::OPTIONS_PRETTY_PRINT, &str);
+ return str;
+}
+
std::string LayerTreeHostImpl::LayerTreeAsJson() const {
std::string str;
if (active_tree_->root_layer_for_testing()) {
@@ -4154,7 +4222,7 @@ void LayerTreeHostImpl::CreateUIResource(UIResourceId uid,
}
id = resource_provider_->CreateResource(
- upload_size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format,
+ upload_size, ResourceProvider::TEXTURE_HINT_DEFAULT, format,
gfx::ColorSpace::CreateSRGB());
if (!scaled) {
@@ -4426,9 +4494,8 @@ void LayerTreeHostImpl::ScrollOffsetAnimationFinished() {
gfx::ScrollOffset LayerTreeHostImpl::GetScrollOffsetForAnimation(
ElementId element_id) const {
if (active_tree()) {
- LayerImpl* layer = active_tree()->LayerByElementId(element_id);
- if (layer)
- return layer->ScrollOffsetForAnimation();
+ return active_tree()->property_trees()->scroll_tree.current_scroll_offset(
+ element_id);
}
return gfx::ScrollOffset();
@@ -4496,4 +4563,13 @@ void LayerTreeHostImpl::ShowScrollbarsForImplScroll(ElementId element_id) {
animation_controller->DidScrollUpdate();
}
+void LayerTreeHostImpl::RequestInvalidationForAnimatedImages() {
+ DCHECK(image_animation_controller_);
+
+ // If we are animating an image, we want at least one draw of the active tree
+ // before a new tree is activated.
+ bool needs_first_draw_on_activation = true;
+ client_->NeedsImplSideInvalidation(needs_first_draw_on_activation);
+}
+
} // namespace cc
diff --git a/chromium/cc/trees/layer_tree_host_impl.h b/chromium/cc/trees/layer_tree_host_impl.h
index 232844fdc0c..a73f0d81624 100644
--- a/chromium/cc/trees/layer_tree_host_impl.h
+++ b/chromium/cc/trees/layer_tree_host_impl.h
@@ -25,9 +25,6 @@
#include "cc/input/input_handler.h"
#include "cc/input/scrollbar_animation_controller.h"
#include "cc/layers/layer_collections.h"
-#include "cc/output/layer_tree_frame_sink_client.h"
-#include "cc/output/managed_memory_policy.h"
-#include "cc/quads/render_pass.h"
#include "cc/resources/layer_tree_resource_provider.h"
#include "cc/resources/ui_resource_client.h"
#include "cc/scheduler/begin_frame_tracker.h"
@@ -37,12 +34,15 @@
#include "cc/tiles/decoded_image_tracker.h"
#include "cc/tiles/image_decode_cache.h"
#include "cc/tiles/tile_manager.h"
+#include "cc/trees/layer_tree_frame_sink_client.h"
#include "cc/trees/layer_tree_mutator.h"
#include "cc/trees/layer_tree_settings.h"
+#include "cc/trees/managed_memory_policy.h"
#include "cc/trees/mutator_host_client.h"
#include "cc/trees/task_runner_provider.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"
#include "components/viz/common/gpu/context_cache_controller.h"
+#include "components/viz/common/quads/render_pass.h"
#include "components/viz/common/surfaces/local_surface_id.h"
#include "components/viz/common/surfaces/surface_id.h"
#include "ui/gfx/geometry/rect.h"
@@ -51,14 +51,17 @@ namespace gfx {
class ScrollOffset;
}
-namespace cc {
+namespace viz {
+class CompositorFrameMetadata;
+}
+namespace cc {
class BrowserControlsOffsetManager;
-class CompositorFrameMetadata;
class LayerTreeFrameSink;
class DebugRectHistory;
class EvictionTilePriorityQueue;
class FrameRateCounter;
+class ImageAnimationController;
class LayerImpl;
class LayerTreeImpl;
class MemoryHistory;
@@ -237,7 +240,7 @@ class CC_EXPORT LayerTreeHostImpl
std::vector<viz::SurfaceId> activation_dependencies;
std::vector<gfx::Rect> occluding_screen_space_rects;
std::vector<gfx::Rect> non_occluding_screen_space_rects;
- RenderPassList render_passes;
+ viz::RenderPassList render_passes;
const RenderSurfaceList* render_surface_list;
LayerImplList will_draw_layers;
bool has_no_damage;
@@ -274,6 +277,9 @@ class CC_EXPORT LayerTreeHostImpl
LayerTreeImpl* tree,
const gfx::ScrollOffset& scroll_offset);
void SetNeedUpdateGpuRasterizationStatus();
+ bool NeedUpdateGpuRasterizationStatusForTesting() const {
+ return need_update_gpu_rasterization_status_;
+ }
// MutatorHostClient implementation.
bool IsElementInList(ElementId element_id,
@@ -354,6 +360,8 @@ class CC_EXPORT LayerTreeHostImpl
void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw) override;
gfx::ColorSpace GetRasterColorSpace() const override;
void RequestImplSideInvalidationForCheckerImagedTiles() override;
+ size_t GetFrameIndexForImage(const PaintImage& paint_image,
+ WhichTree tree) const override;
// ScrollbarAnimationControllerClient implementation.
void PostDelayedScrollbarAnimationTask(const base::Closure& task,
@@ -393,6 +401,9 @@ class CC_EXPORT LayerTreeHostImpl
}
void ReleaseLayerTreeFrameSink();
+ std::string LayerListAsJson() const;
+ // TODO(pdr): This should be removed because there is no longer a tree
+ // of layers, only a list.
std::string LayerTreeAsJson() const;
int RequestedMSAASampleCount() const;
@@ -404,7 +415,10 @@ class CC_EXPORT LayerTreeHostImpl
void SetHasGpuRasterizationTrigger(bool flag);
void SetContentHasSlowPaths(bool flag);
void SetContentHasNonAAPaint(bool flag);
- bool CanUseGpuRasterization();
+ void GetGpuRasterizationCapabilities(bool* gpu_rasterization_enabled,
+ bool* gpu_rasterization_supported,
+ int* max_msaa_samples,
+ bool* supports_disable_msaa);
bool use_gpu_rasterization() const { return use_gpu_rasterization_; }
bool use_msaa() const { return use_msaa_; }
@@ -417,6 +431,11 @@ class CC_EXPORT LayerTreeHostImpl
}
ResourcePool* resource_pool() { return resource_pool_.get(); }
ImageDecodeCache* image_decode_cache() { return image_decode_cache_.get(); }
+ ImageAnimationController* image_animation_controller() {
+ if (!image_animation_controller_.has_value())
+ return nullptr;
+ return &image_animation_controller_.value();
+ }
virtual void WillBeginImplFrame(const viz::BeginFrameArgs& args);
virtual void DidFinishImplFrame();
@@ -468,8 +487,6 @@ class CC_EXPORT LayerTreeHostImpl
const gfx::Transform& DrawTransform() const;
- std::unique_ptr<BeginFrameCallbackList> ProcessLayerTreeMutations();
-
std::unique_ptr<ScrollAndScaleSet> ProcessScrollDeltas();
FrameRateCounter* fps_counter() { return fps_counter_.get(); }
MemoryHistory* memory_history() { return memory_history_.get(); }
@@ -540,7 +557,7 @@ class CC_EXPORT LayerTreeHostImpl
void ScheduleMicroBenchmark(std::unique_ptr<MicroBenchmarkImpl> benchmark);
- CompositorFrameMetadata MakeCompositorFrameMetadata() const;
+ viz::CompositorFrameMetadata MakeCompositorFrameMetadata() const;
// Viewport rectangle and clip in device space. These rects are used to
// prioritize raster and determine what is submitted in a CompositorFrame.
@@ -733,6 +750,9 @@ class CC_EXPORT LayerTreeHostImpl
// tree, because the active tree value always takes precedence for scrollbars.
void PushScrollbarOpacitiesFromActiveToPending();
+ // Request an impl-side invalidation to animate an image.
+ void RequestInvalidationForAnimatedImages();
+
using UIResourceMap = std::unordered_map<UIResourceId, UIResourceData>;
UIResourceMap ui_resource_map_;
@@ -896,6 +916,8 @@ class CC_EXPORT LayerTreeHostImpl
ImplThreadPhase impl_thread_phase_;
+ base::Optional<ImageAnimationController> image_animation_controller_;
+
DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl);
};
diff --git a/chromium/cc/trees/layer_tree_host_impl_unittest.cc b/chromium/cc/trees/layer_tree_host_impl_unittest.cc
index a6ac140be87..b472914239b 100644
--- a/chromium/cc/trees/layer_tree_host_impl_unittest.cc
+++ b/chromium/cc/trees/layer_tree_host_impl_unittest.cc
@@ -21,7 +21,6 @@
#include "cc/animation/animation_id_provider.h"
#include "cc/animation/transform_operations.h"
#include "cc/base/histograms.h"
-#include "cc/base/math_util.h"
#include "cc/input/browser_controls_offset_manager.h"
#include "cc/input/main_thread_scrolling_reason.h"
#include "cc/input/page_scale_animation.h"
@@ -36,12 +35,6 @@
#include "cc/layers/texture_layer_impl.h"
#include "cc/layers/video_layer_impl.h"
#include "cc/layers/viewport.h"
-#include "cc/output/compositor_frame_metadata.h"
-#include "cc/output/latency_info_swap_promise.h"
-#include "cc/quads/render_pass_draw_quad.h"
-#include "cc/quads/solid_color_draw_quad.h"
-#include "cc/quads/texture_draw_quad.h"
-#include "cc/quads/tile_draw_quad.h"
#include "cc/resources/ui_resource_bitmap.h"
#include "cc/resources/ui_resource_manager.h"
#include "cc/test/animation_test_common.h"
@@ -60,6 +53,7 @@
#include "cc/test/test_task_graph_runner.h"
#include "cc/test/test_web_graphics_context_3d.h"
#include "cc/trees/effect_node.h"
+#include "cc/trees/latency_info_swap_promise.h"
#include "cc/trees/layer_tree_host_common.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/mutator_host.h"
@@ -67,8 +61,13 @@
#include "cc/trees/single_thread_proxy.h"
#include "cc/trees/transform_node.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"
-#include "components/viz/common/quads/copy_output_request.h"
-#include "components/viz/common/quads/copy_output_result.h"
+#include "components/viz/common/frame_sinks/copy_output_request.h"
+#include "components/viz/common/frame_sinks/copy_output_result.h"
+#include "components/viz/common/quads/compositor_frame_metadata.h"
+#include "components/viz/common/quads/render_pass_draw_quad.h"
+#include "components/viz/common/quads/solid_color_draw_quad.h"
+#include "components/viz/common/quads/texture_draw_quad.h"
+#include "components/viz/common/quads/tile_draw_quad.h"
#include "components/viz/service/display/gl_renderer.h"
#include "components/viz/test/begin_frame_args_test.h"
#include "components/viz/test/test_layer_tree_frame_sink.h"
@@ -76,6 +75,7 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkMallocPixelRef.h"
+#include "ui/gfx/geometry/angle_conversions.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/geometry/vector2d_conversions.h"
@@ -186,7 +186,8 @@ class LayerTreeHostImplTest : public testing::Test,
std::unique_ptr<TestFrameData> frame(new TestFrameData);
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(frame.get()));
last_on_draw_render_passes_.clear();
- RenderPass::CopyAll(frame->render_passes, &last_on_draw_render_passes_);
+ viz::RenderPass::CopyAll(frame->render_passes,
+ &last_on_draw_render_passes_);
host_impl_->DrawLayers(frame.get());
host_impl_->DidDrawAllLayers(*frame);
last_on_draw_frame_ = std::move(frame);
@@ -436,10 +437,10 @@ class LayerTreeHostImplTest : public testing::Test,
squash1->SetBounds(gfx::Size(140, 300));
squash1->SetPosition(gfx::PointF(220, 0));
if (transparent_layer) {
- // In the it is a transparent layer but should still participate
- // in hit testing.
squash1->test_properties()->opacity = 0.0f;
- squash1->SetShouldHitTest(true);
+ // The transparent layer should still participate in hit testing even
+ // through it does not draw content.
+ squash1->SetHitTestableWithoutDrawsContent(true);
} else {
squash1->SetDrawsContent(true);
}
@@ -672,7 +673,7 @@ class LayerTreeHostImplTest : public testing::Test,
base::Closure animation_task_;
base::TimeDelta requested_animation_delay_;
std::unique_ptr<TestFrameData> last_on_draw_frame_;
- RenderPassList last_on_draw_render_passes_;
+ viz::RenderPassList last_on_draw_render_passes_;
scoped_refptr<AnimationTimeline> timeline_;
std::unique_ptr<base::Thread> image_worker_;
};
@@ -1952,7 +1953,7 @@ class MissingTilesLayer : public LayerImpl {
has_missing_tiles_ = has_missing_tiles;
}
- void AppendQuads(RenderPass* render_pass,
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override {
append_quads_data->num_missing_tiles += has_missing_tiles_;
}
@@ -3903,7 +3904,7 @@ TEST_F(LayerTreeHostImplTest, MouseMoveAtWithDeviceScaleOf2) {
}
// This test verifies that only SurfaceLayers in the viewport and have fallbacks
-// that are different are included in CompositorFrameMetadata's
+// that are different are included in viz::CompositorFrameMetadata's
// |activation_dependencies|.
TEST_F(LayerTreeHostImplTest, ActivationDependenciesInMetadata) {
SetupScrollAndContentsLayers(gfx::Size(100, 100));
@@ -3946,7 +3947,7 @@ TEST_F(LayerTreeHostImplTest, ActivationDependenciesInMetadata) {
auto* fake_layer_tree_frame_sink =
static_cast<FakeLayerTreeFrameSink*>(host_impl_->layer_tree_frame_sink());
- const CompositorFrameMetadata& metadata =
+ const viz::CompositorFrameMetadata& metadata =
fake_layer_tree_frame_sink->last_sent_frame()->metadata;
EXPECT_THAT(
metadata.activation_dependencies,
@@ -3963,7 +3964,7 @@ TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 4.f);
DrawFrame();
{
- CompositorFrameMetadata metadata =
+ viz::CompositorFrameMetadata metadata =
host_impl_->MakeCompositorFrameMetadata();
EXPECT_EQ(gfx::Vector2dF(), metadata.root_scroll_offset);
EXPECT_EQ(1.f, metadata.page_scale_factor);
@@ -3983,13 +3984,13 @@ TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
.thread);
host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 10)).get());
{
- CompositorFrameMetadata metadata =
+ viz::CompositorFrameMetadata metadata =
host_impl_->MakeCompositorFrameMetadata();
EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset);
}
host_impl_->ScrollEnd(EndState().get());
{
- CompositorFrameMetadata metadata =
+ viz::CompositorFrameMetadata metadata =
host_impl_->MakeCompositorFrameMetadata();
EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset);
}
@@ -4002,7 +4003,7 @@ TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
->test_properties()
->user_scrollable_horizontal = false;
host_impl_->active_tree()->BuildPropertyTreesForTesting();
- CompositorFrameMetadata metadata =
+ viz::CompositorFrameMetadata metadata =
host_impl_->MakeCompositorFrameMetadata();
EXPECT_TRUE(metadata.root_overflow_x_hidden);
EXPECT_FALSE(metadata.root_overflow_y_hidden);
@@ -4028,7 +4029,7 @@ TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
->test_properties()
->user_scrollable_vertical = true;
host_impl_->active_tree()->BuildPropertyTreesForTesting();
- CompositorFrameMetadata metadata =
+ viz::CompositorFrameMetadata metadata =
host_impl_->MakeCompositorFrameMetadata();
EXPECT_FALSE(metadata.root_overflow_x_hidden);
EXPECT_FALSE(metadata.root_overflow_y_hidden);
@@ -4042,7 +4043,7 @@ TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
->test_properties()
->user_scrollable_horizontal = false;
host_impl_->active_tree()->BuildPropertyTreesForTesting();
- CompositorFrameMetadata metadata =
+ viz::CompositorFrameMetadata metadata =
host_impl_->MakeCompositorFrameMetadata();
EXPECT_TRUE(metadata.root_overflow_x_hidden);
EXPECT_FALSE(metadata.root_overflow_y_hidden);
@@ -4065,7 +4066,7 @@ TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
host_impl_->PinchGestureEnd();
host_impl_->ScrollEnd(EndState().get());
{
- CompositorFrameMetadata metadata =
+ viz::CompositorFrameMetadata metadata =
host_impl_->MakeCompositorFrameMetadata();
EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset);
EXPECT_EQ(2.f, metadata.page_scale_factor);
@@ -4080,7 +4081,7 @@ TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
host_impl_->active_tree()->PushPageScaleFromMainThread(4.f, 0.5f, 4.f);
host_impl_->active_tree()->SetPageScaleOnActiveTree(4.f);
{
- CompositorFrameMetadata metadata =
+ viz::CompositorFrameMetadata metadata =
host_impl_->MakeCompositorFrameMetadata();
EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset);
EXPECT_EQ(4.f, metadata.page_scale_factor);
@@ -4097,20 +4098,21 @@ class DidDrawCheckLayer : public LayerImpl {
return base::WrapUnique(new DidDrawCheckLayer(tree_impl, id));
}
- bool WillDraw(DrawMode draw_mode, ResourceProvider* provider) override {
+ bool WillDraw(DrawMode draw_mode,
+ LayerTreeResourceProvider* provider) override {
will_draw_called_ = true;
if (will_draw_returns_false_)
return false;
return LayerImpl::WillDraw(draw_mode, provider);
}
- void AppendQuads(RenderPass* render_pass,
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override {
append_quads_called_ = true;
LayerImpl::AppendQuads(render_pass, append_quads_data);
}
- void DidDraw(ResourceProvider* provider) override {
+ void DidDraw(LayerTreeResourceProvider* provider) override {
did_draw_called_ = true;
LayerImpl::DidDraw(provider);
}
@@ -4127,11 +4129,9 @@ class DidDrawCheckLayer : public LayerImpl {
did_draw_called_ = false;
}
- static void IgnoreResult(std::unique_ptr<viz::CopyOutputResult> result) {}
-
void AddCopyRequest() {
test_properties()->copy_requests.push_back(
- viz::CopyOutputRequest::CreateRequest(base::BindOnce(&IgnoreResult)));
+ viz::CopyOutputRequest::CreateStubForTesting());
}
protected:
@@ -4342,7 +4342,7 @@ class MissingTextureAnimatingLayer : public DidDrawCheckLayer {
resource_provider, timeline));
}
- void AppendQuads(RenderPass* render_pass,
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override {
LayerImpl::AppendQuads(render_pass, append_quads_data);
if (had_incomplete_tile_)
@@ -6569,8 +6569,8 @@ TEST_F(LayerTreeHostImplTest, ScrollNonAxisAlignedRotatedLayer) {
// The child layer should have scrolled down in its local coordinates an
// amount proportional to the angle between it and the input scroll delta.
gfx::Vector2d expected_scroll_delta(
- 0, gesture_scroll_delta.y() *
- std::cos(MathUtil::Deg2Rad(child_layer_angle)));
+ 0,
+ gesture_scroll_delta.y() * std::cos(gfx::DegToRad(child_layer_angle)));
std::unique_ptr<ScrollAndScaleSet> scroll_info =
host_impl_->ProcessScrollDeltas();
EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), child_scroll_id,
@@ -6595,8 +6595,8 @@ TEST_F(LayerTreeHostImplTest, ScrollNonAxisAlignedRotatedLayer) {
// The child layer should have scrolled down in its local coordinates an
// amount proportional to the angle between it and the input scroll delta.
gfx::Vector2d expected_scroll_delta(
- 0, -gesture_scroll_delta.x() *
- std::sin(MathUtil::Deg2Rad(child_layer_angle)));
+ 0,
+ -gesture_scroll_delta.x() * std::sin(gfx::DegToRad(child_layer_angle)));
std::unique_ptr<ScrollAndScaleSet> scroll_info =
host_impl_->ProcessScrollDeltas();
EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), child_scroll_id,
@@ -7744,7 +7744,7 @@ class BlendStateCheckLayer : public LayerImpl {
new BlendStateCheckLayer(tree_impl, id, resource_provider));
}
- void AppendQuads(RenderPass* render_pass,
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override {
quads_appended_ = true;
@@ -7758,14 +7758,14 @@ class BlendStateCheckLayer : public LayerImpl {
viz::SharedQuadState* shared_quad_state =
render_pass->CreateAndAppendSharedQuadState();
- PopulateSharedQuadState(shared_quad_state);
+ PopulateSharedQuadState(shared_quad_state, contents_opaque());
- TileDrawQuad* test_blending_draw_quad =
- render_pass->CreateAndAppendDrawQuad<TileDrawQuad>();
+ auto* test_blending_draw_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::TileDrawQuad>();
test_blending_draw_quad->SetNew(
shared_quad_state, quad_rect_, visible_quad_rect, needs_blending,
resource_id_, gfx::RectF(0.f, 0.f, 1.f, 1.f), gfx::Size(1, 1), false,
- false);
+ false, false);
EXPECT_EQ(blend_, test_blending_draw_quad->ShouldDrawWithBlending());
EXPECT_EQ(has_render_surface_,
@@ -7802,7 +7802,7 @@ class BlendStateCheckLayer : public LayerImpl {
quad_visible_rect_(5, 5, 5, 5),
resource_id_(resource_provider->CreateResource(
gfx::Size(1, 1),
- ResourceProvider::TEXTURE_HINT_IMMUTABLE,
+ ResourceProvider::TEXTURE_HINT_DEFAULT,
viz::RGBA_8888,
gfx::ColorSpace())) {
resource_provider->AllocateForTesting(resource_id_);
@@ -8126,7 +8126,7 @@ TEST_F(LayerTreeHostImplTest, MayContainVideo) {
class LayerTreeHostImplViewportCoveredTest : public LayerTreeHostImplTest {
protected:
LayerTreeHostImplViewportCoveredTest()
- : gutter_quad_material_(DrawQuad::SOLID_COLOR),
+ : gutter_quad_material_(viz::DrawQuad::SOLID_COLOR),
child_(NULL),
did_activate_pending_tree_(false) {}
@@ -8190,7 +8190,7 @@ class LayerTreeHostImplViewportCoveredTest : public LayerTreeHostImplTest {
host_impl_->active_tree()->BuildPropertyTreesForTesting();
}
- void VerifyEmptyLayerRenderPasses(const RenderPassList& render_passes) {
+ void VerifyEmptyLayerRenderPasses(const viz::RenderPassList& render_passes) {
ASSERT_EQ(1u, render_passes.size());
EXPECT_EQ(1u, CountGutterQuads(render_passes[0]->quad_list));
@@ -8227,7 +8227,7 @@ class LayerTreeHostImplViewportCoveredTest : public LayerTreeHostImplTest {
host_impl_->active_tree()->BuildPropertyTreesForTesting();
}
- void VerifyLayerInMiddleOfViewport(const RenderPassList& render_passes) {
+ void VerifyLayerInMiddleOfViewport(const viz::RenderPassList& render_passes) {
ASSERT_EQ(1u, render_passes.size());
EXPECT_EQ(4u, CountGutterQuads(render_passes[0]->quad_list));
@@ -8265,7 +8265,8 @@ class LayerTreeHostImplViewportCoveredTest : public LayerTreeHostImplTest {
host_impl_->active_tree()->BuildPropertyTreesForTesting();
}
- void VerifyLayerIsLargerThanViewport(const RenderPassList& render_passes) {
+ void VerifyLayerIsLargerThanViewport(
+ const viz::RenderPassList& render_passes) {
ASSERT_EQ(1u, render_passes.size());
EXPECT_EQ(0u, CountGutterQuads(render_passes[0]->quad_list));
@@ -8292,7 +8293,7 @@ class LayerTreeHostImplViewportCoveredTest : public LayerTreeHostImplTest {
void DidActivateSyncTree() override { did_activate_pending_tree_ = true; }
- void set_gutter_quad_material(DrawQuad::Material material) {
+ void set_gutter_quad_material(viz::DrawQuad::Material material) {
gutter_quad_material_ = material;
}
void set_gutter_texture_size(const gfx::Size& gutter_texture_size) {
@@ -8300,7 +8301,7 @@ class LayerTreeHostImplViewportCoveredTest : public LayerTreeHostImplTest {
}
protected:
- size_t CountGutterQuads(const QuadList& quad_list) {
+ size_t CountGutterQuads(const viz::QuadList& quad_list) {
size_t num_gutter_quads = 0;
for (auto* quad : quad_list) {
num_gutter_quads += (quad->material == gutter_quad_material_) ? 1 : 0;
@@ -8308,17 +8309,18 @@ class LayerTreeHostImplViewportCoveredTest : public LayerTreeHostImplTest {
return num_gutter_quads;
}
- void VerifyQuadsExactlyCoverViewport(const QuadList& quad_list) {
+ void VerifyQuadsExactlyCoverViewport(const viz::QuadList& quad_list) {
LayerTestCommon::VerifyQuadsExactlyCoverRect(
quad_list, gfx::Rect(DipSizeToPixelSize(viewport_size_)));
}
// Make sure that the texture coordinates match their expectations.
- void ValidateTextureDrawQuads(const QuadList& quad_list) {
+ void ValidateTextureDrawQuads(const viz::QuadList& quad_list) {
for (auto* quad : quad_list) {
- if (quad->material != DrawQuad::TEXTURE_CONTENT)
+ if (quad->material != viz::DrawQuad::TEXTURE_CONTENT)
continue;
- const TextureDrawQuad* texture_quad = TextureDrawQuad::MaterialCast(quad);
+ const viz::TextureDrawQuad* texture_quad =
+ viz::TextureDrawQuad::MaterialCast(quad);
gfx::SizeF gutter_texture_size_pixels =
gfx::ScaleSize(gfx::SizeF(gutter_texture_size_),
host_impl_->active_tree()->device_scale_factor());
@@ -8340,7 +8342,7 @@ class LayerTreeHostImplViewportCoveredTest : public LayerTreeHostImplTest {
size, host_impl_->active_tree()->device_scale_factor());
}
- DrawQuad::Material gutter_quad_material_;
+ viz::DrawQuad::Material gutter_quad_material_;
gfx::Size gutter_texture_size_;
gfx::Size viewport_size_;
BlendStateCheckLayer* child_;
@@ -8431,7 +8433,7 @@ class FakeDrawableLayerImpl : public LayerImpl {
: LayerImpl(tree_impl, id) {}
};
-// Make sure damage tracking propagates all the way to the CompositorFrame
+// Make sure damage tracking propagates all the way to the viz::CompositorFrame
// submitted to the LayerTreeFrameSink, where it should request to swap only
// the sub-buffer that is damaged.
TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) {
@@ -8549,17 +8551,17 @@ class FakeLayerWithQuads : public LayerImpl {
return base::WrapUnique(new FakeLayerWithQuads(tree_impl, id));
}
- void AppendQuads(RenderPass* render_pass,
+ void AppendQuads(viz::RenderPass* render_pass,
AppendQuadsData* append_quads_data) override {
viz::SharedQuadState* shared_quad_state =
render_pass->CreateAndAppendSharedQuadState();
- PopulateSharedQuadState(shared_quad_state);
+ PopulateSharedQuadState(shared_quad_state, contents_opaque());
SkColor gray = SkColorSetRGB(100, 100, 100);
gfx::Rect quad_rect(bounds());
gfx::Rect visible_quad_rect(quad_rect);
- SolidColorDrawQuad* my_quad =
- render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
+ auto* my_quad =
+ render_pass->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
my_quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, gray,
false);
}
@@ -8624,13 +8626,13 @@ TEST_F(LayerTreeHostImplTest, HasTransparentBackground) {
host_impl_->active_tree()->set_background_color(SK_ColorWHITE);
// Verify one quad is drawn when transparent background set is not set.
- host_impl_->active_tree()->set_has_transparent_background(false);
TestFrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
{
const auto& root_pass = frame.render_passes.back();
ASSERT_EQ(1u, root_pass->quad_list.size());
- EXPECT_EQ(DrawQuad::SOLID_COLOR, root_pass->quad_list.front()->material);
+ EXPECT_EQ(viz::DrawQuad::SOLID_COLOR,
+ root_pass->quad_list.front()->material);
}
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
@@ -8639,7 +8641,7 @@ TEST_F(LayerTreeHostImplTest, HasTransparentBackground) {
host_impl_->SetFullViewportDamage();
// Verify no quads are drawn when transparent background is set.
- host_impl_->active_tree()->set_has_transparent_background(true);
+ host_impl_->active_tree()->set_background_color(SK_ColorTRANSPARENT);
host_impl_->SetFullViewportDamage();
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
{
@@ -8669,7 +8671,8 @@ class LayerTreeHostImplTestDrawAndTestDamage : public LayerTreeHostImplTest {
ASSERT_EQ(1u, frame.render_passes.size());
// Verify the damage rect for the root render pass.
- const RenderPass* root_render_pass = frame.render_passes.back().get();
+ const viz::RenderPass* root_render_pass =
+ frame.render_passes.back().get();
EXPECT_EQ(expected_damage, root_render_pass->damage_rect);
// Verify the root and child layers' quads are generated and not being
@@ -8797,7 +8800,7 @@ TEST_F(LayerTreeHostImplTest, FarAwayQuadsDontNeedAA) {
ASSERT_EQ(1u, frame.render_passes.size());
ASSERT_LE(1u, frame.render_passes[0]->quad_list.size());
- const DrawQuad* quad = frame.render_passes[0]->quad_list.front();
+ const viz::DrawQuad* quad = frame.render_passes[0]->quad_list.front();
bool clipped = false, force_aa = false;
gfx::QuadF device_layer_quad = MathUtil::MapQuad(
@@ -8837,16 +8840,16 @@ TEST_F(CompositorFrameMetadataTest, CompositorFrameAckCountsAsSwapComplete) {
EXPECT_EQ(acks_received_, 1);
}
-class CountingSoftwareDevice : public SoftwareOutputDevice {
+class CountingSoftwareDevice : public viz::SoftwareOutputDevice {
public:
CountingSoftwareDevice() : frames_began_(0), frames_ended_(0) {}
SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override {
++frames_began_;
- return SoftwareOutputDevice::BeginPaint(damage_rect);
+ return viz::SoftwareOutputDevice::BeginPaint(damage_rect);
}
void EndPaint() override {
- SoftwareOutputDevice::EndPaint();
+ viz::SoftwareOutputDevice::EndPaint();
++frames_ended_;
}
@@ -8987,7 +8990,7 @@ void ExpectFullDamageAndDraw(LayerTreeHostImpl* host_impl) {
TestFrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl->PrepareToDraw(&frame));
ASSERT_EQ(1u, frame.render_passes.size());
- const RenderPass* root_render_pass = frame.render_passes.back().get();
+ const viz::RenderPass* root_render_pass = frame.render_passes.back().get();
EXPECT_EQ(full_frame_damage, root_render_pass->damage_rect);
EXPECT_TRUE(host_impl->DrawLayers(&frame));
host_impl->DidDrawAllLayers(frame);
@@ -9154,16 +9157,13 @@ TEST_F(LayerTreeHostImplTest, CreateETC1UIResource) {
EXPECT_NE(0u, id1);
}
-void ShutdownReleasesContext_Callback(
- std::unique_ptr<viz::CopyOutputResult> result) {}
-
class FrameSinkClient : public viz::TestLayerTreeFrameSinkClient {
public:
explicit FrameSinkClient(
scoped_refptr<viz::ContextProvider> display_context_provider)
: display_context_provider_(std::move(display_context_provider)) {}
- std::unique_ptr<OutputSurface> CreateDisplayOutputSurface(
+ std::unique_ptr<viz::OutputSurface> CreateDisplayOutputSurface(
scoped_refptr<viz::ContextProvider> compositor_context_provider)
override {
return FakeOutputSurface::Create3d(std::move(display_context_provider_));
@@ -9171,9 +9171,11 @@ class FrameSinkClient : public viz::TestLayerTreeFrameSinkClient {
void DisplayReceivedLocalSurfaceId(
const viz::LocalSurfaceId& local_surface_id) override {}
- void DisplayReceivedCompositorFrame(const CompositorFrame& frame) override {}
- void DisplayWillDrawAndSwap(bool will_draw_and_swap,
- const RenderPassList& render_passes) override {}
+ void DisplayReceivedCompositorFrame(
+ const viz::CompositorFrame& frame) override {}
+ void DisplayWillDrawAndSwap(
+ bool will_draw_and_swap,
+ const viz::RenderPassList& render_passes) override {}
void DisplayDidDrawAndSwap() override {}
private:
@@ -9199,9 +9201,16 @@ TEST_F(LayerTreeHostImplTest, ShutdownReleasesContext) {
SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1));
LayerImpl* root = host_impl_->active_tree()->root_layer_for_testing();
+ struct Helper {
+ std::unique_ptr<viz::CopyOutputResult> unprocessed_result;
+ void OnResult(std::unique_ptr<viz::CopyOutputResult> result) {
+ unprocessed_result = std::move(result);
+ }
+ } helper;
root->test_properties()->copy_requests.push_back(
- viz::CopyOutputRequest::CreateRequest(
- base::BindOnce(&ShutdownReleasesContext_Callback)));
+ std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_TEXTURE,
+ base::BindOnce(&Helper::OnResult, base::Unretained(&helper))));
host_impl_->active_tree()->BuildPropertyTreesForTesting();
TestFrameData frame;
@@ -9209,18 +9218,23 @@ TEST_F(LayerTreeHostImplTest, ShutdownReleasesContext) {
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
- // The CopyOutputResult's callback has a ref on the viz::ContextProvider and a
- // texture in a texture mailbox.
+ // The CopyOutputResult has a ref on the viz::ContextProvider and a texture in
+ // a texture mailbox.
+ ASSERT_TRUE(helper.unprocessed_result);
EXPECT_FALSE(context_provider->HasOneRef());
EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures());
host_impl_->ReleaseLayerTreeFrameSink();
host_impl_ = nullptr;
- // The CopyOutputResult's callback was cancelled, the CopyOutputResult
- // released, and the texture deleted.
+ // The texture release callback that was given to the CopyOutputResult has
+ // been canceled, and the texture deleted.
EXPECT_TRUE(context_provider->HasOneRef());
EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures());
+
+ // When resetting the CopyOutputResult, it will run its texture release
+ // callback. This should not cause a crash, etc.
+ helper.unprocessed_result.reset();
}
TEST_F(LayerTreeHostImplTest, TouchFlingShouldNotBubble) {
@@ -9533,7 +9547,7 @@ TEST_F(LayerTreeHostImplTest, ScrollInvisibleScroller) {
}
// Make sure LatencyInfo carried by LatencyInfoSwapPromise are passed
-// in CompositorFrameMetadata.
+// in viz::CompositorFrameMetadata.
TEST_F(LayerTreeHostImplTest, LatencyInfoPassedToCompositorFrameMetadata) {
std::unique_ptr<SolidColorLayerImpl> root =
SolidColorLayerImpl::Create(host_impl_->active_tree(), 1);
@@ -9606,7 +9620,7 @@ TEST_F(LayerTreeHostImplTest, SelectionBoundsPassedToCompositorFrameMetadata) {
host_impl_->DidDrawAllLayers(frame);
// Ensure the selection bounds have propagated to the frame metadata.
- const Selection<gfx::SelectionBound>& selection_after =
+ const viz::Selection<gfx::SelectionBound>& selection_after =
fake_layer_tree_frame_sink->last_sent_frame()->metadata.selection;
EXPECT_EQ(selection.start.type, selection_after.start.type());
EXPECT_EQ(selection.end.type, selection_after.end.type());
@@ -9657,7 +9671,7 @@ TEST_F(LayerTreeHostImplTest, HiddenSelectionBoundsStayHidden) {
host_impl_->DidDrawAllLayers(frame);
// Ensure the selection bounds have propagated to the frame metadata.
- const Selection<gfx::SelectionBound>& selection_after =
+ const viz::Selection<gfx::SelectionBound>& selection_after =
fake_layer_tree_frame_sink->last_sent_frame()->metadata.selection;
EXPECT_EQ(selection.start.type, selection_after.start.type());
EXPECT_EQ(selection.end.type, selection_after.end.type());
@@ -11999,38 +12013,37 @@ TEST_F(LayerTreeHostImplCountingLostSurfaces, TwiceLostSurface) {
EXPECT_LE(1, num_lost_surfaces_);
}
-size_t CountRenderPassesWithId(const RenderPassList& list, RenderPassId id) {
+size_t CountRenderPassesWithId(const viz::RenderPassList& list,
+ viz::RenderPassId id) {
return std::count_if(
list.begin(), list.end(),
- [id](const std::unique_ptr<RenderPass>& p) { return p->id == id; });
+ [id](const std::unique_ptr<viz::RenderPass>& p) { return p->id == id; });
}
TEST_F(LayerTreeHostImplTest, RemoveUnreferencedRenderPass) {
TestFrameData frame;
- frame.render_passes.push_back(RenderPass::Create());
- RenderPass* pass3 = frame.render_passes.back().get();
- frame.render_passes.push_back(RenderPass::Create());
- RenderPass* pass2 = frame.render_passes.back().get();
- frame.render_passes.push_back(RenderPass::Create());
- RenderPass* pass1 = frame.render_passes.back().get();
+ frame.render_passes.push_back(viz::RenderPass::Create());
+ viz::RenderPass* pass3 = frame.render_passes.back().get();
+ frame.render_passes.push_back(viz::RenderPass::Create());
+ viz::RenderPass* pass2 = frame.render_passes.back().get();
+ frame.render_passes.push_back(viz::RenderPass::Create());
+ viz::RenderPass* pass1 = frame.render_passes.back().get();
pass1->SetNew(1, gfx::Rect(), gfx::Rect(), gfx::Transform());
pass2->SetNew(2, gfx::Rect(), gfx::Rect(), gfx::Transform());
pass3->SetNew(3, gfx::Rect(), gfx::Rect(), gfx::Transform());
// Add a quad to each pass so they aren't empty.
- SolidColorDrawQuad* color_quad;
- color_quad = pass1->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->material = DrawQuad::SOLID_COLOR;
- color_quad = pass2->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->material = DrawQuad::SOLID_COLOR;
- color_quad = pass3->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->material = DrawQuad::SOLID_COLOR;
+ auto* color_quad = pass1->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
+ color_quad->material = viz::DrawQuad::SOLID_COLOR;
+ color_quad = pass2->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
+ color_quad->material = viz::DrawQuad::SOLID_COLOR;
+ color_quad = pass3->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
+ color_quad->material = viz::DrawQuad::SOLID_COLOR;
// pass3 is referenced by pass2.
- RenderPassDrawQuad* rpdq =
- pass2->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- rpdq->material = DrawQuad::RENDER_PASS;
+ auto* rpdq = pass2->CreateAndAppendDrawQuad<viz::RenderPassDrawQuad>();
+ rpdq->material = viz::DrawQuad::RENDER_PASS;
rpdq->render_pass_id = pass3->id;
// But pass2 is not referenced by pass1. So pass2 and pass3 should be culled.
@@ -12044,31 +12057,29 @@ TEST_F(LayerTreeHostImplTest, RemoveUnreferencedRenderPass) {
TEST_F(LayerTreeHostImplTest, RemoveEmptyRenderPass) {
TestFrameData frame;
- frame.render_passes.push_back(RenderPass::Create());
- RenderPass* pass3 = frame.render_passes.back().get();
- frame.render_passes.push_back(RenderPass::Create());
- RenderPass* pass2 = frame.render_passes.back().get();
- frame.render_passes.push_back(RenderPass::Create());
- RenderPass* pass1 = frame.render_passes.back().get();
+ frame.render_passes.push_back(viz::RenderPass::Create());
+ viz::RenderPass* pass3 = frame.render_passes.back().get();
+ frame.render_passes.push_back(viz::RenderPass::Create());
+ viz::RenderPass* pass2 = frame.render_passes.back().get();
+ frame.render_passes.push_back(viz::RenderPass::Create());
+ viz::RenderPass* pass1 = frame.render_passes.back().get();
pass1->SetNew(1, gfx::Rect(), gfx::Rect(), gfx::Transform());
pass2->SetNew(2, gfx::Rect(), gfx::Rect(), gfx::Transform());
pass3->SetNew(3, gfx::Rect(), gfx::Rect(), gfx::Transform());
// pass1 is not empty, but pass2 and pass3 are.
- SolidColorDrawQuad* color_quad;
- color_quad = pass1->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
- color_quad->material = DrawQuad::SOLID_COLOR;
+ auto* color_quad = pass1->CreateAndAppendDrawQuad<viz::SolidColorDrawQuad>();
+ color_quad->material = viz::DrawQuad::SOLID_COLOR;
// pass3 is referenced by pass2.
- RenderPassDrawQuad* rpdq =
- pass2->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- rpdq->material = DrawQuad::RENDER_PASS;
+ auto* rpdq = pass2->CreateAndAppendDrawQuad<viz::RenderPassDrawQuad>();
+ rpdq->material = viz::DrawQuad::RENDER_PASS;
rpdq->render_pass_id = pass3->id;
// pass2 is referenced by pass1.
- rpdq = pass1->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- rpdq->material = DrawQuad::RENDER_PASS;
+ rpdq = pass1->CreateAndAppendDrawQuad<viz::RenderPassDrawQuad>();
+ rpdq->material = viz::DrawQuad::RENDER_PASS;
rpdq->render_pass_id = pass2->id;
// Since pass3 is empty it should be removed. Then pass2 is empty too, and
@@ -12079,33 +12090,33 @@ TEST_F(LayerTreeHostImplTest, RemoveEmptyRenderPass) {
EXPECT_EQ(0u, CountRenderPassesWithId(frame.render_passes, 2u));
EXPECT_EQ(0u, CountRenderPassesWithId(frame.render_passes, 3u));
EXPECT_EQ(1u, frame.render_passes[0]->id);
- // The RenderPassDrawQuad should be removed from pass1.
+ // The viz::RenderPassDrawQuad should be removed from pass1.
EXPECT_EQ(1u, pass1->quad_list.size());
- EXPECT_EQ(DrawQuad::SOLID_COLOR, pass1->quad_list.ElementAt(0)->material);
+ EXPECT_EQ(viz::DrawQuad::SOLID_COLOR,
+ pass1->quad_list.ElementAt(0)->material);
}
TEST_F(LayerTreeHostImplTest, DoNotRemoveEmptyRootRenderPass) {
TestFrameData frame;
- frame.render_passes.push_back(RenderPass::Create());
- RenderPass* pass3 = frame.render_passes.back().get();
- frame.render_passes.push_back(RenderPass::Create());
- RenderPass* pass2 = frame.render_passes.back().get();
- frame.render_passes.push_back(RenderPass::Create());
- RenderPass* pass1 = frame.render_passes.back().get();
+ frame.render_passes.push_back(viz::RenderPass::Create());
+ viz::RenderPass* pass3 = frame.render_passes.back().get();
+ frame.render_passes.push_back(viz::RenderPass::Create());
+ viz::RenderPass* pass2 = frame.render_passes.back().get();
+ frame.render_passes.push_back(viz::RenderPass::Create());
+ viz::RenderPass* pass1 = frame.render_passes.back().get();
pass1->SetNew(1, gfx::Rect(), gfx::Rect(), gfx::Transform());
pass2->SetNew(2, gfx::Rect(), gfx::Rect(), gfx::Transform());
pass3->SetNew(3, gfx::Rect(), gfx::Rect(), gfx::Transform());
// pass3 is referenced by pass2.
- RenderPassDrawQuad* rpdq =
- pass2->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- rpdq->material = DrawQuad::RENDER_PASS;
+ auto* rpdq = pass2->CreateAndAppendDrawQuad<viz::RenderPassDrawQuad>();
+ rpdq->material = viz::DrawQuad::RENDER_PASS;
rpdq->render_pass_id = pass3->id;
// pass2 is referenced by pass1.
- rpdq = pass1->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
- rpdq->material = DrawQuad::RENDER_PASS;
+ rpdq = pass1->CreateAndAppendDrawQuad<viz::RenderPassDrawQuad>();
+ rpdq->material = viz::DrawQuad::RENDER_PASS;
rpdq->render_pass_id = pass2->id;
// Since pass3 is empty it should be removed. Then pass2 is empty too, and
@@ -12117,7 +12128,7 @@ TEST_F(LayerTreeHostImplTest, DoNotRemoveEmptyRootRenderPass) {
EXPECT_EQ(0u, CountRenderPassesWithId(frame.render_passes, 2u));
EXPECT_EQ(0u, CountRenderPassesWithId(frame.render_passes, 3u));
EXPECT_EQ(1u, frame.render_passes[0]->id);
- // The RenderPassDrawQuad should be removed from pass1.
+ // The viz::RenderPassDrawQuad should be removed from pass1.
EXPECT_EQ(0u, pass1->quad_list.size());
}
@@ -12223,14 +12234,11 @@ TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusTrigger) {
// Tests that SetContentHasSlowPaths behaves as expected.
TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusSlowPaths) {
- std::unique_ptr<TestWebGraphicsContext3D> context_with_msaa =
- TestWebGraphicsContext3D::Create();
- context_with_msaa->SetMaxSamples(4);
- context_with_msaa->set_gpu_rasterization(true);
LayerTreeSettings msaaSettings = DefaultSettings();
msaaSettings.gpu_rasterization_msaa_sample_count = 4;
- EXPECT_TRUE(CreateHostImpl(msaaSettings, FakeLayerTreeFrameSink::Create3d(
- std::move(context_with_msaa))));
+ EXPECT_TRUE(CreateHostImpl(
+ msaaSettings, FakeLayerTreeFrameSink::Create3dForGpuRasterization(
+ msaaSettings.gpu_rasterization_msaa_sample_count)));
// Set initial state, with slow paths on.
host_impl_->SetHasGpuRasterizationTrigger(true);
@@ -12261,15 +12269,11 @@ TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusSlowPaths) {
// Tests that SetDeviceScaleFactor correctly impacts GPU rasterization.
TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusDeviceScaleFactor) {
- // Create a host impl with MSAA support.
- std::unique_ptr<TestWebGraphicsContext3D> context_with_msaa =
- TestWebGraphicsContext3D::Create();
- context_with_msaa->SetMaxSamples(4);
- context_with_msaa->set_gpu_rasterization(true);
+ // Create a host impl with MSAA support (4 samples).
LayerTreeSettings msaaSettings = DefaultSettings();
msaaSettings.gpu_rasterization_msaa_sample_count = -1;
- EXPECT_TRUE(CreateHostImpl(msaaSettings, FakeLayerTreeFrameSink::Create3d(
- std::move(context_with_msaa))));
+ EXPECT_TRUE(CreateHostImpl(
+ msaaSettings, FakeLayerTreeFrameSink::Create3dForGpuRasterization(4)));
// Set initial state, before varying scale factor.
host_impl_->SetHasGpuRasterizationTrigger(true);
@@ -12301,14 +12305,11 @@ TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusDeviceScaleFactor) {
// Tests that explicit MSAA sample count correctly impacts GPU rasterization.
TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusExplicitMSAACount) {
// Create a host impl with MSAA support and a forced sample count of 4.
- std::unique_ptr<TestWebGraphicsContext3D> context_with_msaa =
- TestWebGraphicsContext3D::Create();
- context_with_msaa->SetMaxSamples(4);
- context_with_msaa->set_gpu_rasterization(true);
LayerTreeSettings msaaSettings = DefaultSettings();
msaaSettings.gpu_rasterization_msaa_sample_count = 4;
- EXPECT_TRUE(CreateHostImpl(msaaSettings, FakeLayerTreeFrameSink::Create3d(
- std::move(context_with_msaa))));
+ EXPECT_TRUE(CreateHostImpl(
+ msaaSettings, FakeLayerTreeFrameSink::Create3dForGpuRasterization(
+ msaaSettings.gpu_rasterization_msaa_sample_count)));
host_impl_->SetHasGpuRasterizationTrigger(true);
host_impl_->SetContentHasSlowPaths(true);
@@ -12357,16 +12358,17 @@ class MsaaIsSlowLayerTreeHostImplTest : public LayerTreeHostImplTest {
void CreateHostImplWithCaps(bool msaa_is_slow, bool avoid_stencil_buffers) {
LayerTreeSettings settings = DefaultSettings();
settings.gpu_rasterization_msaa_sample_count = 4;
- auto context_provider = TestContextProvider::Create();
- context_provider->UnboundTestContext3d()->SetMaxSamples(4);
- context_provider->UnboundTestContext3d()->set_msaa_is_slow(msaa_is_slow);
- context_provider->UnboundTestContext3d()->set_gpu_rasterization(true);
- context_provider->UnboundTestContext3d()->set_avoid_stencil_buffers(
- avoid_stencil_buffers);
- auto msaa_is_normal_layer_tree_frame_sink =
- FakeLayerTreeFrameSink::Create3d(context_provider);
- EXPECT_TRUE(CreateHostImpl(
- settings, std::move(msaa_is_normal_layer_tree_frame_sink)));
+ auto frame_sink =
+ FakeLayerTreeFrameSink::Builder()
+ .AllContexts(&TestWebGraphicsContext3D::SetMaxSamples,
+ settings.gpu_rasterization_msaa_sample_count)
+ .AllContexts(&TestWebGraphicsContext3D::set_msaa_is_slow,
+ msaa_is_slow)
+ .AllContexts(&TestWebGraphicsContext3D::set_gpu_rasterization, true)
+ .AllContexts(&TestWebGraphicsContext3D::set_avoid_stencil_buffers,
+ avoid_stencil_buffers)
+ .Build();
+ EXPECT_TRUE(CreateHostImpl(settings, std::move(frame_sink)));
}
};
@@ -12417,16 +12419,16 @@ class MsaaCompatibilityLayerTreeHostImplTest : public LayerTreeHostImplTest {
bool support_multisample_compatibility) {
LayerTreeSettings settings = DefaultSettings();
settings.gpu_rasterization_msaa_sample_count = 4;
- auto context_provider = TestContextProvider::Create();
- context_provider->UnboundTestContext3d()->SetMaxSamples(4);
- context_provider->UnboundTestContext3d()
- ->set_support_multisample_compatibility(
- support_multisample_compatibility);
- context_provider->UnboundTestContext3d()->set_gpu_rasterization(true);
- auto msaa_is_normal_layer_tree_frame_sink =
- FakeLayerTreeFrameSink::Create3d(context_provider);
- EXPECT_TRUE(CreateHostImpl(
- settings, std::move(msaa_is_normal_layer_tree_frame_sink)));
+ auto frame_sink =
+ FakeLayerTreeFrameSink::Builder()
+ .AllContexts(&TestWebGraphicsContext3D::SetMaxSamples,
+ settings.gpu_rasterization_msaa_sample_count)
+ .AllContexts(&TestWebGraphicsContext3D::
+ set_support_multisample_compatibility,
+ support_multisample_compatibility)
+ .AllContexts(&TestWebGraphicsContext3D::set_gpu_rasterization, true)
+ .Build();
+ EXPECT_TRUE(CreateHostImpl(settings, std::move(frame_sink)));
}
};
@@ -12976,15 +12978,8 @@ TEST_F(LayerTreeHostImplTest, CheckerImagingTileInvalidation) {
EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation()));
}
-TEST_F(LayerTreeHostImplTest, RasterColorSpaceNoColorCorrection) {
- LayerTreeSettings settings = DefaultSettings();
- CreateHostImpl(settings, CreateLayerTreeFrameSink());
- EXPECT_FALSE(host_impl_->GetRasterColorSpace().IsValid());
-}
-
TEST_F(LayerTreeHostImplTest, RasterColorSpace) {
LayerTreeSettings settings = DefaultSettings();
- settings.enable_color_correct_rasterization = true;
CreateHostImpl(settings, CreateLayerTreeFrameSink());
// The default raster color space should be sRGB.
EXPECT_EQ(host_impl_->GetRasterColorSpace(), gfx::ColorSpace::CreateSRGB());
@@ -12997,7 +12992,6 @@ TEST_F(LayerTreeHostImplTest, RasterColorSpace) {
TEST_F(LayerTreeHostImplTest, RasterColorSpaceSoftware) {
LayerTreeSettings settings = DefaultSettings();
- settings.enable_color_correct_rasterization = true;
CreateHostImpl(settings, FakeLayerTreeFrameSink::CreateSoftware());
// Software composited resources should always use sRGB as their color space.
EXPECT_EQ(host_impl_->GetRasterColorSpace(), gfx::ColorSpace::CreateSRGB());
@@ -13177,5 +13171,24 @@ TEST_F(LayerTreeHostImplTest, DrawAfterDroppingTileResources) {
EXPECT_GT(layer->tilings()->num_tilings(), 0u);
}
+TEST_F(LayerTreeHostImplTest, NeedUpdateGpuRasterization) {
+ EXPECT_FALSE(host_impl_->NeedUpdateGpuRasterizationStatusForTesting());
+
+ host_impl_->SetHasGpuRasterizationTrigger(true);
+ EXPECT_TRUE(host_impl_->NeedUpdateGpuRasterizationStatusForTesting());
+ host_impl_->CommitComplete();
+ EXPECT_FALSE(host_impl_->NeedUpdateGpuRasterizationStatusForTesting());
+
+ host_impl_->SetContentHasSlowPaths(true);
+ EXPECT_TRUE(host_impl_->NeedUpdateGpuRasterizationStatusForTesting());
+ host_impl_->CommitComplete();
+ EXPECT_FALSE(host_impl_->NeedUpdateGpuRasterizationStatusForTesting());
+
+ host_impl_->SetContentHasNonAAPaint(true);
+ EXPECT_TRUE(host_impl_->NeedUpdateGpuRasterizationStatusForTesting());
+ host_impl_->CommitComplete();
+ EXPECT_FALSE(host_impl_->NeedUpdateGpuRasterizationStatusForTesting());
+}
+
} // namespace
} // namespace cc
diff --git a/chromium/cc/trees/layer_tree_host_perftest.cc b/chromium/cc/trees/layer_tree_host_perftest.cc
index 84868dbbebc..ad705570f0a 100644
--- a/chromium/cc/trees/layer_tree_host_perftest.cc
+++ b/chromium/cc/trees/layer_tree_host_perftest.cc
@@ -21,8 +21,8 @@
#include "cc/test/layer_tree_json_parser.h"
#include "cc/test/layer_tree_test.h"
#include "cc/trees/layer_tree_impl.h"
-#include "components/viz/common/quads/single_release_callback.h"
#include "components/viz/common/quads/texture_mailbox.h"
+#include "components/viz/common/resources/single_release_callback.h"
#include "components/viz/test/paths.h"
#include "components/viz/test/test_layer_tree_frame_sink.h"
#include "testing/perf/perf_test.h"
diff --git a/chromium/cc/trees/layer_tree_host_pixeltest_blending.cc b/chromium/cc/trees/layer_tree_host_pixeltest_blending.cc
index ed920d9d427..d2585931a16 100644
--- a/chromium/cc/trees/layer_tree_host_pixeltest_blending.cc
+++ b/chromium/cc/trees/layer_tree_host_pixeltest_blending.cc
@@ -27,8 +27,7 @@ SkBlendMode const kBlendModes[] = {
SkBlendMode::kSoftLight, SkBlendMode::kDifference,
SkBlendMode::kExclusion, SkBlendMode::kMultiply,
SkBlendMode::kHue, SkBlendMode::kSaturation,
- SkBlendMode::kColor, SkBlendMode::kLuminosity,
- SkBlendMode::kDstIn};
+ SkBlendMode::kColor, SkBlendMode::kLuminosity};
SkColor kCSSTestColors[] = {
0xffff0000, // red
@@ -156,7 +155,7 @@ class LayerTreeHostBlendingPixelTest : public LayerTreeHostPixelResourceTest {
scoped_refptr<PictureImageLayer> layer = PictureImageLayer::Create();
layer->SetIsDrawable(true);
layer->SetBounds(gfx::Size(width, height));
- layer->SetImage(PaintImageBuilder()
+ layer->SetImage(PaintImageBuilder::WithDefault()
.set_id(PaintImage::GetNextId())
.set_image(backing_store->makeImageSnapshot())
.TakePaintImage());
@@ -181,7 +180,7 @@ class LayerTreeHostBlendingPixelTest : public LayerTreeHostPixelResourceTest {
bounds.width() - kMaskOffset * 2,
bounds.height() - kMaskOffset * 2),
paint);
- mask->SetImage(PaintImageBuilder()
+ mask->SetImage(PaintImageBuilder::WithDefault()
.set_id(PaintImage::GetNextId())
.set_image(surface->makeImageSnapshot())
.TakePaintImage());
@@ -198,7 +197,7 @@ class LayerTreeHostBlendingPixelTest : public LayerTreeHostPixelResourceTest {
int lane_height,
scoped_refptr<Layer> background,
RenderPassOptions flags) {
- const int kLanesCount = kBlendModesCount + 6;
+ const int kLanesCount = kBlendModesCount + 4;
const SkColor kMiscOpaqueColor = 0xffc86464;
const SkColor kMiscTransparentColor = 0x80c86464;
const SkBlendMode kCoeffBlendMode = SkBlendMode::kScreen;
@@ -224,21 +223,14 @@ class LayerTreeHostBlendingPixelTest : public LayerTreeHostPixelResourceTest {
} else if (i == kBlendModesCount + 3) {
blend_mode = kShaderBlendMode;
color = kMiscTransparentColor;
- } else if (i == kBlendModesCount + 4) {
- blend_mode = SkBlendMode::kDstIn;
- opacity = 0.5f;
- } else if (i == kBlendModesCount + 5) {
- blend_mode = SkBlendMode::kDstIn;
- color = kMiscTransparentColor;
}
-
scoped_refptr<SolidColorLayer> lane =
CreateSolidColorLayer(child_rect, color);
lane->SetBlendMode(blend_mode);
lane->SetOpacity(opacity);
lane->SetForceRenderSurfaceForTesting(true);
// Layers with kDstIn blend mode with a mask is not supported.
- if (flags & kUseMasks && blend_mode != SkBlendMode::kDstIn)
+ if (flags & kUseMasks)
SetupMaskLayer(lane);
if (flags & kUseColorMatrix) {
SetupColorMatrix(lane);
@@ -251,7 +243,7 @@ class LayerTreeHostBlendingPixelTest : public LayerTreeHostPixelResourceTest {
const base::FilePath::CharType* expected_path,
RenderPassOptions flags) {
const int kLaneWidth = 8;
- const int kRootWidth = kLaneWidth * (kBlendModesCount + 6);
+ const int kRootWidth = kLaneWidth * (kBlendModesCount + 4);
const int kRootHeight = kLaneWidth * kCSSTestColorsCount;
InitializeFromTestCase(type);
@@ -274,7 +266,7 @@ class LayerTreeHostBlendingPixelTest : public LayerTreeHostPixelResourceTest {
// Blending results might differ with one pixel.
int small_error_allowed = 1;
// Most of the errors are one pixel errors.
- float percentage_pixels_small_error = 13.1f;
+ float percentage_pixels_small_error = 13.2f;
// Because of anti-aliasing, around 10% of pixels (at the edges) have
// bigger errors (from small_error_allowed + 1 to large_error_allowed).
float percentage_pixels_error = 22.5f;
diff --git a/chromium/cc/trees/layer_tree_host_pixeltest_masks.cc b/chromium/cc/trees/layer_tree_host_pixeltest_masks.cc
index ee789667ae3..7d0b8f16b48 100644
--- a/chromium/cc/trees/layer_tree_host_pixeltest_masks.cc
+++ b/chromium/cc/trees/layer_tree_host_pixeltest_masks.cc
@@ -17,6 +17,7 @@
#include "cc/test/layer_tree_pixel_resource_test.h"
#include "cc/test/pixel_comparator.h"
#include "cc/test/solid_color_content_layer_client.h"
+#include "components/viz/test/test_layer_tree_frame_sink.h"
#include "third_party/skia/include/core/SkImage.h"
#if !defined(OS_ANDROID)
@@ -40,7 +41,7 @@ class MaskContentLayerClient : public ContentLayerClient {
scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
PaintingControlSetting picture_control) override {
- auto display_list = make_scoped_refptr(new DisplayItemList);
+ auto display_list = base::MakeRefCounted<DisplayItemList>();
display_list->StartPaint();
display_list->push<SaveOp>();
@@ -110,7 +111,7 @@ TEST_P(LayerTreeHostMasksPixelTest, ImageMaskOfLayer) {
client.PaintContentsToDisplayList(
ContentLayerClient::PAINTING_BEHAVIOR_NORMAL);
mask_display_list->Raster(canvas);
- mask->SetImage(PaintImageBuilder()
+ mask->SetImage(PaintImageBuilder::WithDefault()
.set_id(PaintImage::GetNextId())
.set_image(surface->makeImageSnapshot())
.TakePaintImage());
@@ -186,7 +187,7 @@ class CheckerContentLayerClient : public ContentLayerClient {
gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); }
scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
PaintingControlSetting picture_control) override {
- auto display_list = make_scoped_refptr(new DisplayItemList);
+ auto display_list = base::MakeRefCounted<DisplayItemList>();
display_list->StartPaint();
display_list->push<SaveOp>();
@@ -235,7 +236,7 @@ class CircleContentLayerClient : public ContentLayerClient {
gfx::Rect PaintableRegion() override { return gfx::Rect(bounds_); }
scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
PaintingControlSetting picture_control) override {
- auto display_list = make_scoped_refptr(new DisplayItemList);
+ auto display_list = base::MakeRefCounted<DisplayItemList>();
display_list->StartPaint();
display_list->push<SaveOp>();
@@ -309,6 +310,7 @@ TEST_P(LayerTreeHostMasksForBackgroundFiltersPixelTest,
mask->SetIsDrawable(true);
mask->SetLayerMaskType(mask_type_);
blur->SetMaskLayer(mask.get());
+ CHECK_EQ(Layer::LayerMaskType::SINGLE_TEXTURE_MASK, mask->mask_type());
float percentage_pixels_large_error = 2.5f; // 2.5%, ~250px / (100*100)
float percentage_pixels_small_error = 0.0f;
@@ -379,6 +381,343 @@ TEST_P(LayerTreeHostMasksForBackgroundFiltersPixelTest,
FILE_PATH_LITERAL("mask_of_layer_with_blend.png")));
}
+class StaticPictureLayer : private ContentLayerClient, public PictureLayer {
+ public:
+ static scoped_refptr<StaticPictureLayer> Create(
+ scoped_refptr<DisplayItemList> display_list) {
+ return base::WrapRefCounted(
+ new StaticPictureLayer(std::move(display_list)));
+ }
+
+ gfx::Rect PaintableRegion() override { return gfx::Rect(bounds()); }
+ scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
+ PaintingControlSetting) override {
+ return display_list_;
+ }
+ bool FillsBoundsCompletely() const override { return false; }
+ size_t GetApproximateUnsharedMemoryUsage() const override { return 0; }
+
+ protected:
+ explicit StaticPictureLayer(scoped_refptr<DisplayItemList> display_list)
+ : PictureLayer(this), display_list_(std::move(display_list)) {}
+ ~StaticPictureLayer() override {}
+
+ private:
+ scoped_refptr<DisplayItemList> display_list_;
+};
+
+class LayerTreeHostMaskAsBlendingPixelTest
+ : public LayerTreeHostPixelResourceTest,
+ public ::testing::WithParamInterface<int> {
+ public:
+ LayerTreeHostMaskAsBlendingPixelTest()
+ : LayerTreeHostPixelResourceTest(
+ GetParam() ? GL_ZERO_COPY_RECT_DRAW : SOFTWARE,
+ Layer::LayerMaskType::SINGLE_TEXTURE_MASK),
+ use_antialiasing_(GetParam() == 2 || GetParam() == 4),
+ force_shaders_(GetParam() == 3 || GetParam() == 4) {
+ float percentage_pixels_small_error = 0.f;
+ float percentage_pixels_error = 0.f;
+ float average_error_allowed_in_bad_pixels = 0.f;
+ int large_error_allowed = 0;
+ int small_error_allowed = 0;
+ if (use_antialiasing_) {
+ percentage_pixels_small_error = 0.9f;
+ percentage_pixels_error = 6.7f;
+ average_error_allowed_in_bad_pixels = 3.5f;
+ large_error_allowed = 15;
+ small_error_allowed = 1;
+ } else if (test_type_ != PIXEL_TEST_SOFTWARE) {
+ percentage_pixels_small_error = 0.9f;
+ percentage_pixels_error = 6.5f;
+ average_error_allowed_in_bad_pixels = 3.5f;
+ large_error_allowed = 15;
+ small_error_allowed = 1;
+ }
+
+ pixel_comparator_.reset(new FuzzyPixelComparator(
+ false, // discard_alpha
+ percentage_pixels_error, percentage_pixels_small_error,
+ average_error_allowed_in_bad_pixels, large_error_allowed,
+ small_error_allowed));
+ }
+
+ static scoped_refptr<Layer> CreateCheckerboardLayer(const gfx::Size& bounds) {
+ constexpr int kGridSize = 8;
+ static const SkColor color_even = SkColorSetRGB(153, 153, 153);
+ static const SkColor color_odd = SkColorSetRGB(102, 102, 102);
+
+ auto display_list = base::MakeRefCounted<DisplayItemList>();
+ display_list->StartPaint();
+ display_list->push<DrawColorOp>(color_even, SkBlendMode::kSrc);
+ PaintFlags flags;
+ flags.setColor(color_odd);
+ for (int j = 0; j < (bounds.height() + kGridSize - 1) / kGridSize; j++) {
+ for (int i = 0; i < (bounds.width() + kGridSize - 1) / kGridSize; i++) {
+ bool is_odd_grid = (i ^ j) & 1;
+ if (!is_odd_grid)
+ continue;
+ display_list->push<DrawRectOp>(
+ SkRect::MakeXYWH(i * kGridSize, j * kGridSize, kGridSize,
+ kGridSize),
+ flags);
+ }
+ }
+ display_list->EndPaintOfUnpaired(gfx::Rect(bounds));
+ display_list->Finalize();
+
+ scoped_refptr<Layer> layer =
+ StaticPictureLayer::Create(std::move(display_list));
+ layer->SetIsDrawable(true);
+ layer->SetBounds(bounds);
+ return layer;
+ }
+
+ static scoped_refptr<Layer> CreateTestPatternLayer(const gfx::Size& bounds,
+ int grid_size) {
+ // Creates a layer consists of solid grids. The grids are in a mix of
+ // different transparency and colors (1 transparent, 3 semi-transparent,
+ // and 3 opaque).
+ static SkColor test_colors[7] = {
+ SkColorSetARGB(128, 255, 0, 0), SkColorSetARGB(255, 0, 0, 255),
+ SkColorSetARGB(128, 0, 255, 0), SkColorSetARGB(128, 0, 0, 255),
+ SkColorSetARGB(255, 0, 255, 0), SkColorSetARGB(0, 0, 0, 0),
+ SkColorSetARGB(255, 255, 0, 0)};
+
+ auto display_list = base::MakeRefCounted<DisplayItemList>();
+ display_list->StartPaint();
+ for (int j = 0; j < (bounds.height() + grid_size - 1) / grid_size; j++) {
+ for (int i = 0; i < (bounds.width() + grid_size - 1) / grid_size; i++) {
+ PaintFlags flags;
+ flags.setColor(test_colors[(i + j * 3) % arraysize(test_colors)]);
+ display_list->push<DrawRectOp>(
+ SkRect::MakeXYWH(i * grid_size, j * grid_size, grid_size,
+ grid_size),
+ flags);
+ }
+ }
+ display_list->EndPaintOfUnpaired(gfx::Rect(bounds));
+ display_list->Finalize();
+
+ scoped_refptr<Layer> layer =
+ StaticPictureLayer::Create(std::move(display_list));
+ layer->SetIsDrawable(true);
+ layer->SetBounds(bounds);
+ return layer;
+ }
+
+ protected:
+ std::unique_ptr<viz::TestLayerTreeFrameSink> CreateLayerTreeFrameSink(
+ const viz::RendererSettings& renderer_settings,
+ double refresh_rate,
+ scoped_refptr<viz::ContextProvider> compositor_context_provider,
+ scoped_refptr<viz::ContextProvider> worker_context_provider) override {
+ viz::RendererSettings modified_renderer_settings = renderer_settings;
+ modified_renderer_settings.force_antialiasing = use_antialiasing_;
+ modified_renderer_settings.force_blending_with_shaders = force_shaders_;
+ return LayerTreeHostPixelResourceTest::CreateLayerTreeFrameSink(
+ modified_renderer_settings, refresh_rate,
+ std::move(compositor_context_provider),
+ std::move(worker_context_provider));
+ }
+
+ bool use_antialiasing_;
+ bool force_shaders_;
+};
+
+INSTANTIATE_TEST_CASE_P(All,
+ LayerTreeHostMaskAsBlendingPixelTest,
+ ::testing::Range(0, 5));
+// Instantiate 5 test modes of the following:
+// 0: SOFTWARE (golden sample)
+// 1: GL
+// 2: GL + AA
+// 3: GL + Forced Shaders
+// 4: GL + Forced Shaders + AA
+
+TEST_P(LayerTreeHostMaskAsBlendingPixelTest, PixelAlignedNoop) {
+ // This test verifies the degenerate case of a no-op mask doesn't affect
+ // the contents in any way.
+ scoped_refptr<Layer> root = CreateCheckerboardLayer(gfx::Size(400, 300));
+
+ scoped_refptr<Layer> mask_isolation = Layer::Create();
+ mask_isolation->SetPosition(gfx::PointF(20, 20));
+ mask_isolation->SetBounds(gfx::Size(350, 250));
+ mask_isolation->SetMasksToBounds(true);
+ mask_isolation->SetIsRootForIsolatedGroup(true);
+ root->AddChild(mask_isolation);
+
+ scoped_refptr<Layer> content =
+ CreateTestPatternLayer(gfx::Size(400, 300), 25);
+ content->SetPosition(gfx::PointF(-40, -40));
+ mask_isolation->AddChild(content);
+
+ scoped_refptr<Layer> mask_layer =
+ CreateSolidColorLayer(gfx::Rect(350, 250), kCSSBlack);
+ mask_layer->SetBlendMode(SkBlendMode::kDstIn);
+ mask_isolation->AddChild(mask_layer);
+
+ RunPixelResourceTest(
+ root, base::FilePath(FILE_PATH_LITERAL("mask_as_blending_noop.png")));
+}
+
+TEST_P(LayerTreeHostMaskAsBlendingPixelTest, PixelAlignedClippedCircle) {
+ // This test verifies a simple pixel aligned mask applies correctly.
+ scoped_refptr<Layer> root = CreateCheckerboardLayer(gfx::Size(400, 300));
+
+ scoped_refptr<Layer> mask_isolation = Layer::Create();
+ mask_isolation->SetPosition(gfx::PointF(20, 20));
+ mask_isolation->SetBounds(gfx::Size(350, 250));
+ mask_isolation->SetMasksToBounds(true);
+ mask_isolation->SetIsRootForIsolatedGroup(true);
+ root->AddChild(mask_isolation);
+
+ scoped_refptr<Layer> content =
+ CreateTestPatternLayer(gfx::Size(400, 300), 25);
+ content->SetPosition(gfx::PointF(-40, -40));
+ mask_isolation->AddChild(content);
+
+ auto display_list = base::MakeRefCounted<DisplayItemList>();
+ display_list->StartPaint();
+ PaintFlags flags;
+ flags.setColor(kCSSBlack);
+ flags.setAntiAlias(true);
+ display_list->push<DrawOvalOp>(SkRect::MakeXYWH(-5, -55, 360, 360), flags);
+ display_list->EndPaintOfUnpaired(gfx::Rect(-5, -55, 360, 360));
+ display_list->Finalize();
+ scoped_refptr<Layer> mask_layer =
+ StaticPictureLayer::Create(std::move(display_list));
+ mask_layer->SetIsDrawable(true);
+ mask_layer->SetBounds(gfx::Size(350, 250));
+ mask_layer->SetBlendMode(SkBlendMode::kDstIn);
+ mask_isolation->AddChild(mask_layer);
+
+ RunPixelResourceTest(
+ root, base::FilePath(FILE_PATH_LITERAL("mask_as_blending_circle.png")));
+}
+
+TEST_P(LayerTreeHostMaskAsBlendingPixelTest,
+ PixelAlignedClippedCircleUnderflow) {
+ // This test verifies a simple pixel aligned mask applies correctly when
+ // the content is smaller than the mask.
+ scoped_refptr<Layer> root = CreateCheckerboardLayer(gfx::Size(400, 300));
+
+ scoped_refptr<Layer> mask_isolation = Layer::Create();
+ mask_isolation->SetPosition(gfx::PointF(20, 20));
+ mask_isolation->SetBounds(gfx::Size(350, 250));
+ mask_isolation->SetMasksToBounds(true);
+ mask_isolation->SetIsRootForIsolatedGroup(true);
+ root->AddChild(mask_isolation);
+
+ scoped_refptr<Layer> content =
+ CreateTestPatternLayer(gfx::Size(330, 230), 25);
+ content->SetPosition(gfx::PointF(10, 10));
+ mask_isolation->AddChild(content);
+
+ auto display_list = base::MakeRefCounted<DisplayItemList>();
+ display_list->StartPaint();
+ PaintFlags flags;
+ flags.setColor(kCSSBlack);
+ flags.setAntiAlias(true);
+ display_list->push<DrawOvalOp>(SkRect::MakeXYWH(-5, -55, 360, 360), flags);
+ display_list->EndPaintOfUnpaired(gfx::Rect(-5, -55, 360, 360));
+ display_list->Finalize();
+ scoped_refptr<Layer> mask_layer =
+ StaticPictureLayer::Create(std::move(display_list));
+ mask_layer->SetIsDrawable(true);
+ mask_layer->SetBounds(gfx::Size(350, 250));
+ mask_layer->SetBlendMode(SkBlendMode::kDstIn);
+ mask_isolation->AddChild(mask_layer);
+
+ RunPixelResourceTest(root, base::FilePath(FILE_PATH_LITERAL(
+ "mask_as_blending_circle_underflow.png")));
+}
+
+TEST_P(LayerTreeHostMaskAsBlendingPixelTest, RotatedClippedCircle) {
+ // This test verifies a simple pixel aligned mask that is not pixel aligned
+ // to its target surface is rendered correctly.
+ scoped_refptr<Layer> root = CreateCheckerboardLayer(gfx::Size(400, 300));
+
+ scoped_refptr<Layer> mask_isolation = Layer::Create();
+ mask_isolation->SetPosition(gfx::PointF(20, 20));
+ {
+ gfx::Transform rotate;
+ rotate.Rotate(5.f);
+ mask_isolation->SetTransform(rotate);
+ }
+ mask_isolation->SetBounds(gfx::Size(350, 250));
+ mask_isolation->SetMasksToBounds(true);
+ mask_isolation->SetIsRootForIsolatedGroup(true);
+ root->AddChild(mask_isolation);
+
+ scoped_refptr<Layer> content =
+ CreateTestPatternLayer(gfx::Size(400, 300), 25);
+ content->SetPosition(gfx::PointF(-40, -40));
+ mask_isolation->AddChild(content);
+
+ auto display_list = base::MakeRefCounted<DisplayItemList>();
+ display_list->StartPaint();
+ PaintFlags flags;
+ flags.setColor(kCSSBlack);
+ flags.setAntiAlias(true);
+ display_list->push<DrawOvalOp>(SkRect::MakeXYWH(-5, -55, 360, 360), flags);
+ display_list->EndPaintOfUnpaired(gfx::Rect(-5, -55, 360, 360));
+ display_list->Finalize();
+ scoped_refptr<Layer> mask_layer =
+ StaticPictureLayer::Create(std::move(display_list));
+ mask_layer->SetIsDrawable(true);
+ mask_layer->SetBounds(gfx::Size(350, 250));
+ mask_layer->SetBlendMode(SkBlendMode::kDstIn);
+ mask_isolation->AddChild(mask_layer);
+
+ RunPixelResourceTest(
+ root,
+ base::FilePath(FILE_PATH_LITERAL("mask_as_blending_rotated_circle.png")));
+}
+
+TEST_P(LayerTreeHostMaskAsBlendingPixelTest, RotatedClippedCircleUnderflow) {
+ // This test verifies a simple pixel aligned mask that is not pixel aligned
+ // to its target surface, and has the content smaller than the mask, is
+ // rendered correctly.
+ scoped_refptr<Layer> root = CreateCheckerboardLayer(gfx::Size(400, 300));
+
+ scoped_refptr<Layer> mask_isolation = Layer::Create();
+ mask_isolation->SetPosition(gfx::PointF(20, 20));
+ {
+ gfx::Transform rotate;
+ rotate.Rotate(5.f);
+ mask_isolation->SetTransform(rotate);
+ }
+ mask_isolation->SetBounds(gfx::Size(350, 250));
+ mask_isolation->SetMasksToBounds(true);
+ mask_isolation->SetIsRootForIsolatedGroup(true);
+ root->AddChild(mask_isolation);
+
+ scoped_refptr<Layer> content =
+ CreateTestPatternLayer(gfx::Size(330, 230), 25);
+ content->SetPosition(gfx::PointF(10, 10));
+ mask_isolation->AddChild(content);
+
+ auto display_list = base::MakeRefCounted<DisplayItemList>();
+ display_list->StartPaint();
+ PaintFlags flags;
+ flags.setColor(kCSSBlack);
+ flags.setAntiAlias(true);
+ display_list->push<DrawOvalOp>(SkRect::MakeXYWH(-5, -55, 360, 360), flags);
+ display_list->EndPaintOfUnpaired(gfx::Rect(-5, -55, 360, 360));
+ display_list->Finalize();
+ scoped_refptr<Layer> mask_layer =
+ StaticPictureLayer::Create(std::move(display_list));
+ mask_layer->SetIsDrawable(true);
+ mask_layer->SetBounds(gfx::Size(350, 250));
+ mask_layer->SetBlendMode(SkBlendMode::kDstIn);
+ mask_isolation->AddChild(mask_layer);
+
+ RunPixelResourceTest(root,
+ base::FilePath(FILE_PATH_LITERAL(
+ "mask_as_blending_rotated_circle_underflow.png")));
+}
+
} // namespace
} // namespace cc
diff --git a/chromium/cc/trees/layer_tree_host_pixeltest_readback.cc b/chromium/cc/trees/layer_tree_host_pixeltest_readback.cc
index e2a5461e3b5..e00ecf772fb 100644
--- a/chromium/cc/trees/layer_tree_host_pixeltest_readback.cc
+++ b/chromium/cc/trees/layer_tree_host_pixeltest_readback.cc
@@ -10,9 +10,10 @@
#include "cc/test/layer_tree_pixel_test.h"
#include "cc/test/solid_color_content_layer_client.h"
#include "cc/trees/layer_tree_impl.h"
-#include "components/viz/common/quads/copy_output_request.h"
-#include "components/viz/common/quads/copy_output_result.h"
+#include "components/viz/common/frame_sinks/copy_output_request.h"
+#include "components/viz/common/frame_sinks/copy_output_result.h"
#include "components/viz/test/paths.h"
+#include "components/viz/test/test_layer_tree_frame_sink.h"
#if !defined(OS_ANDROID)
@@ -64,20 +65,26 @@ class LayerTreeHostReadbackPixelTest
std::unique_ptr<viz::CopyOutputRequest> request;
if (readback_type_ == READBACK_BITMAP) {
- request = viz::CopyOutputRequest::CreateBitmapRequest(base::BindOnce(
- &LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap,
- base::Unretained(this)));
+ request = std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
+ base::BindOnce(
+ &LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap,
+ base::Unretained(this)));
} else {
DCHECK_EQ(readback_type_, READBACK_DEFAULT);
if (test_type_ == PIXEL_TEST_SOFTWARE) {
- request = viz::CopyOutputRequest::CreateRequest(base::BindOnce(
- &LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap,
- base::Unretained(this)));
+ request = std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
+ base::BindOnce(
+ &LayerTreeHostReadbackPixelTest::ReadbackResultAsBitmap,
+ base::Unretained(this)));
} else {
DCHECK_EQ(test_type_, PIXEL_TEST_GL);
- request = viz::CopyOutputRequest::CreateRequest(base::BindOnce(
- &LayerTreeHostReadbackPixelTest::ReadbackResultAsTexture,
- base::Unretained(this)));
+ request = std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_TEXTURE,
+ base::BindOnce(
+ &LayerTreeHostReadbackPixelTest::ReadbackResultAsTexture,
+ base::Unretained(this)));
}
}
@@ -106,36 +113,39 @@ class LayerTreeHostReadbackPixelTest
void ReadbackResultAsBitmap(std::unique_ptr<viz::CopyOutputResult> result) {
EXPECT_TRUE(task_runner_provider()->IsMainThread());
- EXPECT_TRUE(result->HasBitmap());
- result_bitmap_ = result->TakeBitmap();
+ EXPECT_FALSE(result->IsEmpty());
+ result_bitmap_ = std::make_unique<SkBitmap>(result->AsSkBitmap());
+ EXPECT_TRUE(result_bitmap_->readyToDraw());
EndTest();
}
void ReadbackResultAsTexture(std::unique_ptr<viz::CopyOutputResult> result) {
EXPECT_TRUE(task_runner_provider()->IsMainThread());
- EXPECT_TRUE(result->HasTexture());
+ EXPECT_EQ(result->format(), viz::CopyOutputResult::Format::RGBA_TEXTURE);
viz::TextureMailbox texture_mailbox;
std::unique_ptr<viz::SingleReleaseCallback> release_callback;
- result->TakeTexture(&texture_mailbox, &release_callback);
- EXPECT_TRUE(texture_mailbox.IsValid());
- EXPECT_TRUE(texture_mailbox.IsTexture());
+ if (auto* mailbox = result->GetTextureMailbox()) {
+ texture_mailbox = *mailbox;
+ release_callback = result->TakeTextureOwnership();
+ }
+ ASSERT_TRUE(texture_mailbox.IsTexture());
+ EXPECT_EQ(texture_mailbox.color_space(), output_color_space_);
- std::unique_ptr<SkBitmap> bitmap =
+ const SkBitmap bitmap =
CopyTextureMailboxToBitmap(result->size(), texture_mailbox);
release_callback->Run(gpu::SyncToken(), false);
- ReadbackResultAsBitmap(
- viz::CopyOutputResult::CreateBitmapResult(std::move(bitmap)));
+ ReadbackResultAsBitmap(std::make_unique<viz::CopyOutputSkBitmapResult>(
+ result->rect(), bitmap));
}
ReadbackType readback_type_;
gfx::Rect copy_subrect_;
+ gfx::ColorSpace output_color_space_ = gfx::ColorSpace::CreateSRGB();
int insert_copy_request_after_frame_count_;
};
-void IgnoreReadbackResult(std::unique_ptr<viz::CopyOutputResult> result) {}
-
TEST_P(LayerTreeHostReadbackPixelTest, ReadbackRootLayer) {
scoped_refptr<SolidColorLayer> background =
CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorWHITE);
@@ -290,8 +300,7 @@ TEST_P(LayerTreeHostReadbackPixelTest,
hidden_target->AddChild(blue);
hidden_target->RequestCopyOfOutput(
- viz::CopyOutputRequest::CreateBitmapRequest(
- base::BindOnce(&IgnoreReadbackResult)));
+ viz::CopyOutputRequest::CreateStubForTesting());
RunReadbackTest(GetParam().pixel_test_type, GetParam().readback_type,
background, base::FilePath(FILE_PATH_LITERAL("black.png")));
}
@@ -415,8 +424,7 @@ TEST_P(LayerTreeHostReadbackPixelTest, ReadbackNonRootOrFirstLayer) {
scoped_refptr<SolidColorLayer> blue =
CreateSolidColorLayer(gfx::Rect(150, 150, 50, 50), SK_ColorBLUE);
- blue->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest(
- base::BindOnce(&IgnoreReadbackResult)));
+ blue->RequestCopyOfOutput(viz::CopyOutputRequest::CreateStubForTesting());
background->AddChild(blue);
RunReadbackTestWithReadbackTarget(
@@ -435,8 +443,8 @@ TEST_P(LayerTreeHostReadbackPixelTest, MultipleReadbacksOnLayer) {
scoped_refptr<SolidColorLayer> background =
CreateSolidColorLayer(gfx::Rect(200, 200), SK_ColorGREEN);
- background->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest(
- base::BindOnce(&IgnoreReadbackResult)));
+ background->RequestCopyOfOutput(
+ viz::CopyOutputRequest::CreateStubForTesting());
RunReadbackTestWithReadbackTarget(
GetParam().pixel_test_type, GetParam().readback_type, background,
@@ -551,6 +559,55 @@ INSTANTIATE_TEST_CASE_P(
ReadbackTestConfig(LayerTreeHostReadbackPixelTest::PIXEL_TEST_GL,
READBACK_BITMAP)));
+class LayerTreeHostReadbackColorSpacePixelTest
+ : public LayerTreeHostReadbackPixelTest {
+ protected:
+ LayerTreeHostReadbackColorSpacePixelTest()
+ : green_client_(SK_ColorGREEN, gfx::Size(200, 200)) {
+ output_color_space_ = gfx::ColorSpace::CreateDisplayP3D65();
+ }
+
+ std::unique_ptr<viz::TestLayerTreeFrameSink> CreateLayerTreeFrameSink(
+ const viz::RendererSettings& renderer_settings,
+ double refresh_rate,
+ scoped_refptr<viz::ContextProvider> compositor_context_provider,
+ scoped_refptr<viz::ContextProvider> worker_context_provider) override {
+ std::unique_ptr<viz::TestLayerTreeFrameSink> frame_sink =
+ LayerTreePixelTest::CreateLayerTreeFrameSink(
+ renderer_settings, refresh_rate, compositor_context_provider,
+ worker_context_provider);
+ frame_sink->SetDisplayColorSpace(output_color_space_, output_color_space_);
+ return frame_sink;
+ }
+
+ SolidColorContentLayerClient green_client_;
+};
+
+TEST_P(LayerTreeHostReadbackColorSpacePixelTest, Readback) {
+ scoped_refptr<FakePictureLayer> background =
+ FakePictureLayer::Create(&green_client_);
+ background->SetBounds(gfx::Size(200, 200));
+ background->SetIsDrawable(true);
+
+ if (GetParam().pixel_test_type == PIXEL_TEST_SOFTWARE) {
+ // Software compositing doesn't support color conversion, so the result will
+ // come out in sRGB, regardless of the display's color properties.
+ RunReadbackTest(GetParam().pixel_test_type, GetParam().readback_type,
+ background, base::FilePath(FILE_PATH_LITERAL("green.png")));
+ } else {
+ // GL compositing will convert the sRGB green into P3.
+ RunReadbackTest(GetParam().pixel_test_type, GetParam().readback_type,
+ background,
+ base::FilePath(FILE_PATH_LITERAL("srgb_green_in_p3.png")));
+ }
+}
+
+INSTANTIATE_TEST_CASE_P(LayerTreeHostReadbackColorSpacePixelTests,
+ LayerTreeHostReadbackColorSpacePixelTest,
+ ::testing::Values(ReadbackTestConfig(
+ LayerTreeHostReadbackPixelTest::PIXEL_TEST_GL,
+ READBACK_BITMAP)));
+
} // namespace
} // namespace cc
diff --git a/chromium/cc/trees/layer_tree_host_pixeltest_tiles.cc b/chromium/cc/trees/layer_tree_host_pixeltest_tiles.cc
index 64ad1811822..8f21cb8fe2f 100644
--- a/chromium/cc/trees/layer_tree_host_pixeltest_tiles.cc
+++ b/chromium/cc/trees/layer_tree_host_pixeltest_tiles.cc
@@ -10,7 +10,7 @@
#include "cc/paint/paint_flags.h"
#include "cc/paint/paint_op_buffer.h"
#include "cc/test/layer_tree_pixel_test.h"
-#include "components/viz/common/quads/copy_output_request.h"
+#include "components/viz/common/frame_sinks/copy_output_request.h"
#include "components/viz/test/test_layer_tree_frame_sink.h"
#include "gpu/command_buffer/client/gles2_interface.h"
@@ -107,7 +107,7 @@ class BlueYellowClient : public ContentLayerClient {
gfx::Rect PaintableRegion() override { return gfx::Rect(size_); }
scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
PaintingControlSetting painting_status) override {
- auto display_list = make_scoped_refptr(new DisplayItemList);
+ auto display_list = base::MakeRefCounted<DisplayItemList>();
display_list->StartPaint();
diff --git a/chromium/cc/trees/layer_tree_host_unittest.cc b/chromium/cc/trees/layer_tree_host_unittest.cc
index ce820e213b5..a6d8479464b 100644
--- a/chromium/cc/trees/layer_tree_host_unittest.cc
+++ b/chromium/cc/trees/layer_tree_host_unittest.cc
@@ -25,15 +25,12 @@
#include "cc/layers/picture_layer.h"
#include "cc/layers/solid_color_layer.h"
#include "cc/layers/video_layer.h"
-#include "cc/output/output_surface.h"
-#include "cc/output/swap_promise.h"
-#include "cc/quads/draw_quad.h"
-#include "cc/quads/render_pass_draw_quad.h"
-#include "cc/quads/tile_draw_quad.h"
+#include "cc/paint/image_animation_count.h"
#include "cc/resources/ui_resource_manager.h"
#include "cc/test/fake_content_layer_client.h"
#include "cc/test/fake_layer_tree_host_client.h"
#include "cc/test/fake_output_surface.h"
+#include "cc/test/fake_paint_image_generator.h"
#include "cc/test/fake_painted_scrollbar_layer.h"
#include "cc/test/fake_picture_layer.h"
#include "cc/test/fake_picture_layer_impl.h"
@@ -57,11 +54,16 @@
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/scroll_node.h"
#include "cc/trees/single_thread_proxy.h"
+#include "cc/trees/swap_promise.h"
#include "cc/trees/swap_promise_manager.h"
#include "cc/trees/transform_node.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"
-#include "components/viz/common/quads/copy_output_request.h"
-#include "components/viz/common/quads/copy_output_result.h"
+#include "components/viz/common/frame_sinks/copy_output_request.h"
+#include "components/viz/common/frame_sinks/copy_output_result.h"
+#include "components/viz/common/quads/draw_quad.h"
+#include "components/viz/common/quads/render_pass_draw_quad.h"
+#include "components/viz/common/quads/tile_draw_quad.h"
+#include "components/viz/service/display/output_surface.h"
#include "components/viz/test/begin_frame_args_test.h"
#include "components/viz/test/test_layer_tree_frame_sink.h"
#include "gpu/GLES2/gl2extchromium.h"
@@ -1685,9 +1687,9 @@ class LayerTreeHostTestSwitchMaskLayer : public LayerTreeHostTest {
void SetupTree() override {
scoped_refptr<Layer> root = Layer::Create();
root->SetBounds(gfx::Size(10, 10));
- child_layer_ = make_scoped_refptr(new UpdateCountingLayer);
+ child_layer_ = base::MakeRefCounted<UpdateCountingLayer>();
child_layer_->SetBounds(gfx::Size(10, 10));
- mask_layer_ = make_scoped_refptr(new UpdateCountingLayer);
+ mask_layer_ = base::MakeRefCounted<UpdateCountingLayer>();
mask_layer_->SetBounds(gfx::Size(10, 10));
child_layer_->SetMaskLayer(mask_layer_.get());
root->AddChild(child_layer_);
@@ -4912,7 +4914,7 @@ class TestSwapPromise : public SwapPromise {
result_->did_activate_called = true;
}
- void WillSwap(CompositorFrameMetadata* metadata) override {
+ void WillSwap(viz::CompositorFrameMetadata* metadata) override {
base::AutoLock lock(result_->lock);
EXPECT_FALSE(result_->did_swap_called);
EXPECT_FALSE(result_->did_not_swap_called);
@@ -5627,13 +5629,20 @@ class LayerTreeHostWithGpuRasterizationTest : public LayerTreeHostTest {
std::unique_ptr<viz::TestLayerTreeFrameSink> CreateLayerTreeFrameSink(
const viz::RendererSettings& renderer_settings,
double refresh_rate,
- scoped_refptr<viz::ContextProvider> compositor_context_provider,
- scoped_refptr<viz::ContextProvider> worker_context_provider) override {
- auto context = TestWebGraphicsContext3D::Create();
- context->SetMaxSamples(4);
- context->set_support_multisample_compatibility(false);
- context->set_gpu_rasterization(true);
- auto context_provider = TestContextProvider::Create(std::move(context));
+ scoped_refptr<viz::ContextProvider> ignored_compositor_context_provider,
+ scoped_refptr<viz::ContextProvider> ignored_worker_context_provider)
+ override {
+ auto context_provider = TestContextProvider::Create();
+ context_provider->UnboundTestContext3d()->SetMaxSamples(4);
+ context_provider->UnboundTestContext3d()
+ ->set_support_multisample_compatibility(false);
+ context_provider->UnboundTestContext3d()->set_gpu_rasterization(true);
+ auto worker_context_provider = TestContextProvider::CreateWorker();
+ worker_context_provider->UnboundTestContext3d()->SetMaxSamples(4);
+ worker_context_provider->UnboundTestContext3d()
+ ->set_support_multisample_compatibility(false);
+ worker_context_provider->UnboundTestContext3d()->set_gpu_rasterization(
+ true);
return LayerTreeHostTest::CreateLayerTreeFrameSink(
renderer_settings, refresh_rate, std::move(context_provider),
std::move(worker_context_provider));
@@ -6334,12 +6343,13 @@ class LayerTreeHostTestCrispUpAfterPinchEnds : public LayerTreeHostTest {
if (frame_data->has_no_damage)
return 0.f;
float frame_scale = 0.f;
- RenderPass* root_pass = frame_data->render_passes.back().get();
+ viz::RenderPass* root_pass = frame_data->render_passes.back().get();
for (auto* draw_quad : root_pass->quad_list) {
// Checkerboards mean an incomplete frame.
- if (draw_quad->material != DrawQuad::TILED_CONTENT)
+ if (draw_quad->material != viz::DrawQuad::TILED_CONTENT)
return 0.f;
- const TileDrawQuad* quad = TileDrawQuad::MaterialCast(draw_quad);
+ const viz::TileDrawQuad* quad =
+ viz::TileDrawQuad::MaterialCast(draw_quad);
float quad_scale =
quad->tex_coord_rect.width() / static_cast<float>(quad->rect.width());
float transform_scale = SkMScalarToFloat(
@@ -6481,7 +6491,7 @@ MULTI_THREAD_TEST_F(LayerTreeHostTestCrispUpAfterPinchEnds);
class LayerTreeHostTestCrispUpAfterPinchEndsWithOneCopy
: public LayerTreeHostTestCrispUpAfterPinchEnds {
protected:
- std::unique_ptr<OutputSurface> CreateDisplayOutputSurfaceOnThread(
+ std::unique_ptr<viz::OutputSurface> CreateDisplayOutputSurfaceOnThread(
scoped_refptr<viz::ContextProvider> compositor_context_provider)
override {
scoped_refptr<TestContextProvider> display_context_provider =
@@ -6642,9 +6652,10 @@ class LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles
if (frame_data->has_no_damage)
return 0.f;
float frame_scale = 0.f;
- RenderPass* root_pass = frame_data->render_passes.back().get();
+ viz::RenderPass* root_pass = frame_data->render_passes.back().get();
for (auto* draw_quad : root_pass->quad_list) {
- const TileDrawQuad* quad = TileDrawQuad::MaterialCast(draw_quad);
+ const viz::TileDrawQuad* quad =
+ viz::TileDrawQuad::MaterialCast(draw_quad);
float quad_scale =
quad->tex_coord_rect.width() / static_cast<float>(quad->rect.width());
float transform_scale = SkMScalarToFloat(
@@ -6924,9 +6935,6 @@ class LayerTreeHostTestUpdateCopyRequests : public LayerTreeHostTest {
LayerTreeHostTest::SetupTree();
}
- static void CopyOutputCallback(
- std::unique_ptr<viz::CopyOutputResult> result) {}
-
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillCommit() override {
@@ -6941,8 +6949,8 @@ class LayerTreeHostTestUpdateCopyRequests : public LayerTreeHostTest {
gfx::Transform transform;
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
- child->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest(
- base::BindOnce(CopyOutputCallback)));
+ child->RequestCopyOfOutput(
+ viz::CopyOutputRequest::CreateStubForTesting());
transform.Scale(2.0, 2.0);
child->SetTransform(transform);
break;
@@ -7029,15 +7037,17 @@ class LayerTreeTestMaskLayerForSurfaceWithContentRectNotAtOrigin
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_EQ(2u, frame_data->render_passes.size());
- RenderPass* root_pass = frame_data->render_passes.back().get();
+ viz::RenderPass* root_pass = frame_data->render_passes.back().get();
EXPECT_EQ(2u, root_pass->quad_list.size());
// There's a solid color quad under everything.
- EXPECT_EQ(DrawQuad::SOLID_COLOR, root_pass->quad_list.back()->material);
+ EXPECT_EQ(viz::DrawQuad::SOLID_COLOR,
+ root_pass->quad_list.back()->material);
- EXPECT_EQ(DrawQuad::RENDER_PASS, root_pass->quad_list.front()->material);
- const RenderPassDrawQuad* render_pass_quad =
- RenderPassDrawQuad::MaterialCast(root_pass->quad_list.front());
+ EXPECT_EQ(viz::DrawQuad::RENDER_PASS,
+ root_pass->quad_list.front()->material);
+ const viz::RenderPassDrawQuad* render_pass_quad =
+ viz::RenderPassDrawQuad::MaterialCast(root_pass->quad_list.front());
EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(),
render_pass_quad->rect.ToString());
if (host_impl->settings().enable_mask_tiling) {
@@ -7156,16 +7166,18 @@ class LayerTreeTestMaskLayerForSurfaceWithClippedLayer : public LayerTreeTest {
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_EQ(2u, frame_data->render_passes.size());
- RenderPass* root_pass = frame_data->render_passes.back().get();
+ viz::RenderPass* root_pass = frame_data->render_passes.back().get();
EXPECT_EQ(2u, root_pass->quad_list.size());
// There's a solid color quad under everything.
- EXPECT_EQ(DrawQuad::SOLID_COLOR, root_pass->quad_list.back()->material);
+ EXPECT_EQ(viz::DrawQuad::SOLID_COLOR,
+ root_pass->quad_list.back()->material);
// The surface is clipped to 10x20.
- EXPECT_EQ(DrawQuad::RENDER_PASS, root_pass->quad_list.front()->material);
- const RenderPassDrawQuad* render_pass_quad =
- RenderPassDrawQuad::MaterialCast(root_pass->quad_list.front());
+ EXPECT_EQ(viz::DrawQuad::RENDER_PASS,
+ root_pass->quad_list.front()->material);
+ const viz::RenderPassDrawQuad* render_pass_quad =
+ viz::RenderPassDrawQuad::MaterialCast(root_pass->quad_list.front());
EXPECT_EQ(gfx::Rect(20, 10, 10, 20).ToString(),
render_pass_quad->rect.ToString());
// The masked layer is 50x50, but the surface size is 10x20. So the texture
@@ -7278,15 +7290,17 @@ class LayerTreeTestMaskLayerWithScaling : public LayerTreeTest {
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_EQ(2u, frame_data->render_passes.size());
- RenderPass* root_pass = frame_data->render_passes.back().get();
+ viz::RenderPass* root_pass = frame_data->render_passes.back().get();
EXPECT_EQ(2u, root_pass->quad_list.size());
// There's a solid color quad under everything.
- EXPECT_EQ(DrawQuad::SOLID_COLOR, root_pass->quad_list.back()->material);
+ EXPECT_EQ(viz::DrawQuad::SOLID_COLOR,
+ root_pass->quad_list.back()->material);
- EXPECT_EQ(DrawQuad::RENDER_PASS, root_pass->quad_list.front()->material);
- const RenderPassDrawQuad* render_pass_quad =
- RenderPassDrawQuad::MaterialCast(root_pass->quad_list.front());
+ EXPECT_EQ(viz::DrawQuad::RENDER_PASS,
+ root_pass->quad_list.front()->material);
+ const viz::RenderPassDrawQuad* render_pass_quad =
+ viz::RenderPassDrawQuad::MaterialCast(root_pass->quad_list.front());
switch (host_impl->active_tree()->source_frame_number()) {
case 0:
// Check that the tree scaling is correctly taken into account for the
@@ -7407,16 +7421,18 @@ class LayerTreeTestMaskWithNonExactTextureSize : public LayerTreeTest {
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_EQ(2u, frame_data->render_passes.size());
- RenderPass* root_pass = frame_data->render_passes.back().get();
+ viz::RenderPass* root_pass = frame_data->render_passes.back().get();
EXPECT_EQ(2u, root_pass->quad_list.size());
// There's a solid color quad under everything.
- EXPECT_EQ(DrawQuad::SOLID_COLOR, root_pass->quad_list.back()->material);
+ EXPECT_EQ(viz::DrawQuad::SOLID_COLOR,
+ root_pass->quad_list.back()->material);
// The surface is 100x100
- EXPECT_EQ(DrawQuad::RENDER_PASS, root_pass->quad_list.front()->material);
- const RenderPassDrawQuad* render_pass_quad =
- RenderPassDrawQuad::MaterialCast(root_pass->quad_list.front());
+ EXPECT_EQ(viz::DrawQuad::RENDER_PASS,
+ root_pass->quad_list.front()->material);
+ const viz::RenderPassDrawQuad* render_pass_quad =
+ viz::RenderPassDrawQuad::MaterialCast(root_pass->quad_list.front());
EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
render_pass_quad->rect.ToString());
// The mask layer is 100x100, but is backed by a 120x150 image.
@@ -7537,7 +7553,7 @@ class LayerTreeHostTestPaintedDeviceScaleFactor : public LayerTreeHostTest {
}
void DisplayReceivedCompositorFrameOnThread(
- const CompositorFrame& frame) override {
+ const viz::CompositorFrame& frame) override {
EXPECT_EQ(2.0f, frame.metadata.device_scale_factor);
EndTest();
}
@@ -7675,7 +7691,7 @@ class LayerTreeHostTestSubmitFrameMetadata : public LayerTreeHostTest {
}
void DisplayReceivedCompositorFrameOnThread(
- const CompositorFrame& frame) override {
+ const viz::CompositorFrame& frame) override {
EXPECT_EQ(1, ++num_swaps_);
EXPECT_EQ(drawn_viewport_, frame.render_pass_list.back()->output_rect);
@@ -7705,14 +7721,14 @@ class LayerTreeHostTestSubmitFrameResources : public LayerTreeHostTest {
DrawResult draw_result) override {
frame->render_passes.clear();
- RenderPass* child_pass =
+ viz::RenderPass* child_pass =
AddRenderPass(&frame->render_passes, 2, gfx::Rect(3, 3, 10, 10),
gfx::Transform(), FilterOperations());
gpu::SyncToken mailbox_sync_token;
AddOneOfEveryQuadType(child_pass, host_impl->resource_provider(), 0,
&mailbox_sync_token);
- RenderPass* pass =
+ viz::RenderPass* pass =
AddRenderPass(&frame->render_passes, 1, gfx::Rect(3, 3, 10, 10),
gfx::Transform(), FilterOperations());
AddOneOfEveryQuadType(pass, host_impl->resource_provider(), child_pass->id,
@@ -7721,7 +7737,7 @@ class LayerTreeHostTestSubmitFrameResources : public LayerTreeHostTest {
}
void DisplayReceivedCompositorFrameOnThread(
- const CompositorFrame& frame) override {
+ const viz::CompositorFrame& frame) override {
EXPECT_EQ(2u, frame.render_pass_list.size());
// Each render pass has 10 resources in it. And the root render pass has a
// mask resource used when drawing the child render pass. The number 10 may
@@ -7754,7 +7770,7 @@ class LayerTreeHostTestContentSourceId : public LayerTreeHostTest {
}
void DisplayReceivedCompositorFrameOnThread(
- const CompositorFrame& frame) override {
+ const viz::CompositorFrame& frame) override {
EXPECT_EQ(5U, frame.metadata.content_source_id);
EndTest();
}
@@ -7782,7 +7798,7 @@ class LayerTreeHostTestBeginFrameAcks : public LayerTreeHostTest {
}
void DisplayReceivedCompositorFrameOnThread(
- const CompositorFrame& frame) override {
+ const viz::CompositorFrame& frame) override {
if (compositor_frame_submitted_)
return;
compositor_frame_submitted_ = true;
@@ -7834,7 +7850,8 @@ class LayerTreeHostTestQueueImageDecode : public LayerTreeHostTest {
image_ = DrawImage(CreateDiscardablePaintImage(gfx::Size(400, 400)),
SkIRect::MakeWH(400, 400), kNone_SkFilterQuality,
- SkMatrix::I(), gfx::ColorSpace());
+ SkMatrix::I(), PaintImage::kDefaultFrameIndex,
+ gfx::ColorSpace());
auto callback =
base::Bind(&LayerTreeHostTestQueueImageDecode::ImageDecodeFinished,
base::Unretained(this));
@@ -7844,24 +7861,20 @@ class LayerTreeHostTestQueueImageDecode : public LayerTreeHostTest {
}
void ReadyToCommitOnThread(LayerTreeHostImpl* impl) override {
- const bool required_for_activation = true;
-
if (one_commit_done_)
return;
EXPECT_TRUE(
impl->tile_manager()->checker_image_tracker().ShouldCheckerImage(
- image_, WhichTree::PENDING_TREE, required_for_activation));
+ image_, WhichTree::PENDING_TREE));
// Reset the tracker as if it has never seen this image.
impl->tile_manager()->checker_image_tracker().ClearTracker(true);
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
- const bool required_for_activation = true;
-
one_commit_done_ = true;
EXPECT_FALSE(
impl->tile_manager()->checker_image_tracker().ShouldCheckerImage(
- image_, WhichTree::PENDING_TREE, required_for_activation));
+ image_, WhichTree::PENDING_TREE));
}
void ImageDecodeFinished(bool decode_succeeded) {
@@ -7893,7 +7906,7 @@ class LayerTreeHostTestQueueImageDecodeNonLazy : public LayerTreeHostTest {
first_ = false;
bitmap_.allocN32Pixels(10, 10);
- PaintImage image = PaintImageBuilder()
+ PaintImage image = PaintImageBuilder::WithDefault()
.set_id(PaintImage::GetNextId())
.set_image(SkImage::MakeFromBitmap(bitmap_))
.TakePaintImage();
@@ -8034,5 +8047,86 @@ class LayerTreeHostTestDiscardAckAfterRelease : public LayerTreeHostTest {
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDiscardAckAfterRelease);
+class LayerTreeHostTestImageAnimation : public LayerTreeHostTest {
+ public:
+ void BeginTest() override { PostSetNeedsCommitToMainThread(); }
+
+ void InitializeSettings(LayerTreeSettings* settings) override {
+ settings->enable_image_animations = true;
+ }
+
+ void SetupTree() override {
+ gfx::Size layer_size(1000, 500);
+ content_layer_client_.set_bounds(layer_size);
+ content_layer_client_.set_fill_with_nonsolid_color(true);
+ std::vector<FrameMetadata> frames = {
+ FrameMetadata(true, base::TimeDelta::FromSeconds(1)),
+ FrameMetadata(true, base::TimeDelta::FromSeconds(1)),
+ FrameMetadata(true, base::TimeDelta::FromSeconds(1))};
+ generator_ = sk_make_sp<FakePaintImageGenerator>(
+ SkImageInfo::MakeN32Premul(500, 500, SkColorSpace::MakeSRGB()), frames);
+ PaintImage image =
+ PaintImageBuilder::WithDefault()
+ .set_id(PaintImage::GetNextId())
+ .set_paint_image_generator(generator_)
+ .set_frame_index(0u)
+ .set_animation_type(PaintImage::AnimationType::ANIMATED)
+ .set_repetition_count(kAnimationLoopOnce)
+ .TakePaintImage();
+ content_layer_client_.add_draw_image(image, gfx::Point(0, 0), PaintFlags());
+
+ layer_tree_host()->SetRootLayer(
+ FakePictureLayer::Create(&content_layer_client_));
+ layer_tree_host()->root_layer()->SetBounds(layer_size);
+ LayerTreeTest::SetupTree();
+ }
+
+ void WillPrepareToDrawOnThread(LayerTreeHostImpl* host_impl) override {
+ gfx::Rect image_rect(-1, -1, 502, 502);
+ auto* layer = static_cast<PictureLayerImpl*>(
+ host_impl->active_tree()->root_layer_for_testing());
+ switch (++draw_count_) {
+ case 1:
+ // First draw, everything is invalid.
+ EXPECT_EQ(layer->InvalidationForTesting().bounds(),
+ gfx::Rect(layer->bounds()));
+ EXPECT_EQ(layer->update_rect(), gfx::Rect(layer->bounds()));
+ EXPECT_EQ(generator_->frames_decoded().size(), 1u);
+ EXPECT_EQ(generator_->frames_decoded().count(0u), 1u);
+ break;
+ case 2:
+ // Every frame after the first one should invalidate only the image.
+ EXPECT_EQ(layer->InvalidationForTesting().bounds(), image_rect);
+ EXPECT_EQ(layer->update_rect(), image_rect);
+ EXPECT_EQ(generator_->frames_decoded().size(), 2u);
+ EXPECT_EQ(generator_->frames_decoded().count(1u), 1u);
+ break;
+ case 3:
+ EXPECT_EQ(layer->InvalidationForTesting().bounds(), image_rect);
+ EXPECT_EQ(layer->update_rect(), image_rect);
+ EXPECT_EQ(generator_->frames_decoded().size(), 3u);
+ EXPECT_EQ(generator_->frames_decoded().count(2u), 1u);
+ break;
+ default:
+ // Only 3 draws should happen for 3 frames of the animate image.
+ NOTREACHED();
+ }
+
+ if (draw_count_ == 3)
+ EndTest();
+ }
+
+ void AfterTest() override {
+ EXPECT_EQ(generator_->frames_decoded().size(), 3u);
+ }
+
+ private:
+ FakeContentLayerClient content_layer_client_;
+ sk_sp<FakePaintImageGenerator> generator_;
+ int draw_count_ = 0;
+};
+
+MULTI_THREAD_TEST_F(LayerTreeHostTestImageAnimation);
+
} // namespace
} // namespace cc
diff --git a/chromium/cc/trees/layer_tree_host_unittest_animation.cc b/chromium/cc/trees/layer_tree_host_unittest_animation.cc
index 3ef88edebdb..3e61e27544a 100644
--- a/chromium/cc/trees/layer_tree_host_unittest_animation.cc
+++ b/chromium/cc/trees/layer_tree_host_unittest_animation.cc
@@ -7,10 +7,12 @@
#include <stdint.h>
#include <climits>
+#include "base/bind.h"
#include "cc/animation/animation_curve.h"
#include "cc/animation/animation_host.h"
#include "cc/animation/animation_id_provider.h"
#include "cc/animation/animation_player.h"
+#include "cc/animation/animation_ticker.h"
#include "cc/animation/animation_timeline.h"
#include "cc/animation/element_animations.h"
#include "cc/animation/scroll_offset_animation_curve.h"
@@ -24,6 +26,7 @@
#include "cc/test/fake_content_layer_client.h"
#include "cc/test/fake_picture_layer.h"
#include "cc/test/layer_tree_test.h"
+#include "cc/test/mock_layer_client.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/transform_node.h"
@@ -425,6 +428,41 @@ class LayerTreeHostAnimationTestAnimationFinishedEvents
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeHostAnimationTestAnimationFinishedEvents);
+// Ensures that LayerClient::DidChangeLayerOpacity() is notified when an
+// animation changes the opacity of a Layer.
+class LayerTreeHostAnimationTestOpacityAnimationNotifiesClient
+ : public LayerTreeHostAnimationTest {
+ public:
+ void BeginTest() override {
+ AttachPlayersToTimeline();
+ Layer* layer = layer_tree_host()->root_layer();
+ layer->SetLayerClient(&layer_client_);
+ player_->AttachElement(layer->element_id());
+ MainThreadTaskRunner()->PostTask(
+ FROM_HERE,
+ base::BindOnce(base::IgnoreResult(&AddOpacityTransitionToPlayer),
+ base::Unretained(player_.get()), 0.0, 1.0f, 0.5f, true));
+ EXPECT_CALL(layer_client_, DidChangeLayerOpacity(1.0f, 0.5f));
+ }
+
+ void NotifyAnimationFinished(base::TimeTicks monotonic_time,
+ int target_property,
+ int group) override {
+ Animation* animation = player_->GetAnimation(TargetProperty::OPACITY);
+ if (animation)
+ player_->RemoveAnimation(animation->id());
+ EndTest();
+ }
+
+ void AfterTest() override {}
+
+ private:
+ MockLayerClient layer_client_;
+};
+
+SINGLE_AND_MULTI_THREAD_TEST_F(
+ LayerTreeHostAnimationTestOpacityAnimationNotifiesClient);
+
// Ensures that when opacity is being animated, this value does not cause the
// subtree to be skipped.
class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity
@@ -754,6 +792,8 @@ class LayerTreeHostAnimationTestScrollOffsetChangesArePropagated
break;
}
default:
+ EXPECT_GE(scroll_layer_->scroll_offset().x(), 10);
+ EXPECT_GE(scroll_layer_->scroll_offset().y(), 20);
if (scroll_layer_->scroll_offset().x() > 10 &&
scroll_layer_->scroll_offset().y() > 20)
EndTest();
@@ -850,17 +890,17 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted
AttachPlayersToTimeline();
}
- AnimationPlayer& ScrollOffsetPlayer(
+ AnimationTicker& ScrollOffsetTicker(
const LayerTreeHostImpl& host_impl,
scoped_refptr<FakePictureLayer> layer) const {
scoped_refptr<ElementAnimations> element_animations =
GetImplAnimationHost(&host_impl)
->GetElementAnimationsForElementId(layer->element_id());
DCHECK(element_animations);
- DCHECK(element_animations->players_list().might_have_observers());
- AnimationPlayer* player = &*element_animations->players_list().begin();
- DCHECK(player);
- return *player;
+ DCHECK(element_animations->tickers_list().might_have_observers());
+ AnimationTicker* ticker = &*element_animations->tickers_list().begin();
+ DCHECK(ticker);
+ return *ticker;
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
@@ -887,7 +927,7 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted
GetImplTimelineAndPlayerByID(*host_impl);
// This happens after the impl-only animation is added in
// WillCommitCompleteOnThread.
- Animation* animation = ScrollOffsetPlayer(*host_impl, scroll_layer_)
+ Animation* animation = ScrollOffsetTicker(*host_impl, scroll_layer_)
.GetAnimation(TargetProperty::SCROLL_OFFSET);
DCHECK(animation);
ScrollOffsetAnimationCurve* curve =
@@ -911,7 +951,7 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->sync_tree()->source_frame_number() == 1) {
- Animation* animation = ScrollOffsetPlayer(*host_impl, scroll_layer_)
+ Animation* animation = ScrollOffsetTicker(*host_impl, scroll_layer_)
.GetAnimation(TargetProperty::SCROLL_OFFSET);
DCHECK(animation);
ScrollOffsetAnimationCurve* curve =
@@ -975,8 +1015,12 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval
void BeginMainFrame(const viz::BeginFrameArgs& args) override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 0:
+ EXPECT_EQ(scroll_layer_->scroll_offset().x(), 100);
+ EXPECT_EQ(scroll_layer_->scroll_offset().y(), 200);
break;
case 1: {
+ EXPECT_GE(scroll_layer_->scroll_offset().x(), 100);
+ EXPECT_GE(scroll_layer_->scroll_offset().y(), 200);
Animation* animation =
player_child_->GetAnimation(TargetProperty::SCROLL_OFFSET);
player_child_->RemoveAnimation(animation->id());
@@ -1466,7 +1510,7 @@ class LayerTreeHostAnimationTestRemoveAnimation
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->sync_tree()->source_frame_number() >= last_frame_number_) {
// Check that eventually the animation is removed.
- EXPECT_FALSE(player_child_impl_->has_any_animation());
+ EXPECT_FALSE(player_child_impl_->animation_ticker()->has_any_animation());
EndTest();
}
}
diff --git a/chromium/cc/trees/layer_tree_host_unittest_checkerimaging.cc b/chromium/cc/trees/layer_tree_host_unittest_checkerimaging.cc
index f3f3ce2d940..3a96d3b3bad 100644
--- a/chromium/cc/trees/layer_tree_host_unittest_checkerimaging.cc
+++ b/chromium/cc/trees/layer_tree_host_unittest_checkerimaging.cc
@@ -112,6 +112,12 @@ class LayerTreeHostCheckerImagingTestMergeWithMainFrame
}
}
}
+
+ // Insetting of image is included in the update rect.
+ gfx::Rect expected_update_rect(-1, -1, 452, 452);
+ expected_update_rect.Union(gfx::Rect(600, 0, 50, 500));
+ EXPECT_EQ(sync_layer_impl->update_rect(), expected_update_rect);
+
EndTest();
} break;
default:
@@ -165,6 +171,9 @@ class LayerTreeHostCheckerImagingTestImplSideTree
}
}
}
+
+ // Insetting of image is included in the update rect.
+ EXPECT_EQ(sync_layer_impl->update_rect(), gfx::Rect(-1, -1, 452, 452));
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
diff --git a/chromium/cc/trees/layer_tree_host_unittest_context.cc b/chromium/cc/trees/layer_tree_host_unittest_context.cc
index c9c5315edc9..4aa3c7fe473 100644
--- a/chromium/cc/trees/layer_tree_host_unittest_context.cc
+++ b/chromium/cc/trees/layer_tree_host_unittest_context.cc
@@ -35,7 +35,7 @@
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/single_thread_proxy.h"
-#include "components/viz/common/quads/single_release_callback.h"
+#include "components/viz/common/resources/single_release_callback.h"
#include "components/viz/test/test_layer_tree_frame_sink.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "media/base/media.h"
@@ -883,7 +883,7 @@ class LayerTreeHostContextTestDontUseLostResources
CHECK(child_context_provider_->BindToCurrentThread());
shared_bitmap_manager_.reset(new TestSharedBitmapManager);
child_resource_provider_ =
- FakeResourceProvider::Create<LayerTreeResourceProvider>(
+ FakeResourceProvider::CreateLayerTreeResourceProvider(
child_context_provider_.get(), shared_bitmap_manager_.get());
}
diff --git a/chromium/cc/trees/layer_tree_host_unittest_copyrequest.cc b/chromium/cc/trees/layer_tree_host_unittest_copyrequest.cc
index 8c02666c0c9..0bc9295339b 100644
--- a/chromium/cc/trees/layer_tree_host_unittest_copyrequest.cc
+++ b/chromium/cc/trees/layer_tree_host_unittest_copyrequest.cc
@@ -9,14 +9,14 @@
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "cc/layers/effect_tree_layer_list_iterator.h"
-#include "cc/output/direct_renderer.h"
#include "cc/test/fake_content_layer_client.h"
#include "cc/test/fake_output_surface.h"
#include "cc/test/fake_picture_layer.h"
#include "cc/test/layer_tree_test.h"
#include "cc/trees/layer_tree_impl.h"
-#include "components/viz/common/quads/copy_output_request.h"
-#include "components/viz/common/quads/copy_output_result.h"
+#include "components/viz/common/frame_sinks/copy_output_request.h"
+#include "components/viz/common/frame_sinks/copy_output_result.h"
+#include "components/viz/service/display/direct_renderer.h"
#include "components/viz/test/test_layer_tree_frame_sink.h"
#include "gpu/GLES2/gl2extchromium.h"
@@ -62,7 +62,8 @@ class LayerTreeHostCopyRequestTestMultipleRequests
int frame = layer_tree_host()->SourceFrameNumber();
switch (frame) {
case 1:
- child->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest(
+ child->RequestCopyOfOutput(std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
base::BindOnce(&LayerTreeHostCopyRequestTestMultipleRequests::
CopyOutputCallback,
base::Unretained(this), 0)));
@@ -79,16 +80,19 @@ class LayerTreeHostCopyRequestTestMultipleRequests
EXPECT_EQ(1u, callbacks_.size());
EXPECT_EQ(gfx::Size(10, 10).ToString(), callbacks_[0].ToString());
- child->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest(
+ child->RequestCopyOfOutput(std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
base::BindOnce(&LayerTreeHostCopyRequestTestMultipleRequests::
CopyOutputCallback,
base::Unretained(this), 1)));
- root->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest(
+ root->RequestCopyOfOutput(std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
base::BindOnce(&LayerTreeHostCopyRequestTestMultipleRequests::
CopyOutputCallback,
base::Unretained(this), 2)));
grand_child->RequestCopyOfOutput(
- viz::CopyOutputRequest::CreateBitmapRequest(
+ std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
base::BindOnce(&LayerTreeHostCopyRequestTestMultipleRequests::
CopyOutputCallback,
base::Unretained(this), 3)));
@@ -121,21 +125,21 @@ class LayerTreeHostCopyRequestTestMultipleRequests
void CopyOutputCallback(size_t id,
std::unique_ptr<viz::CopyOutputResult> result) {
EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread());
- EXPECT_TRUE(result->HasBitmap());
- std::unique_ptr<SkBitmap> bitmap = result->TakeBitmap();
- EXPECT_EQ(result->size().ToString(),
- gfx::Size(bitmap->width(), bitmap->height()).ToString());
+ EXPECT_FALSE(result->IsEmpty());
+ const SkBitmap& bitmap = result->AsSkBitmap();
+ EXPECT_TRUE(bitmap.readyToDraw());
+ EXPECT_EQ(result->size(), gfx::Size(bitmap.width(), bitmap.height()));
callbacks_[id] = result->size();
}
void AfterTest() override { EXPECT_EQ(4u, callbacks_.size()); }
- std::unique_ptr<OutputSurface> CreateDisplayOutputSurfaceOnThread(
+ std::unique_ptr<viz::OutputSurface> CreateDisplayOutputSurfaceOnThread(
scoped_refptr<viz::ContextProvider> compositor_context_provider)
override {
if (!use_gl_renderer_) {
return FakeOutputSurface::CreateSoftware(
- base::WrapUnique(new SoftwareOutputDevice));
+ std::make_unique<viz::SoftwareOutputDevice>());
}
scoped_refptr<TestContextProvider> display_context_provider =
@@ -220,7 +224,8 @@ class LayerTreeHostCopyRequestCompletionCausesCommit
int frame = layer_tree_host()->SourceFrameNumber();
switch (frame) {
case 1:
- layer_->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest(
+ layer_->RequestCopyOfOutput(std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
base::BindOnce(&LayerTreeHostCopyRequestCompletionCausesCommit::
CopyOutputCallback)));
break;
@@ -277,12 +282,16 @@ class LayerTreeHostCopyRequestTestLayerDestroyed
int frame = layer_tree_host()->SourceFrameNumber();
switch (frame) {
case 1:
- main_destroyed_->RequestCopyOfOutput(
- viz::CopyOutputRequest::CreateBitmapRequest(base::BindOnce(
+ main_destroyed_->RequestCopyOfOutput(std::make_unique<
+ viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
+ base::BindOnce(
&LayerTreeHostCopyRequestTestLayerDestroyed::CopyOutputCallback,
base::Unretained(this))));
- impl_destroyed_->RequestCopyOfOutput(
- viz::CopyOutputRequest::CreateBitmapRequest(base::BindOnce(
+ impl_destroyed_->RequestCopyOfOutput(std::make_unique<
+ viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
+ base::BindOnce(
&LayerTreeHostCopyRequestTestLayerDestroyed::CopyOutputCallback,
base::Unretained(this))));
EXPECT_EQ(0, callback_count_);
@@ -368,8 +377,9 @@ class LayerTreeHostCopyRequestTestInHiddenSubtree
}
void AddCopyRequest(Layer* layer) {
- layer->RequestCopyOfOutput(
- viz::CopyOutputRequest::CreateBitmapRequest(base::BindOnce(
+ layer->RequestCopyOfOutput(std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
+ base::BindOnce(
&LayerTreeHostCopyRequestTestInHiddenSubtree::CopyOutputCallback,
base::Unretained(this))));
}
@@ -482,8 +492,9 @@ class LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest
void BeginTest() override {
PostSetNeedsCommitToMainThread();
- copy_layer_->RequestCopyOfOutput(
- viz::CopyOutputRequest::CreateBitmapRequest(base::BindOnce(
+ copy_layer_->RequestCopyOfOutput(std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
+ base::BindOnce(
&LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest::
CopyOutputCallback,
base::Unretained(this))));
@@ -497,7 +508,7 @@ class LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest
void DisplayWillDrawAndSwapOnThread(
bool will_draw_and_swap,
- const RenderPassList& render_passes) override {
+ const viz::RenderPassList& render_passes) override {
EXPECT_TRUE(will_draw_and_swap) << did_swap_;
if (did_swap_) {
// TODO(crbug.com/564832): Ignore the extra frame that occurs due to copy
@@ -513,7 +524,8 @@ class LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest
}
void DisplayDidDrawAndSwapOnThread() override {
- DirectRenderer* renderer = frame_sink_->display()->renderer_for_testing();
+ viz::DirectRenderer* renderer =
+ frame_sink_->display()->renderer_for_testing();
// |parent| owns a surface, but it was hidden and not part of the copy
// request so it should not allocate any resource.
@@ -537,8 +549,8 @@ class LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest
void AfterTest() override { EXPECT_TRUE(did_swap_); }
- RenderPassId parent_render_pass_id = 0;
- RenderPassId copy_layer_render_pass_id = 0;
+ viz::RenderPassId parent_render_pass_id = 0;
+ viz::RenderPassId copy_layer_render_pass_id = 0;
viz::TestLayerTreeFrameSink* frame_sink_ = nullptr;
bool did_swap_ = false;
FakeContentLayerClient client_;
@@ -576,8 +588,9 @@ class LayerTreeHostCopyRequestTestClippedOut
void BeginTest() override {
PostSetNeedsCommitToMainThread();
- copy_layer_->RequestCopyOfOutput(
- viz::CopyOutputRequest::CreateBitmapRequest(base::BindOnce(
+ copy_layer_->RequestCopyOfOutput(std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
+ base::BindOnce(
&LayerTreeHostCopyRequestTestClippedOut::CopyOutputCallback,
base::Unretained(this))));
}
@@ -632,9 +645,11 @@ class LayerTreeHostCopyRequestTestScaledLayer
PostSetNeedsCommitToMainThread();
std::unique_ptr<viz::CopyOutputRequest> request =
- viz::CopyOutputRequest::CreateBitmapRequest(base::BindOnce(
- &LayerTreeHostCopyRequestTestScaledLayer::CopyOutputCallback,
- base::Unretained(this)));
+ std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
+ base::BindOnce(
+ &LayerTreeHostCopyRequestTestScaledLayer::CopyOutputCallback,
+ base::Unretained(this)));
request->set_area(gfx::Rect(5, 5));
copy_layer_->RequestCopyOfOutput(std::move(request));
}
@@ -673,8 +688,9 @@ class LayerTreeHostTestAsyncTwoReadbacksWithoutDraw
}
void AddCopyRequest(Layer* layer) {
- layer->RequestCopyOfOutput(
- viz::CopyOutputRequest::CreateBitmapRequest(base::BindOnce(
+ layer->RequestCopyOfOutput(std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
+ base::BindOnce(
&LayerTreeHostTestAsyncTwoReadbacksWithoutDraw::CopyOutputCallback,
base::Unretained(this))));
}
@@ -742,7 +758,7 @@ SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestAsyncTwoReadbacksWithoutDraw);
class LayerTreeHostCopyRequestTestDeleteTexture
: public LayerTreeHostCopyRequestTest {
protected:
- std::unique_ptr<OutputSurface> CreateDisplayOutputSurfaceOnThread(
+ std::unique_ptr<viz::OutputSurface> CreateDisplayOutputSurfaceOnThread(
scoped_refptr<viz::ContextProvider> compositor_context_provider)
override {
display_context_provider_ = TestContextProvider::Create();
@@ -769,7 +785,8 @@ class LayerTreeHostCopyRequestTestDeleteTexture
std::unique_ptr<viz::CopyOutputResult> result) {
EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread());
EXPECT_EQ(gfx::Size(10, 10).ToString(), result->size().ToString());
- EXPECT_TRUE(result->HasTexture());
+ EXPECT_EQ(result->format(), viz::CopyOutputResult::Format::RGBA_TEXTURE);
+ EXPECT_NE(result->GetTextureMailbox(), nullptr);
// Save the result for later.
EXPECT_FALSE(result_);
@@ -780,7 +797,8 @@ class LayerTreeHostCopyRequestTestDeleteTexture
}
void InsertCopyRequest() {
- copy_layer_->RequestCopyOfOutput(viz::CopyOutputRequest::CreateRequest(
+ copy_layer_->RequestCopyOfOutput(std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_TEXTURE,
base::BindOnce(&LayerTreeHostCopyRequestTestDeleteTexture::
ReceiveCopyRequestOutputAndCommit,
base::Unretained(this))));
@@ -869,7 +887,7 @@ class LayerTreeHostCopyRequestTestCountTextures
settings->resource_settings.texture_id_allocation_chunk_size = 1;
}
- std::unique_ptr<OutputSurface> CreateDisplayOutputSurfaceOnThread(
+ std::unique_ptr<viz::OutputSurface> CreateDisplayOutputSurfaceOnThread(
scoped_refptr<viz::ContextProvider> compositor_context_provider)
override {
// These tests expect the LayerTreeHostImpl to share a context with
@@ -970,18 +988,22 @@ class LayerTreeHostCopyRequestTestCreatesTexture
protected:
void RequestCopy(Layer* layer) override {
// Request a normal texture copy. This should create a new texture.
- copy_layer_->RequestCopyOfOutput(
- viz::CopyOutputRequest::CreateRequest(base::BindOnce(
+ copy_layer_->RequestCopyOfOutput(std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_TEXTURE,
+ base::BindOnce(
&LayerTreeHostCopyRequestTestCreatesTexture::CopyOutputCallback,
base::Unretained(this))));
}
void CopyOutputCallback(std::unique_ptr<viz::CopyOutputResult> result) {
EXPECT_FALSE(result->IsEmpty());
- EXPECT_TRUE(result->HasTexture());
-
- viz::TextureMailbox mailbox;
- result->TakeTexture(&mailbox, &release_);
+ EXPECT_EQ(result->format(), viz::CopyOutputResult::Format::RGBA_TEXTURE);
+ viz::TextureMailbox texture_mailbox;
+ if (auto* mailbox = result->GetTextureMailbox()) {
+ texture_mailbox = *mailbox;
+ release_ = result->TakeTextureOwnership();
+ }
+ EXPECT_TRUE(texture_mailbox.IsTexture());
EXPECT_TRUE(release_);
}
@@ -1010,21 +1032,27 @@ class LayerTreeHostCopyRequestTestProvideTexture
void CopyOutputCallback(std::unique_ptr<viz::CopyOutputResult> result) {
EXPECT_FALSE(result->IsEmpty());
- EXPECT_TRUE(result->HasTexture());
-
- viz::TextureMailbox mailbox;
- std::unique_ptr<viz::SingleReleaseCallback> release;
- result->TakeTexture(&mailbox, &release);
- EXPECT_FALSE(release);
+ EXPECT_EQ(result->format(), viz::CopyOutputResult::Format::RGBA_TEXTURE);
+ viz::TextureMailbox texture_mailbox;
+ std::unique_ptr<viz::SingleReleaseCallback> release_callback;
+ if (auto* mailbox = result->GetTextureMailbox()) {
+ texture_mailbox = *mailbox;
+ release_callback = result->TakeTextureOwnership();
+ }
+ EXPECT_TRUE(texture_mailbox.IsTexture());
+ ASSERT_TRUE(release_callback);
+ release_callback->Run(gpu::SyncToken(), false);
}
void RequestCopy(Layer* layer) override {
// Request a copy to a provided texture. This should not create a new
// texture.
std::unique_ptr<viz::CopyOutputRequest> request =
- viz::CopyOutputRequest::CreateRequest(base::BindOnce(
- &LayerTreeHostCopyRequestTestProvideTexture::CopyOutputCallback,
- base::Unretained(this)));
+ std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_TEXTURE,
+ base::BindOnce(
+ &LayerTreeHostCopyRequestTestProvideTexture::CopyOutputCallback,
+ base::Unretained(this)));
gpu::gles2::GLES2Interface* gl = external_context_provider_->ContextGL();
gpu::Mailbox mailbox;
@@ -1096,7 +1124,8 @@ class LayerTreeHostCopyRequestTestDestroyBeforeCopy
// Put a copy request on the layer, but then don't allow any
// drawing to take place.
std::unique_ptr<viz::CopyOutputRequest> request =
- viz::CopyOutputRequest::CreateRequest(
+ std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_TEXTURE,
base::BindOnce(&LayerTreeHostCopyRequestTestDestroyBeforeCopy::
CopyOutputCallback,
base::Unretained(this)));
@@ -1174,7 +1203,8 @@ class LayerTreeHostCopyRequestTestShutdownBeforeCopy
// Put a copy request on the layer, but then don't allow any
// drawing to take place.
std::unique_ptr<viz::CopyOutputRequest> request =
- viz::CopyOutputRequest::CreateRequest(
+ std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_TEXTURE,
base::BindOnce(&LayerTreeHostCopyRequestTestShutdownBeforeCopy::
CopyOutputCallback,
base::Unretained(this)));
@@ -1233,8 +1263,9 @@ class LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest
void DidCommit() override {
// Send a copy request after the first commit.
if (layer_tree_host()->SourceFrameNumber() == 1) {
- child_->RequestCopyOfOutput(
- viz::CopyOutputRequest::CreateBitmapRequest(base::BindOnce(
+ child_->RequestCopyOfOutput(std::make_unique<viz::CopyOutputRequest>(
+ viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
+ base::BindOnce(
&LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest::
CopyOutputCallback,
base::Unretained(this))));
diff --git a/chromium/cc/trees/layer_tree_impl.cc b/chromium/cc/trees/layer_tree_impl.cc
index 70d89a01900..08000f77df9 100644
--- a/chromium/cc/trees/layer_tree_impl.cc
+++ b/chromium/cc/trees/layer_tree_impl.cc
@@ -29,11 +29,11 @@
#include "cc/layers/layer_list_iterator.h"
#include "cc/layers/render_surface_impl.h"
#include "cc/layers/scrollbar_layer_impl_base.h"
-#include "cc/output/layer_tree_frame_sink.h"
#include "cc/resources/ui_resource_request.h"
#include "cc/trees/clip_node.h"
#include "cc/trees/draw_property_utils.h"
#include "cc/trees/effect_node.h"
+#include "cc/trees/layer_tree_frame_sink.h"
#include "cc/trees/layer_tree_host_common.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/mutator_host.h"
@@ -77,7 +77,6 @@ LayerTreeImpl::LayerTreeImpl(
root_layer_for_testing_(nullptr),
hud_layer_(nullptr),
background_color_(0),
- has_transparent_background_(false),
last_scrolled_scroll_node_index_(ScrollTree::kInvalidNodeId),
page_scale_factor_(page_scale_factor),
min_page_scale_factor_(0),
@@ -453,7 +452,6 @@ void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
// LayerTreeHost::finishCommitOnImplThread().
target_tree->set_source_frame_number(source_frame_number());
target_tree->set_background_color(background_color());
- target_tree->set_has_transparent_background(has_transparent_background());
target_tree->set_have_scroll_event_handlers(have_scroll_event_handlers());
target_tree->set_event_listener_properties(
EventListenerClass::kTouchStartOrMove,
@@ -550,7 +548,7 @@ void LayerTreeImpl::AddToElementMap(LayerImpl* layer) {
if (!element_id)
return;
- TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("compositor-worker"),
+ TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("layer-element"),
"LayerTreeImpl::AddToElementMap", "element",
element_id.AsValue().release(), "layer_id", layer->id());
@@ -572,7 +570,7 @@ void LayerTreeImpl::RemoveFromElementMap(LayerImpl* layer) {
if (!layer->element_id())
return;
- TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("compositor-worker"),
+ TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("layer-element"),
"LayerTreeImpl::RemoveFromElementMap", "element",
layer->element_id().AsValue().release(), "layer_id",
layer->id());
@@ -1121,6 +1119,11 @@ bool LayerTreeImpl::UpdateDrawProperties() {
"layers_updated_count", layers_updated_count);
}
+ if (image_animation_controller()) {
+ image_animation_controller()->UpdateStateFromDrivers(
+ host_impl_->CurrentBeginFrameArgs().frame_time);
+ }
+
DCHECK(!needs_update_draw_properties_)
<< "CalcDrawProperties should not set_needs_update_draw_properties()";
return true;
@@ -1330,6 +1333,10 @@ ImageDecodeCache* LayerTreeImpl::image_decode_cache() const {
return host_impl_->image_decode_cache();
}
+ImageAnimationController* LayerTreeImpl::image_animation_controller() const {
+ return host_impl_->image_animation_controller();
+}
+
FrameRateCounter* LayerTreeImpl::frame_rate_counter() const {
return host_impl_->fps_counter();
}
@@ -1551,7 +1558,7 @@ void LayerTreeImpl::AppendSwapPromises(
new_swap_promises.clear();
}
-void LayerTreeImpl::FinishSwapPromises(CompositorFrameMetadata* metadata) {
+void LayerTreeImpl::FinishSwapPromises(viz::CompositorFrameMetadata* metadata) {
for (const auto& swap_promise : swap_promise_list_)
swap_promise->WillSwap(metadata);
for (const auto& swap_promise : pinned_swap_promise_list_)
@@ -2046,13 +2053,13 @@ static gfx::SelectionBound ComputeViewportSelectionBound(
}
void LayerTreeImpl::GetViewportSelection(
- Selection<gfx::SelectionBound>* selection) {
+ viz::Selection<gfx::SelectionBound>* selection) {
DCHECK(selection);
selection->start = ComputeViewportSelectionBound(
selection_.start,
selection_.start.layer_id ? LayerById(selection_.start.layer_id) : NULL,
- device_scale_factor());
+ device_scale_factor() * painted_device_scale_factor());
if (selection->start.type() == gfx::SelectionBound::CENTER ||
selection->start.type() == gfx::SelectionBound::EMPTY) {
selection->end = selection->start;
@@ -2060,7 +2067,7 @@ void LayerTreeImpl::GetViewportSelection(
selection->end = ComputeViewportSelectionBound(
selection_.end,
selection_.end.layer_id ? LayerById(selection_.end.layer_id) : NULL,
- device_scale_factor());
+ device_scale_factor() * painted_device_scale_factor());
}
}
diff --git a/chromium/cc/trees/layer_tree_impl.h b/chromium/cc/trees/layer_tree_impl.h
index 1be26cd874a..c7c25b1eee1 100644
--- a/chromium/cc/trees/layer_tree_impl.h
+++ b/chromium/cc/trees/layer_tree_impl.h
@@ -20,10 +20,10 @@
#include "cc/input/scroll_boundary_behavior.h"
#include "cc/layers/layer_impl.h"
#include "cc/layers/layer_list_iterator.h"
-#include "cc/output/swap_promise.h"
#include "cc/resources/ui_resource_client.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/property_tree.h"
+#include "cc/trees/swap_promise.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"
namespace base {
@@ -111,6 +111,7 @@ class CC_EXPORT LayerTreeImpl {
LayerTreeResourceProvider* resource_provider() const;
TileManager* tile_manager() const;
ImageDecodeCache* image_decode_cache() const;
+ ImageAnimationController* image_animation_controller() const;
FrameRateCounter* frame_rate_counter() const;
MemoryHistory* memory_history() const;
gfx::Size device_viewport_size() const;
@@ -167,6 +168,7 @@ class CC_EXPORT LayerTreeImpl {
// DCHECK(lifecycle().AllowsPropertyTreeAccess());
return &property_trees_;
}
+ const PropertyTrees* property_trees() const { return &property_trees_; }
void PushPropertyTreesTo(LayerTreeImpl* tree_impl);
void PushPropertiesTo(LayerTreeImpl* tree_impl);
@@ -257,13 +259,6 @@ class CC_EXPORT LayerTreeImpl {
SkColor background_color() const { return background_color_; }
void set_background_color(SkColor color) { background_color_ = color; }
- bool has_transparent_background() const {
- return has_transparent_background_;
- }
- void set_has_transparent_background(bool transparent) {
- has_transparent_background_ = transparent;
- }
-
void UpdatePropertyTreeAnimationFromMainThread();
void SetPageScaleOnActiveTree(float active_page_scale);
@@ -371,8 +366,7 @@ class CC_EXPORT LayerTreeImpl {
LayerImpl* LayerById(int id) const;
// TODO(jaydasika): this is deprecated. It is used by
- // animation/compositor-worker to look up layers to mutate, but in future, we
- // will update property trees.
+ // scrolling animation to look up layers to mutate.
LayerImpl* LayerByElementId(ElementId element_id) const;
void AddToElementMap(LayerImpl* layer);
void RemoveFromElementMap(LayerImpl* layer);
@@ -444,7 +438,7 @@ class CC_EXPORT LayerTreeImpl {
std::vector<std::unique_ptr<SwapPromise>> new_swap_promises);
void AppendSwapPromises(
std::vector<std::unique_ptr<SwapPromise>> new_swap_promises);
- void FinishSwapPromises(CompositorFrameMetadata* metadata);
+ void FinishSwapPromises(viz::CompositorFrameMetadata* metadata);
void ClearSwapPromises();
void BreakSwapPromises(SwapPromise::DidNotSwapReason reason);
@@ -479,7 +473,7 @@ class CC_EXPORT LayerTreeImpl {
// Compute the current selection handle location and visbility with respect to
// the viewport.
- void GetViewportSelection(Selection<gfx::SelectionBound>* selection);
+ void GetViewportSelection(viz::Selection<gfx::SelectionBound>* selection);
void set_browser_controls_shrink_blink_size(bool shrink);
bool browser_controls_shrink_blink_size() const {
@@ -576,7 +570,6 @@ class CC_EXPORT LayerTreeImpl {
HeadsUpDisplayLayerImpl* hud_layer_;
PropertyTrees property_trees_;
SkColor background_color_;
- bool has_transparent_background_;
int last_scrolled_scroll_node_index_;
diff --git a/chromium/cc/trees/layer_tree_impl_unittest.cc b/chromium/cc/trees/layer_tree_impl_unittest.cc
index b68556aea86..40c039d1c08 100644
--- a/chromium/cc/trees/layer_tree_impl_unittest.cc
+++ b/chromium/cc/trees/layer_tree_impl_unittest.cc
@@ -14,7 +14,6 @@
#include "cc/trees/draw_property_utils.h"
#include "cc/trees/layer_tree_host_common.h"
#include "cc/trees/layer_tree_host_impl.h"
-#include "cc/trees/mutable_properties.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -1875,7 +1874,7 @@ TEST_F(LayerTreeImplTest, SelectionBoundsForSingleLayer) {
input.end.edge_bottom = gfx::Point(50, 30);
input.end.layer_id = root->id();
- Selection<gfx::SelectionBound> output;
+ viz::Selection<gfx::SelectionBound> output;
// Empty input bounds should produce empty output bounds.
host_impl().active_tree()->GetViewportSelection(&output);
@@ -1956,7 +1955,7 @@ TEST_F(LayerTreeImplTest, SelectionBoundsForPartialOccludedLayers) {
host_impl().active_tree()->RegisterSelection(input);
// The left bound should be occluded by the clip layer.
- Selection<gfx::SelectionBound> output;
+ viz::Selection<gfx::SelectionBound> output;
host_impl().active_tree()->GetViewportSelection(&output);
EXPECT_EQ(input.start.type, output.start.type());
auto expected_output_start_top = gfx::PointF(input.start.edge_top);
@@ -1996,52 +1995,6 @@ TEST_F(LayerTreeImplTest, SelectionBoundsForPartialOccludedLayers) {
EXPECT_TRUE(output.start.visible());
}
-TEST_F(LayerTreeImplTest, NodesiesForProxies) {
- LayerImpl* root = root_layer();
- root->SetDrawsContent(true);
- root->SetBounds(gfx::Size(100, 100));
-
- uint32_t properties[] = {
- MutableProperty::kOpacity, MutableProperty::kScrollLeft,
- MutableProperty::kScrollTop, MutableProperty::kTransform,
- };
-
- for (size_t i = 0; i < arraysize(properties); ++i) {
- int sub_layer_id = i + 2;
- std::unique_ptr<LayerImpl> sub_layer =
- LayerImpl::Create(host_impl().active_tree(), sub_layer_id);
- sub_layer->SetBounds(gfx::Size(50, 50));
- sub_layer->SetDrawsContent(true);
- sub_layer->SetMutableProperties(properties[i]);
- root->test_properties()->AddChild(std::move(sub_layer));
- }
-
- host_impl().active_tree()->BuildPropertyTreesForTesting();
-
- for (size_t i = 0; i < arraysize(properties); ++i) {
- LayerImpl* layer = host_impl().active_tree()->LayerById(i + 2);
- switch (properties[i]) {
- case MutableProperty::kOpacity:
- DCHECK_EQ(root->transform_tree_index(), layer->transform_tree_index());
- DCHECK_NE(root->effect_tree_index(), layer->effect_tree_index());
- break;
- case MutableProperty::kScrollLeft:
- case MutableProperty::kScrollTop:
- case MutableProperty::kTransform:
- DCHECK_EQ(root->effect_tree_index(), layer->effect_tree_index());
- DCHECK_NE(root->transform_tree_index(), layer->transform_tree_index());
- for (size_t j = 0; j < arraysize(properties); ++j) {
- if (j == i)
- continue;
- LayerImpl* other = host_impl().active_tree()->LayerById(j + 2);
- DCHECK_NE(other->transform_tree_index(),
- layer->transform_tree_index());
- }
- break;
- }
- }
-}
-
TEST_F(LayerTreeImplTest, SelectionBoundsForScaledLayers) {
LayerImpl* root = root_layer();
root->SetDrawsContent(true);
@@ -2096,7 +2049,7 @@ TEST_F(LayerTreeImplTest, SelectionBoundsForScaledLayers) {
// The viewport bounds should be properly scaled by the page scale, but should
// remain in DIP coordinates.
- Selection<gfx::SelectionBound> output;
+ viz::Selection<gfx::SelectionBound> output;
host_impl().active_tree()->GetViewportSelection(&output);
EXPECT_EQ(input.start.type, output.start.type());
auto expected_output_start_top = gfx::PointF(input.start.edge_top);
@@ -2119,6 +2072,77 @@ TEST_F(LayerTreeImplTest, SelectionBoundsForScaledLayers) {
EXPECT_TRUE(output.end.visible());
}
+TEST_F(LayerTreeImplTest, SelectionBoundsForDSFEnabled) {
+ LayerImpl* root = root_layer();
+ root->SetDrawsContent(true);
+ root->SetBounds(gfx::Size(100, 100));
+
+ int root_layer_id = root->id();
+ int sub_layer_id = 2;
+
+ gfx::Vector2dF sub_layer_offset(10, 0);
+ {
+ std::unique_ptr<LayerImpl> sub_layer =
+ LayerImpl::Create(host_impl().active_tree(), sub_layer_id);
+ sub_layer->SetPosition(gfx::PointF() + sub_layer_offset);
+ sub_layer->SetBounds(gfx::Size(50, 50));
+ sub_layer->SetDrawsContent(true);
+ root->test_properties()->AddChild(std::move(sub_layer));
+ }
+
+ host_impl().active_tree()->BuildPropertyTreesForTesting();
+
+ float device_scale_factor = 3.f;
+ float painted_device_scale_factor = 5.f;
+
+ LayerTreeImpl::ViewportLayerIds viewport_ids;
+ viewport_ids.page_scale = root->id();
+ host_impl().active_tree()->SetViewportLayersFromIds(viewport_ids);
+ host_impl().active_tree()->SetDeviceScaleFactor(device_scale_factor);
+ host_impl().active_tree()->set_painted_device_scale_factor(
+ painted_device_scale_factor);
+
+ LayerSelection input;
+ input.start.type = gfx::SelectionBound::LEFT;
+ input.start.edge_top = gfx::Point(10, 10);
+ input.start.edge_bottom = gfx::Point(10, 30);
+ input.start.layer_id = root_layer_id;
+
+ input.end.type = gfx::SelectionBound::RIGHT;
+ input.end.edge_top = gfx::Point(0, 0);
+ input.end.edge_bottom = gfx::Point(0, 20);
+ input.end.layer_id = sub_layer_id;
+ host_impl().active_tree()->RegisterSelection(input);
+
+ // The viewport bounds should be properly scaled by the page scale, but should
+ // remain in DIP coordinates.
+ viz::Selection<gfx::SelectionBound> output;
+ host_impl().active_tree()->GetViewportSelection(&output);
+ EXPECT_EQ(input.start.type, output.start.type());
+ auto expected_output_start_top = gfx::PointF(input.start.edge_top);
+ auto expected_output_edge_bottom = gfx::PointF(input.start.edge_bottom);
+ expected_output_start_top.Scale(
+ 1.f / (device_scale_factor * painted_device_scale_factor));
+ expected_output_edge_bottom.Scale(
+ 1.f / (device_scale_factor * painted_device_scale_factor));
+ EXPECT_EQ(expected_output_start_top, output.start.edge_top());
+ EXPECT_EQ(expected_output_edge_bottom, output.start.edge_bottom());
+ EXPECT_TRUE(output.start.visible());
+ EXPECT_EQ(input.end.type, output.end.type());
+
+ auto expected_output_end_top = gfx::PointF(input.end.edge_top);
+ auto expected_output_end_bottom = gfx::PointF(input.end.edge_bottom);
+ expected_output_end_top.Offset(sub_layer_offset.x(), sub_layer_offset.y());
+ expected_output_end_bottom.Offset(sub_layer_offset.x(), sub_layer_offset.y());
+ expected_output_end_top.Scale(
+ 1.f / (device_scale_factor * painted_device_scale_factor));
+ expected_output_end_bottom.Scale(
+ 1.f / (device_scale_factor * painted_device_scale_factor));
+ EXPECT_EQ(expected_output_end_top, output.end.edge_top());
+ EXPECT_EQ(expected_output_end_bottom, output.end.edge_bottom());
+ EXPECT_TRUE(output.end.visible());
+}
+
TEST_F(LayerTreeImplTest, SelectionBoundsWithLargeTransforms) {
LayerImpl* root = root_layer();
root->SetBounds(gfx::Size(100, 100));
@@ -2163,7 +2187,7 @@ TEST_F(LayerTreeImplTest, SelectionBoundsWithLargeTransforms) {
host_impl().active_tree()->RegisterSelection(input);
- Selection<gfx::SelectionBound> output;
+ viz::Selection<gfx::SelectionBound> output;
host_impl().active_tree()->GetViewportSelection(&output);
// edge_bottom and edge_top aren't allowed to have NaNs, so the selection
@@ -2268,7 +2292,7 @@ class PersistentSwapPromise
~PersistentSwapPromise() override = default;
void DidActivate() override {}
- MOCK_METHOD1(WillSwap, void(CompositorFrameMetadata* metadata));
+ MOCK_METHOD1(WillSwap, void(viz::CompositorFrameMetadata* metadata));
MOCK_METHOD0(DidSwap, void());
DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override {
@@ -2287,7 +2311,7 @@ class NotPersistentSwapPromise
~NotPersistentSwapPromise() override = default;
void DidActivate() override {}
- void WillSwap(CompositorFrameMetadata* metadata) override {}
+ void WillSwap(viz::CompositorFrameMetadata* metadata) override {}
void DidSwap() override {}
DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override {
diff --git a/chromium/cc/trees/layer_tree_mutator.h b/chromium/cc/trees/layer_tree_mutator.h
index 84fbeb5531e..b0e1e116490 100644
--- a/chromium/cc/trees/layer_tree_mutator.h
+++ b/chromium/cc/trees/layer_tree_mutator.h
@@ -27,10 +27,6 @@ class CC_EXPORT LayerTreeMutator {
// Returns true if the mutator should be rescheduled.
virtual bool Mutate(base::TimeTicks now) = 0;
virtual void SetClient(LayerTreeMutatorClient* client) = 0;
-
- // Returns a callback which is responsible for applying layer tree mutations
- // to DOM elements.
- virtual base::Closure TakeMutations() = 0;
};
} // namespace cc
diff --git a/chromium/cc/trees/layer_tree_settings.cc b/chromium/cc/trees/layer_tree_settings.cc
index 7e9229940bf..0007e96f4cf 100644
--- a/chromium/cc/trees/layer_tree_settings.cc
+++ b/chromium/cc/trees/layer_tree_settings.cc
@@ -45,6 +45,7 @@ TileManagerSettings LayerTreeSettings::ToTileManagerSettings() const {
tile_manager_settings.use_partial_raster = use_partial_raster;
tile_manager_settings.enable_checker_imaging = enable_checker_imaging;
tile_manager_settings.min_image_bytes_to_checker = min_image_bytes_to_checker;
+ tile_manager_settings.enable_image_animations = enable_image_animations;
return tile_manager_settings;
}
diff --git a/chromium/cc/trees/layer_tree_settings.h b/chromium/cc/trees/layer_tree_settings.h
index 2378dabef39..fa6b63dd385 100644
--- a/chromium/cc/trees/layer_tree_settings.h
+++ b/chromium/cc/trees/layer_tree_settings.h
@@ -12,9 +12,9 @@
#include "base/time/time.h"
#include "cc/cc_export.h"
#include "cc/debug/layer_tree_debug_state.h"
-#include "cc/output/managed_memory_policy.h"
#include "cc/scheduler/scheduler_settings.h"
#include "cc/tiles/tile_manager_settings.h"
+#include "cc/trees/managed_memory_policy.h"
#include "components/viz/common/display/renderer_settings.h"
#include "components/viz/common/resources/resource_format.h"
#include "components/viz/common/resources/resource_settings.h"
@@ -92,8 +92,6 @@ class CC_EXPORT LayerTreeSettings {
int max_preraster_distance_in_screen_pixels = 1000;
viz::ResourceFormat preferred_tile_format;
- bool enable_color_correct_rasterization = false;
-
bool enable_mask_tiling = false;
// If set to true, the compositor may selectively defer image decodes to the
@@ -145,6 +143,12 @@ class CC_EXPORT LayerTreeSettings {
// Whether to use out of process raster. If true, whenever gpu raster
// would have been used, out of process gpu raster will be used instead.
bool enable_oop_rasterization = false;
+
+ // Whether images should be animated in the compositor.
+ bool enable_image_animations = false;
+
+ // Whether to use edge anti-aliasing for all layer types that supports it.
+ bool enable_edge_anti_aliasing = true;
};
} // namespace cc
diff --git a/chromium/cc/output/managed_memory_policy.cc b/chromium/cc/trees/managed_memory_policy.cc
index ed3f4a86509..3583c8b0d2e 100644
--- a/chromium/cc/output/managed_memory_policy.cc
+++ b/chromium/cc/trees/managed_memory_policy.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "cc/output/managed_memory_policy.h"
+#include "cc/trees/managed_memory_policy.h"
#include <stddef.h>
diff --git a/chromium/cc/output/managed_memory_policy.h b/chromium/cc/trees/managed_memory_policy.h
index 886bebdfac2..ceecc05f586 100644
--- a/chromium/cc/output/managed_memory_policy.h
+++ b/chromium/cc/trees/managed_memory_policy.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CC_OUTPUT_MANAGED_MEMORY_POLICY_H_
-#define CC_OUTPUT_MANAGED_MEMORY_POLICY_H_
+#ifndef CC_TREES_MANAGED_MEMORY_POLICY_H_
+#define CC_TREES_MANAGED_MEMORY_POLICY_H_
#include <stddef.h>
@@ -21,8 +21,7 @@ struct CC_EXPORT ManagedMemoryPolicy {
static const size_t kDefaultNumResourcesLimit;
explicit ManagedMemoryPolicy(size_t bytes_limit_when_visible);
- explicit ManagedMemoryPolicy(
- const gpu::MemoryAllocation& allocation);
+ explicit ManagedMemoryPolicy(const gpu::MemoryAllocation& allocation);
ManagedMemoryPolicy(
size_t bytes_limit_when_visible,
gpu::MemoryAllocation::PriorityCutoff priority_cutoff_when_visible,
@@ -40,4 +39,4 @@ struct CC_EXPORT ManagedMemoryPolicy {
} // namespace cc
-#endif // CC_OUTPUT_MANAGED_MEMORY_POLICY_H_
+#endif // CC_TREES_MANAGED_MEMORY_POLICY_H_
diff --git a/chromium/cc/trees/mutable_properties.h b/chromium/cc/trees/mutable_properties.h
deleted file mode 100644
index ef68c5ad274..00000000000
--- a/chromium/cc/trees/mutable_properties.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_TREES_MUTABLE_PROPERTIES_H_
-#define CC_TREES_MUTABLE_PROPERTIES_H_
-
-#include <stdint.h>
-
-namespace cc {
-
-struct MutableProperty {
- enum : uint32_t { kNone = 0 };
- enum : uint32_t { kOpacity = 1 << 0 };
- enum : uint32_t { kScrollLeft = 1 << 1 };
- enum : uint32_t { kScrollTop = 1 << 2 };
- enum : uint32_t { kTransform = 1 << 3 };
- enum : uint32_t { kTransformRelated = kTransform | kScrollLeft | kScrollTop };
-
- enum : int { kNumProperties = 4 };
-};
-
-} // namespace cc
-
-#endif // CC_TREES_MUTABLE_PROPERTIES_H_
diff --git a/chromium/cc/trees/mutator_host.h b/chromium/cc/trees/mutator_host.h
index f619819ecdf..992c64125f9 100644
--- a/chromium/cc/trees/mutator_host.h
+++ b/chromium/cc/trees/mutator_host.h
@@ -64,17 +64,6 @@ class MutatorHost {
virtual bool UpdateAnimationState(bool start_ready_animations,
MutatorEvents* events) = 0;
- // Returns a callback which is responsible for applying layer tree mutations
- // to DOM elements. The callback are transfered to main thread when we begin
- // main frame and should only be invoked on the main thread.
- //
- // TODO(majidvp): http://crbug.com/756539 Eliminate this. Once we implement
- // syncing animation local times from animation worklet to cc then we should
- // not directly send mutations to main thread and eliminate of this method.
- // Instead the animation local times should be send to main thread via
- // existing cc->main plumbing for animations which is |SetAnimationEvents|.
- virtual base::Closure TakeMutations() = 0;
-
virtual std::unique_ptr<MutatorEvents> CreateEvents() = 0;
virtual void SetAnimationEvents(std::unique_ptr<MutatorEvents> events) = 0;
@@ -103,13 +92,6 @@ class MutatorHost {
ElementId element_id,
TargetProperty::Type property) const = 0;
- virtual bool HasTransformAnimationThatInflatesBounds(
- ElementId element_id) const = 0;
-
- virtual bool TransformAnimationBoundsForBox(ElementId element_id,
- const gfx::BoxF& box,
- gfx::BoxF* bounds) const = 0;
-
virtual bool HasOnlyTranslationTransforms(
ElementId element_id,
ElementListType list_type) const = 0;
diff --git a/chromium/cc/trees/occlusion_tracker.cc b/chromium/cc/trees/occlusion_tracker.cc
index 2d20af4e03e..9cf7f167f2d 100644
--- a/chromium/cc/trees/occlusion_tracker.cc
+++ b/chromium/cc/trees/occlusion_tracker.cc
@@ -136,7 +136,7 @@ void OcclusionTracker::EnterRenderTarget(
const RenderSurfaceImpl* new_occlusion_immune_ancestor =
new_target_surface->nearest_occlusion_immune_ancestor();
- stack_.push_back(StackObject(new_target_surface));
+ stack_.emplace_back(new_target_surface);
// We copy the screen occlusion into the new RenderSurfaceImpl subtree, but we
// never copy in the occlusion from inside the target, since we are looking
@@ -198,6 +198,7 @@ void OcclusionTracker::FinishedRenderTarget(
// If the occlusion within the surface can not be applied to things outside of
// the surface's subtree, then clear the occlusion here so it won't be used.
if (finished_target_surface->HasMask() ||
+ finished_target_surface->HasMaskingContributingSurface() ||
finished_target_surface->draw_opacity() < 1 ||
!finished_target_surface->UsesDefaultBlendMode() ||
target_is_only_for_copy_request_or_force_render_surface ||
@@ -215,25 +216,20 @@ static void ReduceOcclusionBelowSurface(
if (surface_rect.IsEmpty())
return;
- gfx::Rect affected_area_in_target =
+ gfx::Rect target_rect =
MathUtil::MapEnclosingClippedRect(surface_transform, surface_rect);
if (contributing_surface->is_clipped()) {
- affected_area_in_target.Intersect(contributing_surface->clip_rect());
+ target_rect.Intersect(contributing_surface->clip_rect());
}
- if (affected_area_in_target.IsEmpty())
+ if (target_rect.IsEmpty())
return;
- // The filter's bounds for asymmetric filters (ex: drop shadow) are
- // relative to the target surface, which moves the pixels from outside of the
- // clip to the filtered surface. As a result, |affected_area| needs to expand.
- // Since we are concerned with the target surface, we need to swap the outsets
- // before applying them to the filtered surface bounds.
- int outset_top, outset_right, outset_bottom, outset_left;
- contributing_surface->BackgroundFilters().GetOutsets(
- &outset_bottom, &outset_left, &outset_top, &outset_right);
-
- affected_area_in_target.Inset(-outset_left, -outset_top, -outset_right,
- -outset_bottom);
+ gfx::Rect affected_area_in_target =
+ contributing_surface->BackgroundFilters().MapRectReverse(target_rect,
+ SkMatrix::I());
+ // Unite target_rect because we only care about positive outsets.
+ affected_area_in_target.Union(target_rect);
+
SimpleEnclosedRegion affected_occlusion = *occlusion_from_inside_target;
affected_occlusion.Intersect(affected_area_in_target);
@@ -246,15 +242,20 @@ static void ReduceOcclusionBelowSurface(
// The left outset of the filters moves pixels on the right side of
// the occlusion_rect into it, shrinking its right edge.
int shrink_left =
- occlusion_rect.x() == affected_area_in_target.x() ? 0 : outset_right;
+ occlusion_rect.x() == affected_area_in_target.x()
+ ? 0
+ : affected_area_in_target.right() - target_rect.right();
int shrink_top =
- occlusion_rect.y() == affected_area_in_target.y() ? 0 : outset_bottom;
- int shrink_right =
- occlusion_rect.right() == affected_area_in_target.right() ?
- 0 : outset_left;
+ occlusion_rect.y() == affected_area_in_target.y()
+ ? 0
+ : affected_area_in_target.bottom() - target_rect.bottom();
+ int shrink_right = occlusion_rect.right() == affected_area_in_target.right()
+ ? 0
+ : target_rect.x() - affected_area_in_target.x();
int shrink_bottom =
- occlusion_rect.bottom() == affected_area_in_target.bottom() ?
- 0 : outset_top;
+ occlusion_rect.bottom() == affected_area_in_target.bottom()
+ ? 0
+ : target_rect.y() - affected_area_in_target.y();
occlusion_rect.Inset(shrink_left, shrink_top, shrink_right, shrink_bottom);
diff --git a/chromium/cc/trees/occlusion_tracker_unittest.cc b/chromium/cc/trees/occlusion_tracker_unittest.cc
index c7c9ff6e6d8..7230a52810b 100644
--- a/chromium/cc/trees/occlusion_tracker_unittest.cc
+++ b/chromium/cc/trees/occlusion_tracker_unittest.cc
@@ -22,8 +22,8 @@
#include "cc/test/test_task_graph_runner.h"
#include "cc/trees/layer_tree_host_common.h"
#include "cc/trees/single_thread_proxy.h"
-#include "components/viz/common/quads/copy_output_request.h"
-#include "components/viz/common/quads/copy_output_result.h"
+#include "components/viz/common/frame_sinks/copy_output_request.h"
+#include "components/viz/common/frame_sinks/copy_output_result.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/transform.h"
@@ -195,19 +195,13 @@ class OcclusionTrackerTest : public testing::Test {
layer_iterator_.reset();
}
- void CopyOutputCallback(std::unique_ptr<viz::CopyOutputResult> result) {}
-
void AddCopyRequest(Layer* layer) {
- layer->RequestCopyOfOutput(viz::CopyOutputRequest::CreateBitmapRequest(
- base::BindOnce(&OcclusionTrackerTest::CopyOutputCallback,
- base::Unretained(this))));
+ layer->RequestCopyOfOutput(viz::CopyOutputRequest::CreateStubForTesting());
}
void AddCopyRequest(LayerImpl* layer) {
layer->test_properties()->copy_requests.push_back(
- viz::CopyOutputRequest::CreateBitmapRequest(
- base::BindOnce(&OcclusionTrackerTest::CopyOutputCallback,
- base::Unretained(this))));
+ viz::CopyOutputRequest::CreateStubForTesting());
}
void CalcDrawEtc(TestContentLayerImpl* root) {
diff --git a/chromium/cc/trees/property_tree.cc b/chromium/cc/trees/property_tree.cc
index d3e139f758c..b6a8513f093 100644
--- a/chromium/cc/trees/property_tree.cc
+++ b/chromium/cc/trees/property_tree.cc
@@ -19,7 +19,7 @@
#include "cc/trees/property_tree.h"
#include "cc/trees/scroll_node.h"
#include "cc/trees/transform_node.h"
-#include "components/viz/common/quads/copy_output_request.h"
+#include "components/viz/common/frame_sinks/copy_output_request.h"
#include "ui/gfx/geometry/vector2d_conversions.h"
namespace cc {
@@ -812,6 +812,15 @@ void EffectTree::UpdateBackfaceVisibility(EffectNode* node,
.is_showing_backface;
}
+void EffectTree::UpdateHasMaskingChild(EffectNode* node,
+ EffectNode* parent_node) {
+ // Reset to false when a node is first met. We'll set the bit later
+ // when we actually encounter a masking child.
+ node->has_masking_child = false;
+ if (node->blend_mode == SkBlendMode::kDstIn)
+ parent_node->has_masking_child = true;
+}
+
void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) {
if (!effect_node->has_render_surface) {
effect_node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f);
@@ -886,6 +895,7 @@ void EffectTree::UpdateEffects(int id) {
UpdateIsDrawn(node, parent_node);
UpdateEffectChanged(node, parent_node);
UpdateBackfaceVisibility(node, parent_node);
+ UpdateHasMaskingChild(node, parent_node);
UpdateSurfaceContentsScale(node);
}
@@ -1534,11 +1544,9 @@ void ScrollTree::DistributeScroll(ScrollNode* scroll_node,
return;
scroll_state->DistributeToScrollChainDescendant();
- // If the scroll doesn't propagate, and we're currently scrolling
- // a node other than this one, prevent the scroll from
- // propagating to this node.
- if (!scroll_state->should_propagate() &&
- scroll_state->delta_consumed_for_scroll_sequence() &&
+ // If we're currently scrolling a node other than this one, prevent the scroll
+ // from propagating to this node.
+ if (scroll_state->delta_consumed_for_scroll_sequence() &&
scroll_state->current_native_scrolling_node()->id != scroll_node->id) {
return;
}
diff --git a/chromium/cc/trees/property_tree.h b/chromium/cc/trees/property_tree.h
index 22ac11c4d9c..d89b0d65d7a 100644
--- a/chromium/cc/trees/property_tree.h
+++ b/chromium/cc/trees/property_tree.h
@@ -368,6 +368,7 @@ class CC_EXPORT EffectTree final : public PropertyTree<EffectNode> {
void UpdateOpacities(EffectNode* node, EffectNode* parent_node);
void UpdateIsDrawn(EffectNode* node, EffectNode* parent_node);
void UpdateBackfaceVisibility(EffectNode* node, EffectNode* parent_node);
+ void UpdateHasMaskingChild(EffectNode* node, EffectNode* parent_node);
// Stores copy requests, keyed by node id.
std::unordered_multimap<int, std::unique_ptr<viz::CopyOutputRequest>>
diff --git a/chromium/cc/trees/property_tree_builder.cc b/chromium/cc/trees/property_tree_builder.cc
index 089eaa45109..497ece19434 100644
--- a/chromium/cc/trees/property_tree_builder.cc
+++ b/chromium/cc/trees/property_tree_builder.cc
@@ -18,11 +18,10 @@
#include "cc/trees/effect_node.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/layer_tree_settings.h"
-#include "cc/trees/mutable_properties.h"
#include "cc/trees/mutator_host.h"
#include "cc/trees/scroll_node.h"
#include "cc/trees/transform_node.h"
-#include "components/viz/common/quads/copy_output_request.h"
+#include "components/viz/common/frame_sinks/copy_output_request.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/vector2d_conversions.h"
@@ -343,8 +342,7 @@ void PropertyTreeBuilderContext<LayerType>::AddClipNodeIfNeeded(
} else {
DCHECK(Filters(layer).HasFilterThatMovesPixels());
node.clip_type = ClipNode::ClipType::EXPANDS_CLIP;
- node.clip_expander =
- std::make_unique<ClipExpander>(layer->effect_tree_index());
+ node.clip_expander = ClipExpander(layer->effect_tree_index());
}
data_for_children->clip_tree_parent = clip_tree_.Insert(node, parent_id);
}
@@ -411,9 +409,6 @@ bool PropertyTreeBuilderContext<LayerType>::AddTransformNodeIfNeeded(
const bool has_any_transform_animation =
HasAnyAnimationTargetingProperty(layer, TargetProperty::TRANSFORM);
- const bool has_proxied_transform_related_property =
- !!(layer->mutable_properties() & MutableProperty::kTransformRelated);
-
const bool has_surface = created_render_surface;
const bool is_at_boundary_of_3d_rendering_context =
@@ -423,8 +418,7 @@ bool PropertyTreeBuilderContext<LayerType>::AddTransformNodeIfNeeded(
bool requires_node = is_root || is_snapped || has_significant_transform ||
has_any_transform_animation || has_surface || is_fixed ||
is_page_scale_layer || is_overscroll_elasticity_layer ||
- has_proxied_transform_related_property || is_sticky ||
- is_at_boundary_of_3d_rendering_context;
+ is_sticky || is_at_boundary_of_3d_rendering_context;
int parent_index = TransformTree::kRootNodeId;
int source_index = TransformTree::kRootNodeId;
@@ -626,6 +620,14 @@ static inline bool DoubleSided(LayerImpl* layer) {
return layer->test_properties()->double_sided;
}
+static inline bool TrilinearFiltering(Layer* layer) {
+ return layer->trilinear_filtering();
+}
+
+static inline bool TrilinearFiltering(LayerImpl* layer) {
+ return layer->test_properties()->trilinear_filtering;
+}
+
static inline bool CacheRenderSurface(Layer* layer) {
return layer->cache_render_surface();
}
@@ -761,6 +763,11 @@ bool ShouldCreateRenderSurface(LayerType* layer,
return true;
}
+ // If the layer uses trilinear filtering.
+ if (TrilinearFiltering(layer)) {
+ return true;
+ }
+
// If the layer uses a CSS filter.
if (!Filters(layer).IsEmpty() || !BackgroundFilters(layer).IsEmpty()) {
return true;
@@ -786,8 +793,8 @@ bool ShouldCreateRenderSurface(LayerType* layer,
// If the layer has blending.
// TODO(rosca): this is temporary, until blending is implemented for other
- // types of quads than RenderPassDrawQuad. Layers having descendants that draw
- // content will still create a separate rendering surface.
+ // types of quads than viz::RenderPassDrawQuad. Layers having descendants that
+ // draw content will still create a separate rendering surface.
if (BlendMode(layer) != SkBlendMode::kSrcOver) {
TRACE_EVENT_INSTANT0(
"cc", "PropertyTreeBuilder::ShouldCreateRenderSurface blending",
@@ -908,8 +915,6 @@ bool PropertyTreeBuilderContext<LayerType>::AddEffectNodeIfNeeded(
HasPotentialOpacityAnimation(layer);
const bool has_potential_filter_animation =
HasPotentiallyRunningFilterAnimation(layer);
- const bool has_proxied_opacity =
- !!(layer->mutable_properties() & MutableProperty::kOpacity);
data_for_children->animation_axis_aligned_since_render_target &=
AnimationsPreserveAxisAlignment(layer);
@@ -928,10 +933,9 @@ bool PropertyTreeBuilderContext<LayerType>::AddEffectNodeIfNeeded(
bool has_non_axis_aligned_clip =
not_axis_aligned_since_last_clip && LayerClipsSubtree(layer);
- bool requires_node = is_root || has_transparency ||
- has_potential_opacity_animation || has_proxied_opacity ||
- has_non_axis_aligned_clip ||
- should_create_render_surface;
+ bool requires_node =
+ is_root || has_transparency || has_potential_opacity_animation ||
+ has_non_axis_aligned_clip || should_create_render_surface;
int parent_id = data_from_ancestor.effect_tree_parent;
@@ -954,6 +958,7 @@ bool PropertyTreeBuilderContext<LayerType>::AddEffectNodeIfNeeded(
node->filters = Filters(layer);
node->background_filters = BackgroundFilters(layer);
node->filters_origin = FiltersOrigin(layer);
+ node->trilinear_filtering = TrilinearFiltering(layer);
node->has_potential_opacity_animation = has_potential_opacity_animation;
node->has_potential_filter_animation = has_potential_filter_animation;
node->double_sided = DoubleSided(layer);
diff --git a/chromium/cc/trees/proxy_common.h b/chromium/cc/trees/proxy_common.h
index 200b8eabc0d..3d82f01b765 100644
--- a/chromium/cc/trees/proxy_common.h
+++ b/chromium/cc/trees/proxy_common.h
@@ -22,7 +22,6 @@ struct CC_EXPORT BeginMainFrameAndCommitState {
unsigned int begin_frame_id = 0;
viz::BeginFrameArgs begin_frame_args;
- std::unique_ptr<BeginFrameCallbackList> begin_frame_callbacks;
std::unique_ptr<ScrollAndScaleSet> scroll_info;
size_t memory_allocation_limit_bytes = 0;
bool evicted_ui_resources = false;
diff --git a/chromium/cc/trees/proxy_impl.cc b/chromium/cc/trees/proxy_impl.cc
index 089825bc4ba..508ad019c7e 100644
--- a/chromium/cc/trees/proxy_impl.cc
+++ b/chromium/cc/trees/proxy_impl.cc
@@ -18,8 +18,8 @@
#include "cc/base/devtools_instrumentation.h"
#include "cc/benchmarks/benchmark_instrumentation.h"
#include "cc/input/browser_controls_offset_manager.h"
-#include "cc/output/layer_tree_frame_sink.h"
#include "cc/scheduler/compositor_timing_history.h"
+#include "cc/trees/layer_tree_frame_sink.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/mutator_host.h"
@@ -110,7 +110,7 @@ ProxyImpl::~ProxyImpl() {
void ProxyImpl::InitializeMutatorOnImpl(
std::unique_ptr<LayerTreeMutator> mutator) {
- TRACE_EVENT0("cc,compositor-worker", "ProxyImpl::InitializeMutatorOnImpl");
+ TRACE_EVENT0("cc", "ProxyImpl::InitializeMutatorOnImpl");
DCHECK(IsImplThread());
host_impl_->SetLayerTreeMutator(std::move(mutator));
}
@@ -506,8 +506,6 @@ void ProxyImpl::ScheduledActionSendBeginMainFrame(
new BeginMainFrameAndCommitState);
begin_main_frame_state->begin_frame_id = begin_frame_id;
begin_main_frame_state->begin_frame_args = args;
- begin_main_frame_state->begin_frame_callbacks =
- host_impl_->ProcessLayerTreeMutations();
begin_main_frame_state->scroll_info = host_impl_->ProcessScrollDeltas();
begin_main_frame_state->evicted_ui_resources =
host_impl_->EvictedUIResourcesExist();
diff --git a/chromium/cc/trees/proxy_main.cc b/chromium/cc/trees/proxy_main.cc
index 875e8b3c460..c0e8699e511 100644
--- a/chromium/cc/trees/proxy_main.cc
+++ b/chromium/cc/trees/proxy_main.cc
@@ -13,14 +13,13 @@
#include "cc/base/completion_event.h"
#include "cc/base/devtools_instrumentation.h"
#include "cc/benchmarks/benchmark_instrumentation.h"
-#include "cc/output/layer_tree_frame_sink.h"
-#include "cc/output/swap_promise.h"
#include "cc/resources/ui_resource_manager.h"
-#include "cc/trees/blocking_task_runner.h"
+#include "cc/trees/layer_tree_frame_sink.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/mutator_host.h"
#include "cc/trees/proxy_impl.h"
#include "cc/trees/scoped_abort_remaining_swap_promises.h"
+#include "cc/trees/swap_promise.h"
namespace cc {
@@ -172,25 +171,31 @@ void ProxyMain::BeginMainFrame(
current_pipeline_stage_ = ANIMATE_PIPELINE_STAGE;
+ // Synchronizes scroll offsets and page scale deltas (for pinch zoom) from the
+ // compositor thread thread to the main thread for both cc and and its
+ // client (e.g. Blink).
layer_tree_host_->ApplyScrollAndScale(
begin_main_frame_state->scroll_info.get());
- if (begin_main_frame_state->begin_frame_callbacks) {
- for (auto& callback : *begin_main_frame_state->begin_frame_callbacks)
- callback.Run();
- }
-
layer_tree_host_->WillBeginMainFrame();
+ // See LayerTreeHostClient::BeginMainFrame for more documentation on
+ // what this does.
layer_tree_host_->BeginMainFrame(begin_main_frame_state->begin_frame_args);
+
+ // Updates cc animations on the main-thread. This appears to be entirely
+ // duplicated by work done in LayerTreeHost::BeginMainFrame. crbug.com/762717.
layer_tree_host_->AnimateLayers(
begin_main_frame_state->begin_frame_args.frame_time);
- // Recreate all UI resources if there were evicted UI resources when the impl
+ // Recreates all UI resources if the compositor thread evicted UI resources
+ // because it became invisible or there was a lost context when the compositor
// thread initiated the commit.
if (begin_main_frame_state->evicted_ui_resources)
layer_tree_host_->GetUIResourceManager()->RecreateUIResources();
+ // See LayerTreeHostClient::MainFrameUpdate for more documentation on
+ // what this does.
layer_tree_host_->RequestMainFrameUpdate();
// At this point the main frame may have deferred commits to avoid committing
@@ -219,6 +224,15 @@ void ProxyMain::BeginMainFrame(
current_pipeline_stage_ = UPDATE_LAYERS_PIPELINE_STAGE;
bool should_update_layers =
final_pipeline_stage_ >= UPDATE_LAYERS_PIPELINE_STAGE;
+
+ // Among other things, UpdateLayers:
+ // -Updates property trees in cc.
+ // -Updates state for and "paints" display lists for cc layers by asking
+ // cc's client to do so.
+ // If the layer painting is backed by Blink, Blink generates the display
+ // list in advance, and "painting" amounts to copying the Blink display list
+ // to corresponding cc display list. An exception is for painted scrollbars,
+ // which paint eagerly during layer update.
bool updated = should_update_layers && layer_tree_host_->UpdateLayers();
// If updating the layers resulted in a content update, we need a commit.
@@ -259,12 +273,6 @@ void ProxyMain::BeginMainFrame(
DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
- // This CapturePostTasks should be destroyed before CommitComplete() is
- // called since that goes out to the embedder, and we want the embedder
- // to receive its callbacks before that.
- BlockingTaskRunner::CapturePostTasks blocked(
- task_runner_provider_->blocking_main_thread_task_runner());
-
bool hold_commit_for_activation = commit_waits_for_activation_;
commit_waits_for_activation_ = false;
CompletionEvent completion;
@@ -449,7 +457,7 @@ void ProxyMain::Stop() {
}
void ProxyMain::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) {
- TRACE_EVENT0("compositor-worker", "ThreadProxy::SetMutator");
+ TRACE_EVENT0("cc", "ThreadProxy::SetMutator");
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&ProxyImpl::InitializeMutatorOnImpl,
base::Unretained(proxy_impl_.get()),
diff --git a/chromium/cc/trees/scoped_abort_remaining_swap_promises.h b/chromium/cc/trees/scoped_abort_remaining_swap_promises.h
index ec6c9e4bf7a..b6c119705f0 100644
--- a/chromium/cc/trees/scoped_abort_remaining_swap_promises.h
+++ b/chromium/cc/trees/scoped_abort_remaining_swap_promises.h
@@ -6,7 +6,7 @@
#define CC_TREES_SCOPED_ABORT_REMAINING_SWAP_PROMISES_H_
#include "base/macros.h"
-#include "cc/output/swap_promise.h"
+#include "cc/trees/swap_promise.h"
#include "cc/trees/swap_promise_manager.h"
namespace cc {
diff --git a/chromium/cc/trees/single_thread_proxy.cc b/chromium/cc/trees/single_thread_proxy.cc
index f608e7c84ff..b9c041374fd 100644
--- a/chromium/cc/trees/single_thread_proxy.cc
+++ b/chromium/cc/trees/single_thread_proxy.cc
@@ -6,16 +6,14 @@
#include "base/auto_reset.h"
#include "base/memory/ptr_util.h"
-#include "base/profiler/scoped_tracker.h"
#include "base/trace_event/trace_event.h"
#include "cc/base/devtools_instrumentation.h"
#include "cc/benchmarks/benchmark_instrumentation.h"
-#include "cc/output/layer_tree_frame_sink.h"
-#include "cc/quads/draw_quad.h"
#include "cc/resources/ui_resource_manager.h"
#include "cc/scheduler/commit_earlyout_reason.h"
#include "cc/scheduler/compositor_timing_history.h"
#include "cc/scheduler/scheduler.h"
+#include "cc/trees/layer_tree_frame_sink.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_host_common.h"
#include "cc/trees/layer_tree_host_single_thread_client.h"
@@ -190,12 +188,6 @@ void SingleThreadProxy::DoCommit() {
DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
DebugScopedSetImplThread impl(task_runner_provider_);
- // This CapturePostTasks should be destroyed before CommitComplete() is
- // called since that goes out to the embedder, and we want the embedder
- // to receive its callbacks before that.
- commit_blocking_task_runner_.reset(new BlockingTaskRunner::CapturePostTasks(
- task_runner_provider_->blocking_main_thread_task_runner()));
-
host_impl_->ReadyToCommit();
host_impl_->BeginCommit();
@@ -233,10 +225,8 @@ void SingleThreadProxy::CommitComplete() {
// SetNextCommitWaitsForActivation calls.
DCHECK(!host_impl_->pending_tree())
<< "Activation is expected to have synchronously occurred by now.";
- DCHECK(commit_blocking_task_runner_);
DebugScopedSetMainThread main(task_runner_provider_);
- commit_blocking_task_runner_.reset();
layer_tree_host_->CommitComplete();
layer_tree_host_->DidBeginMainFrame();
@@ -385,9 +375,6 @@ bool SingleThreadProxy::IsInsideDraw() {
}
void SingleThreadProxy::DidActivateSyncTree() {
- // Synchronously call to CommitComplete. Resetting
- // |commit_blocking_task_runner| would make sure all tasks posted during
- // commit/activation before CommitComplete.
CommitComplete();
}
@@ -583,8 +570,6 @@ DrawResult SingleThreadProxy::DoComposite(LayerTreeHostImpl::FrameData* frame) {
// there as the main thread is not blocked, so any posted tasks inside
// the swap buffers will execute first.
DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
- BlockingTaskRunner::CapturePostTasks blocked(
- task_runner_provider_->blocking_main_thread_task_runner());
draw_result = host_impl_->PrepareToDraw(frame);
draw_frame = draw_result == DRAW_SUCCESS;
@@ -802,8 +787,6 @@ void SingleThreadProxy::ScheduledActionPerformImplSideInvalidation() {
DCHECK(scheduler_on_impl_thread_);
DebugScopedSetImplThread impl(task_runner_provider_);
- commit_blocking_task_runner_.reset(new BlockingTaskRunner::CapturePostTasks(
- task_runner_provider_->blocking_main_thread_task_runner()));
host_impl_->InvalidateContentOnImplSide();
// Invalidations go directly to the active tree, so we synchronously call
@@ -814,13 +797,6 @@ void SingleThreadProxy::ScheduledActionPerformImplSideInvalidation() {
NotifyReadyToActivate();
}
-void SingleThreadProxy::UpdateBrowserControlsState(
- BrowserControlsState constraints,
- BrowserControlsState current,
- bool animate) {
- NOTREACHED() << "Browser Controls are used only in threaded mode";
-}
-
void SingleThreadProxy::DidFinishImplFrame() {
host_impl_->DidFinishImplFrame();
#if DCHECK_IS_ON()
diff --git a/chromium/cc/trees/single_thread_proxy.h b/chromium/cc/trees/single_thread_proxy.h
index 5843ed24bd0..152cc72c092 100644
--- a/chromium/cc/trees/single_thread_proxy.h
+++ b/chromium/cc/trees/single_thread_proxy.h
@@ -11,7 +11,6 @@
#include "base/macros.h"
#include "base/time/time.h"
#include "cc/scheduler/scheduler.h"
-#include "cc/trees/blocking_task_runner.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/proxy.h"
#include "cc/trees/task_runner_provider.h"
@@ -58,9 +57,12 @@ class CC_EXPORT SingleThreadProxy : public Proxy,
void SetMutator(std::unique_ptr<LayerTreeMutator> mutator) override;
bool SupportsImplScrolling() const override;
bool MainFrameWillHappenForTesting() override;
+
+ // Blink layout tests might call into this even though an unthreaded CC
+ // doesn't have BrowserControls itself.
void UpdateBrowserControlsState(BrowserControlsState constraints,
BrowserControlsState current,
- bool animate) override;
+ bool animate) override {}
// SchedulerClient implementation
void WillBeginImplFrame(const viz::BeginFrameArgs& args) override;
@@ -147,8 +149,6 @@ class CC_EXPORT SingleThreadProxy : public Proxy,
// Accessed from both threads.
std::unique_ptr<Scheduler> scheduler_on_impl_thread_;
- std::unique_ptr<BlockingTaskRunner::CapturePostTasks>
- commit_blocking_task_runner_;
bool next_frame_is_newly_committed_frame_;
#if DCHECK_IS_ON()
diff --git a/chromium/cc/output/swap_promise.h b/chromium/cc/trees/swap_promise.h
index 70b9ac87226..81ec7cd0e36 100644
--- a/chromium/cc/output/swap_promise.h
+++ b/chromium/cc/trees/swap_promise.h
@@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CC_OUTPUT_SWAP_PROMISE_H_
-#define CC_OUTPUT_SWAP_PROMISE_H_
+#ifndef CC_TREES_SWAP_PROMISE_H_
+#define CC_TREES_SWAP_PROMISE_H_
#include <stdint.h>
-#include "cc/output/compositor_frame_metadata.h"
+#include "cc/cc_export.h"
+#include "components/viz/common/quads/compositor_frame_metadata.h"
namespace cc {
@@ -60,7 +61,7 @@ class CC_EXPORT SwapPromise {
virtual ~SwapPromise() {}
virtual void DidActivate() = 0;
- virtual void WillSwap(CompositorFrameMetadata* metadata) = 0;
+ virtual void WillSwap(viz::CompositorFrameMetadata* metadata) = 0;
virtual void DidSwap() = 0;
// Return |KEEP_ACTIVE| if this promise should remain active (should not be
// broken by the owner).
@@ -76,4 +77,4 @@ class CC_EXPORT SwapPromise {
} // namespace cc
-#endif // CC_OUTPUT_SWAP_PROMISE_H_
+#endif // CC_TREES_SWAP_PROMISE_H_
diff --git a/chromium/cc/trees/swap_promise_manager.cc b/chromium/cc/trees/swap_promise_manager.cc
index 7a177417114..124e2b3bbf5 100644
--- a/chromium/cc/trees/swap_promise_manager.cc
+++ b/chromium/cc/trees/swap_promise_manager.cc
@@ -4,7 +4,7 @@
#include "cc/trees/swap_promise_manager.h"
-#include "cc/output/swap_promise.h"
+#include "cc/trees/swap_promise.h"
#include "cc/trees/swap_promise_monitor.h"
namespace cc {
diff --git a/chromium/cc/trees/swap_promise_manager.h b/chromium/cc/trees/swap_promise_manager.h
index 795493dd3bb..da72a8ac0aa 100644
--- a/chromium/cc/trees/swap_promise_manager.h
+++ b/chromium/cc/trees/swap_promise_manager.h
@@ -10,7 +10,7 @@
#include "base/macros.h"
#include "cc/cc_export.h"
-#include "cc/output/swap_promise.h"
+#include "cc/trees/swap_promise.h"
namespace cc {
class SwapPromise;
diff --git a/chromium/cc/trees/swap_promise_manager_unittest.cc b/chromium/cc/trees/swap_promise_manager_unittest.cc
index 9975899a41d..02f4df2d0a7 100644
--- a/chromium/cc/trees/swap_promise_manager_unittest.cc
+++ b/chromium/cc/trees/swap_promise_manager_unittest.cc
@@ -31,7 +31,7 @@ class MockSwapPromise : public SwapPromise {
~MockSwapPromise() override {}
void DidActivate() override {}
- void WillSwap(CompositorFrameMetadata* metadata) override {}
+ void WillSwap(viz::CompositorFrameMetadata* metadata) override {}
void DidSwap() override {}
DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override {
return DidNotSwapAction::BREAK_PROMISE;
diff --git a/chromium/cc/trees/task_runner_provider.cc b/chromium/cc/trees/task_runner_provider.cc
index 053b047385f..ebe7dd0c55f 100644
--- a/chromium/cc/trees/task_runner_provider.cc
+++ b/chromium/cc/trees/task_runner_provider.cc
@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "base/single_thread_task_runner.h"
-#include "cc/trees/blocking_task_runner.h"
#include "cc/trees/task_runner_provider.h"
namespace cc {
@@ -71,15 +70,10 @@ TaskRunnerProvider::TaskRunnerProvider(
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner)
#if !DCHECK_IS_ON()
- : main_task_runner_(main_task_runner),
- impl_task_runner_(impl_task_runner),
- blocking_main_thread_task_runner_(
- BlockingTaskRunner::Create(main_task_runner)) {
+ : main_task_runner_(main_task_runner), impl_task_runner_(impl_task_runner) {
#else
: main_task_runner_(main_task_runner),
impl_task_runner_(impl_task_runner),
- blocking_main_thread_task_runner_(
- BlockingTaskRunner::Create(main_task_runner)),
main_thread_id_(base::PlatformThread::CurrentId()),
impl_thread_is_overridden_(false),
is_main_thread_blocked_(false) {
diff --git a/chromium/cc/trees/task_runner_provider.h b/chromium/cc/trees/task_runner_provider.h
index 1a7ebf5adca..42b0ed80a31 100644
--- a/chromium/cc/trees/task_runner_provider.h
+++ b/chromium/cc/trees/task_runner_provider.h
@@ -23,7 +23,6 @@ class SingleThreadTaskRunner;
}
namespace cc {
-class BlockingTaskRunner;
// Class responsible for controlling access to the main and impl task runners.
// Useful for assertion checks.
@@ -53,10 +52,6 @@ class CC_EXPORT TaskRunnerProvider {
virtual ~TaskRunnerProvider();
- BlockingTaskRunner* blocking_main_thread_task_runner() const {
- return blocking_main_thread_task_runner_.get();
- }
-
protected:
TaskRunnerProvider(
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
@@ -69,7 +64,6 @@ class CC_EXPORT TaskRunnerProvider {
private:
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_;
- std::unique_ptr<BlockingTaskRunner> blocking_main_thread_task_runner_;
#if DCHECK_IS_ON()
const base::PlatformThreadId main_thread_id_;
diff --git a/chromium/cc/trees/tree_synchronizer_unittest.cc b/chromium/cc/trees/tree_synchronizer_unittest.cc
index f7e7e9f92b1..f87b4e58f46 100644
--- a/chromium/cc/trees/tree_synchronizer_unittest.cc
+++ b/chromium/cc/trees/tree_synchronizer_unittest.cc
@@ -66,7 +66,7 @@ class MockLayer : public Layer {
public:
static scoped_refptr<MockLayer> Create(
std::vector<int>* layer_impl_destruction_list) {
- return make_scoped_refptr(new MockLayer(layer_impl_destruction_list));
+ return base::WrapRefCounted(new MockLayer(layer_impl_destruction_list));
}
std::unique_ptr<LayerImpl> CreateLayerImpl(