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

Side by Side Diff: components/viz/service/display/surface_aggregator.cc

Issue 2873593002: Force use of and cache render surface. (Closed)
Patch Set: Reduce unneeded code in surface aggregator and add more test. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/viz/service/display/surface_aggregator.h" 5 #include "components/viz/service/display/surface_aggregator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 10
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 size_t sqs_size = source.shared_quad_state_list.size(); 258 size_t sqs_size = source.shared_quad_state_list.size();
259 size_t dq_size = source.quad_list.size(); 259 size_t dq_size = source.quad_list.size();
260 std::unique_ptr<cc::RenderPass> copy_pass( 260 std::unique_ptr<cc::RenderPass> copy_pass(
261 cc::RenderPass::Create(sqs_size, dq_size)); 261 cc::RenderPass::Create(sqs_size, dq_size));
262 262
263 cc::RenderPassId remapped_pass_id = RemapPassId(source.id, surface_id); 263 cc::RenderPassId remapped_pass_id = RemapPassId(source.id, surface_id);
264 264
265 copy_pass->SetAll(remapped_pass_id, source.output_rect, source.output_rect, 265 copy_pass->SetAll(remapped_pass_id, source.output_rect, source.output_rect,
266 source.transform_to_root_target, source.filters, 266 source.transform_to_root_target, source.filters,
267 source.background_filters, blending_color_space_, 267 source.background_filters, blending_color_space_,
268 source.has_transparent_background); 268 source.has_transparent_background,
269 source.cache_render_surface,
270 source.has_damage_from_contributing_content);
269 271
270 MoveMatchingRequests(source.id, &copy_requests, &copy_pass->copy_requests); 272 MoveMatchingRequests(source.id, &copy_requests, &copy_pass->copy_requests);
271 273
272 // Contributing passes aggregated in to the pass list need to take the 274 // Contributing passes aggregated in to the pass list need to take the
273 // transform of the surface quad into account to update their transform to 275 // transform of the surface quad into account to update their transform to
274 // the root surface. 276 // the root surface.
275 copy_pass->transform_to_root_target.ConcatTransform( 277 copy_pass->transform_to_root_target.ConcatTransform(
276 surface_quad->shared_quad_state->quad_to_target_transform); 278 surface_quad->shared_quad_state->quad_to_target_transform);
277 copy_pass->transform_to_root_target.ConcatTransform(target_transform); 279 copy_pass->transform_to_root_target.ConcatTransform(target_transform);
278 copy_pass->transform_to_root_target.ConcatTransform( 280 copy_pass->transform_to_root_target.ConcatTransform(
279 dest_pass->transform_to_root_target); 281 dest_pass->transform_to_root_target);
280 282
281 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, 283 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list,
282 child_to_parent_map, gfx::Transform(), ClipData(), 284 child_to_parent_map, gfx::Transform(), ClipData(),
283 copy_pass.get(), surface_id); 285 copy_pass.get(), surface_id);
284 286
285 if (!copy_request_passes_.count(remapped_pass_id) && 287 if (!copy_request_passes_.count(remapped_pass_id) &&
288 !copy_pass->cache_render_surface &&
danakj 2017/07/25 18:55:02 I feel that each of these 3 conditions needs a com
wutao 2017/07/26 07:48:52 Do not need this change anymore. But I try to exp
wutao 2017/07/27 02:30:13 Added comments.
286 !moved_pixel_passes_.count(remapped_pass_id)) { 289 !moved_pixel_passes_.count(remapped_pass_id)) {
287 gfx::Transform inverse_transform(gfx::Transform::kSkipInitialization); 290 gfx::Transform inverse_transform(gfx::Transform::kSkipInitialization);
288 if (copy_pass->transform_to_root_target.GetInverse(&inverse_transform)) { 291 if (copy_pass->transform_to_root_target.GetInverse(&inverse_transform)) {
289 gfx::Rect damage_rect_in_render_pass_space = 292 gfx::Rect damage_rect_in_render_pass_space =
290 cc::MathUtil::ProjectEnclosingClippedRect(inverse_transform, 293 cc::MathUtil::ProjectEnclosingClippedRect(inverse_transform,
291 root_damage_rect_); 294 root_damage_rect_);
292 copy_pass->damage_rect.Intersect(damage_rect_in_render_pass_space); 295 copy_pass->damage_rect.Intersect(damage_rect_in_render_pass_space);
293 } 296 }
294 } 297 }
295 298
296 dest_pass_list_->push_back(std::move(copy_pass)); 299 dest_pass_list_->push_back(std::move(copy_pass));
297 } 300 }
298 301
299 gfx::Transform surface_transform = 302 gfx::Transform surface_transform =
300 surface_quad->shared_quad_state->quad_to_target_transform; 303 surface_quad->shared_quad_state->quad_to_target_transform;
301 surface_transform.ConcatTransform(target_transform); 304 surface_transform.ConcatTransform(target_transform);
302 305
303 const auto& last_pass = *render_pass_list.back(); 306 const auto& last_pass = *render_pass_list.back();
307 // This will check if all the surface_quads (including child surfaces) has
308 // damage because HandleSurfaceQuad is a recursive call by calling
309 // CopyQuadsToPass in it. This is different than the damage_rect calculated in
danakj 2017/07/25 18:55:03 I'm not clear why this is talking about Prewalk tr
wutao 2017/07/26 07:48:52 I should mention Prewalk here. I did just because
310 // PrewalkTree, which also includes all the damage in the top level surface,
311 // containing damage from damage_tracker.
danakj 2017/07/25 18:55:03 "containing damage specified with the CompositorFr
wutao 2017/07/26 07:48:52 Deleted comments related to PrewalkTree.
312 if (dest_pass->cache_render_surface) {
313 dest_pass->has_damage_from_contributing_content |=
jbauman 2017/07/25 20:40:34 Suppose we have a Surface 1 with damage, and a sur
wutao 2017/07/26 07:48:53 Yes. we should set the flag. You example makes me
314 !DamageRectForSurface(surface, last_pass, last_pass.output_rect)
315 .IsEmpty();
316 }
317
304 if (merge_pass) { 318 if (merge_pass) {
305 // TODO(jamesr): Clean up last pass special casing. 319 // TODO(jamesr): Clean up last pass special casing.
306 const cc::QuadList& quads = last_pass.quad_list; 320 const cc::QuadList& quads = last_pass.quad_list;
307 321
308 // Intersect the transformed visible rect and the clip rect to create a 322 // Intersect the transformed visible rect and the clip rect to create a
309 // smaller cliprect for the quad. 323 // smaller cliprect for the quad.
310 ClipData surface_quad_clip_rect( 324 ClipData surface_quad_clip_rect(
311 true, cc::MathUtil::MapEnclosingClippedRect( 325 true, cc::MathUtil::MapEnclosingClippedRect(
312 surface_quad->shared_quad_state->quad_to_target_transform, 326 surface_quad->shared_quad_state->quad_to_target_transform,
313 surface_quad->visible_rect)); 327 surface_quad->visible_rect));
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 const cc::QuadList& source_quad_list, 417 const cc::QuadList& source_quad_list,
404 const cc::SharedQuadStateList& source_shared_quad_state_list, 418 const cc::SharedQuadStateList& source_shared_quad_state_list,
405 const std::unordered_map<cc::ResourceId, cc::ResourceId>& 419 const std::unordered_map<cc::ResourceId, cc::ResourceId>&
406 child_to_parent_map, 420 child_to_parent_map,
407 const gfx::Transform& target_transform, 421 const gfx::Transform& target_transform,
408 const ClipData& clip_rect, 422 const ClipData& clip_rect,
409 cc::RenderPass* dest_pass, 423 cc::RenderPass* dest_pass,
410 const SurfaceId& surface_id) { 424 const SurfaceId& surface_id) {
411 const cc::SharedQuadState* last_copied_source_shared_quad_state = nullptr; 425 const cc::SharedQuadState* last_copied_source_shared_quad_state = nullptr;
412 const cc::SharedQuadState* dest_shared_quad_state = nullptr; 426 const cc::SharedQuadState* dest_shared_quad_state = nullptr;
413 // If the current frame has copy requests then aggregate the entire 427 // If the current frame has copy requests or cache render surface, then
414 // thing, as otherwise parts of the copy requests may be ignored. 428 // aggregate the entire thing, because we want full content.
danakj 2017/07/25 18:55:02 I think this comment is saying what we want as the
jbauman 2017/07/25 20:40:34 I think if the renderpass is partially offscreen i
wutao 2017/07/26 07:48:53 We do not need this change any more for cache rend
wutao 2017/07/27 02:30:13 Yes, if the render pass is off screen, then it is
danakj 2017/07/27 21:24:33 Thanks!
415 const bool ignore_undamaged = aggregate_only_damaged_ && 429 const bool ignore_undamaged =
416 !has_copy_requests_ && 430 aggregate_only_damaged_ && !has_copy_requests_ &&
417 !moved_pixel_passes_.count(dest_pass->id); 431 !has_cached_render_surfaces_ && !moved_pixel_passes_.count(dest_pass->id);
418 // Damage rect in the quad space of the current shared quad state. 432 // Damage rect in the quad space of the current shared quad state.
419 // TODO(jbauman): This rect may contain unnecessary area if 433 // TODO(jbauman): This rect may contain unnecessary area if
420 // transform isn't axis-aligned. 434 // transform isn't axis-aligned.
421 gfx::Rect damage_rect_in_quad_space; 435 gfx::Rect damage_rect_in_quad_space;
422 bool damage_rect_in_quad_space_valid = false; 436 bool damage_rect_in_quad_space_valid = false;
423 437
424 #if DCHECK_IS_ON() 438 #if DCHECK_IS_ON()
425 // If quads have come in with SharedQuadState out of order, or when quads have 439 // If quads have come in with SharedQuadState out of order, or when quads have
426 // invalid SharedQuadState pointer, it should DCHECK. 440 // invalid SharedQuadState pointer, it should DCHECK.
427 auto sqs_iter = source_shared_quad_state_list.cbegin(); 441 auto sqs_iter = source_shared_quad_state_list.cbegin();
(...skipping 20 matching lines...) Expand all
448 continue; 462 continue;
449 463
450 HandleSurfaceQuad(surface_quad, target_transform, clip_rect, dest_pass, 464 HandleSurfaceQuad(surface_quad, target_transform, clip_rect, dest_pass,
451 ignore_undamaged, &damage_rect_in_quad_space, 465 ignore_undamaged, &damage_rect_in_quad_space,
452 &damage_rect_in_quad_space_valid); 466 &damage_rect_in_quad_space_valid);
453 } else { 467 } else {
454 if (quad->shared_quad_state != last_copied_source_shared_quad_state) { 468 if (quad->shared_quad_state != last_copied_source_shared_quad_state) {
455 dest_shared_quad_state = CopySharedQuadState( 469 dest_shared_quad_state = CopySharedQuadState(
456 quad->shared_quad_state, target_transform, clip_rect, dest_pass); 470 quad->shared_quad_state, target_transform, clip_rect, dest_pass);
457 last_copied_source_shared_quad_state = quad->shared_quad_state; 471 last_copied_source_shared_quad_state = quad->shared_quad_state;
458 if (aggregate_only_damaged_ && !has_copy_requests_) { 472 if (aggregate_only_damaged_ && !has_copy_requests_ &&
473 !has_cached_render_surfaces_) {
459 damage_rect_in_quad_space_valid = CalculateQuadSpaceDamageRect( 474 damage_rect_in_quad_space_valid = CalculateQuadSpaceDamageRect(
460 dest_shared_quad_state->quad_to_target_transform, 475 dest_shared_quad_state->quad_to_target_transform,
461 dest_pass->transform_to_root_target, root_damage_rect_, 476 dest_pass->transform_to_root_target, root_damage_rect_,
462 &damage_rect_in_quad_space); 477 &damage_rect_in_quad_space);
463 } 478 }
464 } 479 }
465 480
466 if (ignore_undamaged) { 481 if (ignore_undamaged) {
467 if (damage_rect_in_quad_space_valid && 482 if (damage_rect_in_quad_space_valid &&
468 !damage_rect_in_quad_space.Intersects(quad->visible_rect)) 483 !damage_rect_in_quad_space.Intersects(quad->visible_rect))
469 continue; 484 continue;
470 } 485 }
471 486
472 cc::DrawQuad* dest_quad; 487 cc::DrawQuad* dest_quad;
473 if (quad->material == cc::DrawQuad::RENDER_PASS) { 488 if (quad->material == cc::DrawQuad::RENDER_PASS) {
474 const auto* pass_quad = cc::RenderPassDrawQuad::MaterialCast(quad); 489 const auto* pass_quad = cc::RenderPassDrawQuad::MaterialCast(quad);
475 int original_pass_id = pass_quad->render_pass_id; 490 int original_pass_id = pass_quad->render_pass_id;
476 int remapped_pass_id = RemapPassId(original_pass_id, surface_id); 491 int remapped_pass_id = RemapPassId(original_pass_id, surface_id);
477
478 dest_quad = dest_pass->CopyFromAndAppendRenderPassDrawQuad( 492 dest_quad = dest_pass->CopyFromAndAppendRenderPassDrawQuad(
479 pass_quad, dest_shared_quad_state, remapped_pass_id); 493 pass_quad, dest_shared_quad_state, remapped_pass_id);
480 } else if (quad->material == cc::DrawQuad::TEXTURE_CONTENT) { 494 } else if (quad->material == cc::DrawQuad::TEXTURE_CONTENT) {
481 const auto* texture_quad = cc::TextureDrawQuad::MaterialCast(quad); 495 const auto* texture_quad = cc::TextureDrawQuad::MaterialCast(quad);
482 if (texture_quad->secure_output_only && 496 if (texture_quad->secure_output_only &&
483 (!output_is_secure_ || copy_request_passes_.count(dest_pass->id))) { 497 (!output_is_secure_ || copy_request_passes_.count(dest_pass->id))) {
484 auto* solid_color_quad = 498 auto* solid_color_quad =
485 dest_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); 499 dest_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>();
486 solid_color_quad->SetNew(dest_shared_quad_state, quad->rect, 500 solid_color_quad->SetNew(dest_shared_quad_state, quad->rect,
487 quad->visible_rect, SK_ColorBLACK, false); 501 quad->visible_rect, SK_ColorBLACK, false);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 auto copy_pass = cc::RenderPass::Create(sqs_size, dq_size); 549 auto copy_pass = cc::RenderPass::Create(sqs_size, dq_size);
536 550
537 MoveMatchingRequests(source.id, &copy_requests, &copy_pass->copy_requests); 551 MoveMatchingRequests(source.id, &copy_requests, &copy_pass->copy_requests);
538 552
539 cc::RenderPassId remapped_pass_id = 553 cc::RenderPassId remapped_pass_id =
540 RemapPassId(source.id, surface->surface_id()); 554 RemapPassId(source.id, surface->surface_id());
541 555
542 copy_pass->SetAll(remapped_pass_id, source.output_rect, source.output_rect, 556 copy_pass->SetAll(remapped_pass_id, source.output_rect, source.output_rect,
543 source.transform_to_root_target, source.filters, 557 source.transform_to_root_target, source.filters,
544 source.background_filters, blending_color_space_, 558 source.background_filters, blending_color_space_,
545 source.has_transparent_background); 559 source.has_transparent_background,
560 source.cache_render_surface,
561 source.has_damage_from_contributing_content);
546 562
547 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, 563 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list,
548 child_to_parent_map, gfx::Transform(), ClipData(), 564 child_to_parent_map, gfx::Transform(), ClipData(),
549 copy_pass.get(), surface->surface_id()); 565 copy_pass.get(), surface->surface_id());
550 if (!copy_request_passes_.count(remapped_pass_id) && 566 if (!copy_request_passes_.count(remapped_pass_id) &&
567 !copy_pass->cache_render_surface &&
danakj 2017/07/25 18:55:03 I also think each of these needs the same comments
wutao 2017/07/26 07:48:53 Do not need this any more.
wutao 2017/07/27 02:30:13 Added comments.
551 !moved_pixel_passes_.count(remapped_pass_id)) { 568 !moved_pixel_passes_.count(remapped_pass_id)) {
552 gfx::Transform inverse_transform(gfx::Transform::kSkipInitialization); 569 gfx::Transform inverse_transform(gfx::Transform::kSkipInitialization);
553 if (copy_pass->transform_to_root_target.GetInverse(&inverse_transform)) { 570 if (copy_pass->transform_to_root_target.GetInverse(&inverse_transform)) {
554 gfx::Rect damage_rect_in_render_pass_space = 571 gfx::Rect damage_rect_in_render_pass_space =
555 cc::MathUtil::ProjectEnclosingClippedRect(inverse_transform, 572 cc::MathUtil::ProjectEnclosingClippedRect(inverse_transform,
556 root_damage_rect_); 573 root_damage_rect_);
557 copy_pass->damage_rect.Intersect(damage_rect_in_render_pass_space); 574 copy_pass->damage_rect.Intersect(damage_rect_in_render_pass_space);
558 } 575 }
559 } 576 }
560 577
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 CHECK(debug_weak_this.get()); 771 CHECK(debug_weak_this.get());
755 // TODO(staraz): It shouldn't need to call the callback when the damage is 772 // TODO(staraz): It shouldn't need to call the callback when the damage is
756 // from |surface| and not from |child_surfaces|. 773 // from |surface| and not from |child_surfaces|.
757 if (!damage_rect.IsEmpty()) { 774 if (!damage_rect.IsEmpty()) {
758 surface->RunWillDrawCallback(damage_rect); 775 surface->RunWillDrawCallback(damage_rect);
759 manager_->SurfaceWillDraw(surface->surface_id()); 776 manager_->SurfaceWillDraw(surface->surface_id());
760 } 777 }
761 778
762 CHECK(debug_weak_this.get()); 779 CHECK(debug_weak_this.get());
763 for (const auto& render_pass : frame.render_pass_list) { 780 for (const auto& render_pass : frame.render_pass_list) {
764 if (!render_pass->copy_requests.empty()) { 781 cc::RenderPassId remapped_pass_id =
765 cc::RenderPassId remapped_pass_id = 782 RemapPassId(render_pass->id, surface_id);
766 RemapPassId(render_pass->id, surface_id); 783 if (!render_pass->copy_requests.empty())
767 copy_request_passes_.insert(remapped_pass_id); 784 copy_request_passes_.insert(remapped_pass_id);
768 } 785 if (render_pass->cache_render_surface)
786 cached_render_surface_passes_.insert(remapped_pass_id);
769 } 787 }
770 788
771 referenced_surfaces_.erase(referenced_surfaces_.find(surface->surface_id())); 789 referenced_surfaces_.erase(referenced_surfaces_.find(surface->surface_id()));
772 if (!damage_rect.IsEmpty() && frame.metadata.may_contain_video) 790 if (!damage_rect.IsEmpty() && frame.metadata.may_contain_video)
773 result->may_contain_video = true; 791 result->may_contain_video = true;
774 return damage_rect; 792 return damage_rect;
775 } 793 }
776 794
777 void SurfaceAggregator::CopyUndrawnSurfaces(PrewalkResult* prewalk_result) { 795 void SurfaceAggregator::CopyUndrawnSurfaces(PrewalkResult* prewalk_result) {
778 // undrawn_surfaces are Surfaces that were identified by prewalk as being 796 // undrawn_surfaces are Surfaces that were identified by prewalk as being
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 868
851 cc::CompositorFrame frame; 869 cc::CompositorFrame frame;
852 870
853 dest_pass_list_ = &frame.render_pass_list; 871 dest_pass_list_ = &frame.render_pass_list;
854 872
855 valid_surfaces_.clear(); 873 valid_surfaces_.clear();
856 PrewalkResult prewalk_result; 874 PrewalkResult prewalk_result;
857 root_damage_rect_ = PrewalkTree(surface_id, false, 0, &prewalk_result); 875 root_damage_rect_ = PrewalkTree(surface_id, false, 0, &prewalk_result);
858 PropagateCopyRequestPasses(); 876 PropagateCopyRequestPasses();
859 has_copy_requests_ = !copy_request_passes_.empty(); 877 has_copy_requests_ = !copy_request_passes_.empty();
878 has_cached_render_surfaces_ = !cached_render_surface_passes_.empty();
860 frame.metadata.may_contain_video = prewalk_result.may_contain_video; 879 frame.metadata.may_contain_video = prewalk_result.may_contain_video;
861 880
862 CopyUndrawnSurfaces(&prewalk_result); 881 CopyUndrawnSurfaces(&prewalk_result);
863 referenced_surfaces_.insert(surface_id); 882 referenced_surfaces_.insert(surface_id);
864 CopyPasses(root_surface_frame, surface); 883 CopyPasses(root_surface_frame, surface);
865 // CopyPasses may have mutated container, need to re-query to erase. 884 // CopyPasses may have mutated container, need to re-query to erase.
866 referenced_surfaces_.erase(referenced_surfaces_.find(surface_id)); 885 referenced_surfaces_.erase(referenced_surfaces_.find(surface_id));
867 AddColorConversionPass(); 886 AddColorConversionPass();
868 887
869 moved_pixel_passes_.clear(); 888 moved_pixel_passes_.clear();
870 copy_request_passes_.clear(); 889 copy_request_passes_.clear();
890 cached_render_surface_passes_.clear();
871 render_pass_dependencies_.clear(); 891 render_pass_dependencies_.clear();
872 892
873 // Remove all render pass mappings that weren't used in the current frame. 893 // Remove all render pass mappings that weren't used in the current frame.
874 for (auto it = render_pass_allocator_map_.begin(); 894 for (auto it = render_pass_allocator_map_.begin();
875 it != render_pass_allocator_map_.end();) { 895 it != render_pass_allocator_map_.end();) {
876 if (it->second.in_use) { 896 if (it->second.in_use) {
877 it->second.in_use = false; 897 it->second.in_use = false;
878 it++; 898 it++;
879 } else { 899 } else {
880 it = render_pass_allocator_map_.erase(it); 900 it = render_pass_allocator_map_.erase(it);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 const gfx::ColorSpace& output_color_space) { 953 const gfx::ColorSpace& output_color_space) {
934 blending_color_space_ = blending_color_space.IsValid() 954 blending_color_space_ = blending_color_space.IsValid()
935 ? blending_color_space 955 ? blending_color_space
936 : gfx::ColorSpace::CreateSRGB(); 956 : gfx::ColorSpace::CreateSRGB();
937 output_color_space_ = output_color_space.IsValid() 957 output_color_space_ = output_color_space.IsValid()
938 ? output_color_space 958 ? output_color_space
939 : gfx::ColorSpace::CreateSRGB(); 959 : gfx::ColorSpace::CreateSRGB();
940 } 960 }
941 961
942 } // namespace viz 962 } // namespace viz
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698