| OLD | NEW |
| 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 "cc/surfaces/surface_aggregator.h" | 5 #include "cc/surfaces/surface_aggregator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 std::multimap<int, std::unique_ptr<CopyOutputRequest>>* copy_requests, | 37 std::multimap<int, std::unique_ptr<CopyOutputRequest>>* copy_requests, |
| 38 std::vector<std::unique_ptr<CopyOutputRequest>>* output_requests) { | 38 std::vector<std::unique_ptr<CopyOutputRequest>>* output_requests) { |
| 39 auto request_range = copy_requests->equal_range(render_pass_id); | 39 auto request_range = copy_requests->equal_range(render_pass_id); |
| 40 for (auto it = request_range.first; it != request_range.second; ++it) { | 40 for (auto it = request_range.first; it != request_range.second; ++it) { |
| 41 DCHECK(it->second); | 41 DCHECK(it->second); |
| 42 output_requests->push_back(std::move(it->second)); | 42 output_requests->push_back(std::move(it->second)); |
| 43 } | 43 } |
| 44 copy_requests->erase(request_range.first, request_range.second); | 44 copy_requests->erase(request_range.first, request_range.second); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Returns true if the damage rect is valid. |
| 48 bool CalculateQuadSpaceDamageRect( |
| 49 const gfx::Transform& quad_to_target_transform, |
| 50 const gfx::Transform& target_to_root_transform, |
| 51 const gfx::Rect& root_damage_rect, |
| 52 gfx::Rect* quad_space_damage_rect) { |
| 53 gfx::Transform quad_to_root_transform(target_to_root_transform, |
| 54 quad_to_target_transform); |
| 55 gfx::Transform inverse_transform(gfx::Transform::kSkipInitialization); |
| 56 bool inverse_valid = quad_to_root_transform.GetInverse(&inverse_transform); |
| 57 if (!inverse_valid) |
| 58 return false; |
| 59 |
| 60 *quad_space_damage_rect = MathUtil::ProjectEnclosingClippedRect( |
| 61 inverse_transform, root_damage_rect); |
| 62 return true; |
| 63 } |
| 64 |
| 47 } // namespace | 65 } // namespace |
| 48 | 66 |
| 49 SurfaceAggregator::SurfaceAggregator(SurfaceManager* manager, | 67 SurfaceAggregator::SurfaceAggregator(SurfaceManager* manager, |
| 50 ResourceProvider* provider, | 68 ResourceProvider* provider, |
| 51 bool aggregate_only_damaged) | 69 bool aggregate_only_damaged) |
| 52 : manager_(manager), | 70 : manager_(manager), |
| 53 provider_(provider), | 71 provider_(provider), |
| 54 next_render_pass_id_(1), | 72 next_render_pass_id_(1), |
| 55 aggregate_only_damaged_(aggregate_only_damaged), | 73 aggregate_only_damaged_(aggregate_only_damaged), |
| 56 weak_factory_(this) { | 74 weak_factory_(this) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 return source.damage_rect; | 170 return source.damage_rect; |
| 153 } | 171 } |
| 154 | 172 |
| 155 return full_rect; | 173 return full_rect; |
| 156 } | 174 } |
| 157 | 175 |
| 158 void SurfaceAggregator::HandleSurfaceQuad( | 176 void SurfaceAggregator::HandleSurfaceQuad( |
| 159 const SurfaceDrawQuad* surface_quad, | 177 const SurfaceDrawQuad* surface_quad, |
| 160 const gfx::Transform& target_transform, | 178 const gfx::Transform& target_transform, |
| 161 const ClipData& clip_rect, | 179 const ClipData& clip_rect, |
| 162 RenderPass* dest_pass) { | 180 RenderPass* dest_pass, |
| 181 bool ignore_undamaged, |
| 182 gfx::Rect* damage_rect_in_quad_space, |
| 183 bool* damage_rect_in_quad_space_valid) { |
| 163 SurfaceId surface_id = surface_quad->surface_id; | 184 SurfaceId surface_id = surface_quad->surface_id; |
| 164 // If this surface's id is already in our referenced set then it creates | 185 // If this surface's id is already in our referenced set then it creates |
| 165 // a cycle in the graph and should be dropped. | 186 // a cycle in the graph and should be dropped. |
| 166 if (referenced_surfaces_.count(surface_id)) | 187 if (referenced_surfaces_.count(surface_id)) |
| 167 return; | 188 return; |
| 168 Surface* surface = manager_->GetSurfaceForId(surface_id); | 189 Surface* surface = manager_->GetSurfaceForId(surface_id); |
| 169 if (!surface) | 190 if (!surface || !surface->HasFrame()) { |
| 191 if (surface_quad->fallback_quad) { |
| 192 HandleSurfaceQuad(surface_quad->fallback_quad, target_transform, |
| 193 clip_rect, dest_pass, ignore_undamaged, |
| 194 damage_rect_in_quad_space, |
| 195 damage_rect_in_quad_space_valid); |
| 196 } |
| 170 return; | 197 return; |
| 171 if (!surface->HasFrame()) | 198 } |
| 172 return; | 199 |
| 200 if (ignore_undamaged) { |
| 201 gfx::Transform quad_to_target_transform( |
| 202 target_transform, |
| 203 surface_quad->shared_quad_state->quad_to_target_transform); |
| 204 *damage_rect_in_quad_space_valid = CalculateQuadSpaceDamageRect( |
| 205 quad_to_target_transform, dest_pass->transform_to_root_target, |
| 206 root_damage_rect_, damage_rect_in_quad_space); |
| 207 if (*damage_rect_in_quad_space_valid && |
| 208 !damage_rect_in_quad_space->Intersects(surface_quad->visible_rect)) { |
| 209 return; |
| 210 } |
| 211 } |
| 212 |
| 173 const CompositorFrame& frame = surface->GetEligibleFrame(); | 213 const CompositorFrame& frame = surface->GetEligibleFrame(); |
| 174 | 214 |
| 175 // A map keyed by RenderPass id. | 215 // A map keyed by RenderPass id. |
| 176 std::multimap<int, std::unique_ptr<CopyOutputRequest>> copy_requests; | 216 std::multimap<int, std::unique_ptr<CopyOutputRequest>> copy_requests; |
| 177 surface->TakeCopyOutputRequests(©_requests); | 217 surface->TakeCopyOutputRequests(©_requests); |
| 178 | 218 |
| 179 const RenderPassList& render_pass_list = frame.render_pass_list; | 219 const RenderPassList& render_pass_list = frame.render_pass_list; |
| 180 if (!valid_surfaces_.count(surface->surface_id())) { | 220 if (!valid_surfaces_.count(surface->surface_id())) { |
| 181 for (auto& request : copy_requests) | 221 for (auto& request : copy_requests) |
| 182 request.second->SendEmptyResult(); | 222 request.second->SendEmptyResult(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 target_transform); | 342 target_transform); |
| 303 | 343 |
| 304 ClipData new_clip_rect = CalculateClipRect( | 344 ClipData new_clip_rect = CalculateClipRect( |
| 305 clip_rect, ClipData(source_sqs->is_clipped, source_sqs->clip_rect), | 345 clip_rect, ClipData(source_sqs->is_clipped, source_sqs->clip_rect), |
| 306 target_transform); | 346 target_transform); |
| 307 copy_shared_quad_state->is_clipped = new_clip_rect.is_clipped; | 347 copy_shared_quad_state->is_clipped = new_clip_rect.is_clipped; |
| 308 copy_shared_quad_state->clip_rect = new_clip_rect.rect; | 348 copy_shared_quad_state->clip_rect = new_clip_rect.rect; |
| 309 return copy_shared_quad_state; | 349 return copy_shared_quad_state; |
| 310 } | 350 } |
| 311 | 351 |
| 312 // Returns true if the damage rect is valid. | |
| 313 static bool CalculateQuadSpaceDamageRect( | |
| 314 const gfx::Transform& quad_to_target_transform, | |
| 315 const gfx::Transform& target_to_root_transform, | |
| 316 const gfx::Rect& root_damage_rect, | |
| 317 gfx::Rect* quad_space_damage_rect) { | |
| 318 gfx::Transform quad_to_root_transform(target_to_root_transform, | |
| 319 quad_to_target_transform); | |
| 320 gfx::Transform inverse_transform(gfx::Transform::kSkipInitialization); | |
| 321 bool inverse_valid = quad_to_root_transform.GetInverse(&inverse_transform); | |
| 322 if (!inverse_valid) | |
| 323 return false; | |
| 324 | |
| 325 *quad_space_damage_rect = MathUtil::ProjectEnclosingClippedRect( | |
| 326 inverse_transform, root_damage_rect); | |
| 327 return true; | |
| 328 } | |
| 329 | |
| 330 void SurfaceAggregator::CopyQuadsToPass( | 352 void SurfaceAggregator::CopyQuadsToPass( |
| 331 const QuadList& source_quad_list, | 353 const QuadList& source_quad_list, |
| 332 const SharedQuadStateList& source_shared_quad_state_list, | 354 const SharedQuadStateList& source_shared_quad_state_list, |
| 333 const ResourceProvider::ResourceIdMap& child_to_parent_map, | 355 const ResourceProvider::ResourceIdMap& child_to_parent_map, |
| 334 const gfx::Transform& target_transform, | 356 const gfx::Transform& target_transform, |
| 335 const ClipData& clip_rect, | 357 const ClipData& clip_rect, |
| 336 RenderPass* dest_pass, | 358 RenderPass* dest_pass, |
| 337 const SurfaceId& surface_id) { | 359 const SurfaceId& surface_id) { |
| 338 const SharedQuadState* last_copied_source_shared_quad_state = nullptr; | 360 const SharedQuadState* last_copied_source_shared_quad_state = nullptr; |
| 339 const SharedQuadState* dest_shared_quad_state = nullptr; | 361 const SharedQuadState* dest_shared_quad_state = nullptr; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 362 } | 384 } |
| 363 #endif | 385 #endif |
| 364 | 386 |
| 365 for (auto* quad : source_quad_list) { | 387 for (auto* quad : source_quad_list) { |
| 366 if (quad->material == DrawQuad::SURFACE_CONTENT) { | 388 if (quad->material == DrawQuad::SURFACE_CONTENT) { |
| 367 const SurfaceDrawQuad* surface_quad = SurfaceDrawQuad::MaterialCast(quad); | 389 const SurfaceDrawQuad* surface_quad = SurfaceDrawQuad::MaterialCast(quad); |
| 368 // HandleSurfaceQuad may add other shared quad state, so reset the | 390 // HandleSurfaceQuad may add other shared quad state, so reset the |
| 369 // current data. | 391 // current data. |
| 370 last_copied_source_shared_quad_state = nullptr; | 392 last_copied_source_shared_quad_state = nullptr; |
| 371 | 393 |
| 372 if (ignore_undamaged) { | 394 // The primary SurfaceDrawQuad should have already dealt with the fallback |
| 373 gfx::Transform quad_to_target_transform( | 395 // DrawQuad. |
| 374 target_transform, | 396 if (surface_quad->surface_draw_quad_type == SurfaceDrawQuadType::FALLBACK) |
| 375 quad->shared_quad_state->quad_to_target_transform); | 397 continue; |
| 376 damage_rect_in_quad_space_valid = CalculateQuadSpaceDamageRect( | 398 |
| 377 quad_to_target_transform, dest_pass->transform_to_root_target, | 399 HandleSurfaceQuad(surface_quad, target_transform, clip_rect, dest_pass, |
| 378 root_damage_rect_, &damage_rect_in_quad_space); | 400 ignore_undamaged, &damage_rect_in_quad_space, |
| 379 if (damage_rect_in_quad_space_valid && | 401 &damage_rect_in_quad_space_valid); |
| 380 !damage_rect_in_quad_space.Intersects(quad->visible_rect)) | |
| 381 continue; | |
| 382 } | |
| 383 HandleSurfaceQuad(surface_quad, target_transform, clip_rect, dest_pass); | |
| 384 } else { | 402 } else { |
| 385 if (quad->shared_quad_state != last_copied_source_shared_quad_state) { | 403 if (quad->shared_quad_state != last_copied_source_shared_quad_state) { |
| 386 dest_shared_quad_state = CopySharedQuadState( | 404 dest_shared_quad_state = CopySharedQuadState( |
| 387 quad->shared_quad_state, target_transform, clip_rect, dest_pass); | 405 quad->shared_quad_state, target_transform, clip_rect, dest_pass); |
| 388 last_copied_source_shared_quad_state = quad->shared_quad_state; | 406 last_copied_source_shared_quad_state = quad->shared_quad_state; |
| 389 if (aggregate_only_damaged_ && !has_copy_requests_) { | 407 if (aggregate_only_damaged_ && !has_copy_requests_) { |
| 390 damage_rect_in_quad_space_valid = CalculateQuadSpaceDamageRect( | 408 damage_rect_in_quad_space_valid = CalculateQuadSpaceDamageRect( |
| 391 dest_shared_quad_state->quad_to_target_transform, | 409 dest_shared_quad_state->quad_to_target_transform, |
| 392 dest_pass->transform_to_root_target, root_damage_rect_, | 410 dest_pass->transform_to_root_target, root_damage_rect_, |
| 393 &damage_rect_in_quad_space); | 411 &damage_rect_in_quad_space); |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 | 860 |
| 843 void SurfaceAggregator::SetFullDamageForSurface(const SurfaceId& surface_id) { | 861 void SurfaceAggregator::SetFullDamageForSurface(const SurfaceId& surface_id) { |
| 844 auto it = previous_contained_surfaces_.find(surface_id); | 862 auto it = previous_contained_surfaces_.find(surface_id); |
| 845 if (it == previous_contained_surfaces_.end()) | 863 if (it == previous_contained_surfaces_.end()) |
| 846 return; | 864 return; |
| 847 // Set the last drawn index as 0 to ensure full damage next time it's drawn. | 865 // Set the last drawn index as 0 to ensure full damage next time it's drawn. |
| 848 it->second = 0; | 866 it->second = 0; |
| 849 } | 867 } |
| 850 | 868 |
| 851 } // namespace cc | 869 } // namespace cc |
| OLD | NEW |