| 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/display.h" | 5 #include "cc/surfaces/display.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // overlays. | 210 // overlays. |
| 211 bool output_partial_list = renderer_->use_partial_swap() && | 211 bool output_partial_list = renderer_->use_partial_swap() && |
| 212 !output_surface_->GetOverlayCandidateValidator(); | 212 !output_surface_->GetOverlayCandidateValidator(); |
| 213 aggregator_.reset(new SurfaceAggregator( | 213 aggregator_.reset(new SurfaceAggregator( |
| 214 surface_manager_, resource_provider_.get(), output_partial_list)); | 214 surface_manager_, resource_provider_.get(), output_partial_list)); |
| 215 aggregator_->set_output_is_secure(output_is_secure_); | 215 aggregator_->set_output_is_secure(output_is_secure_); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void Display::UpdateRootSurfaceResourcesLocked() { | 218 void Display::UpdateRootSurfaceResourcesLocked() { |
| 219 Surface* surface = surface_manager_->GetSurfaceForId(current_surface_id_); | 219 Surface* surface = surface_manager_->GetSurfaceForId(current_surface_id_); |
| 220 bool root_surface_resources_locked = | 220 bool root_surface_resources_locked = !surface || !surface->HasFrame(); |
| 221 !surface || !surface->GetEligibleFrame().delegated_frame_data; | |
| 222 if (scheduler_) | 221 if (scheduler_) |
| 223 scheduler_->SetRootSurfaceResourcesLocked(root_surface_resources_locked); | 222 scheduler_->SetRootSurfaceResourcesLocked(root_surface_resources_locked); |
| 224 } | 223 } |
| 225 | 224 |
| 226 void Display::DidLoseContextProvider() { | 225 void Display::DidLoseContextProvider() { |
| 227 if (scheduler_) | 226 if (scheduler_) |
| 228 scheduler_->OutputSurfaceLost(); | 227 scheduler_->OutputSurfaceLost(); |
| 229 // WARNING: The client may delete the Display in this method call. Do not | 228 // WARNING: The client may delete the Display in this method call. Do not |
| 230 // make any additional references to members after this call. | 229 // make any additional references to members after this call. |
| 231 client_->DisplayOutputSurfaceLost(); | 230 client_->DisplayOutputSurfaceLost(); |
| 232 } | 231 } |
| 233 | 232 |
| 234 bool Display::DrawAndSwap() { | 233 bool Display::DrawAndSwap() { |
| 235 TRACE_EVENT0("cc", "Display::DrawAndSwap"); | 234 TRACE_EVENT0("cc", "Display::DrawAndSwap"); |
| 236 | 235 |
| 237 if (!current_surface_id_.is_valid()) { | 236 if (!current_surface_id_.is_valid()) { |
| 238 TRACE_EVENT_INSTANT0("cc", "No root surface.", TRACE_EVENT_SCOPE_THREAD); | 237 TRACE_EVENT_INSTANT0("cc", "No root surface.", TRACE_EVENT_SCOPE_THREAD); |
| 239 return false; | 238 return false; |
| 240 } | 239 } |
| 241 | 240 |
| 242 if (!output_surface_) { | 241 if (!output_surface_) { |
| 243 TRACE_EVENT_INSTANT0("cc", "No output surface", TRACE_EVENT_SCOPE_THREAD); | 242 TRACE_EVENT_INSTANT0("cc", "No output surface", TRACE_EVENT_SCOPE_THREAD); |
| 244 return false; | 243 return false; |
| 245 } | 244 } |
| 246 | 245 |
| 247 CompositorFrame frame = aggregator_->Aggregate(current_surface_id_); | 246 CompositorFrame frame = aggregator_->Aggregate(current_surface_id_); |
| 248 if (!frame.delegated_frame_data) { | 247 |
| 248 if (frame.render_pass_list.empty()) { |
| 249 TRACE_EVENT_INSTANT0("cc", "Empty aggregated frame.", | 249 TRACE_EVENT_INSTANT0("cc", "Empty aggregated frame.", |
| 250 TRACE_EVENT_SCOPE_THREAD); | 250 TRACE_EVENT_SCOPE_THREAD); |
| 251 return false; | 251 return false; |
| 252 } | 252 } |
| 253 | 253 |
| 254 // Run callbacks early to allow pipelining. | 254 // Run callbacks early to allow pipelining. |
| 255 for (const auto& id_entry : aggregator_->previous_contained_surfaces()) { | 255 for (const auto& id_entry : aggregator_->previous_contained_surfaces()) { |
| 256 Surface* surface = surface_manager_->GetSurfaceForId(id_entry.first); | 256 Surface* surface = surface_manager_->GetSurfaceForId(id_entry.first); |
| 257 if (surface) | 257 if (surface) |
| 258 surface->RunDrawCallbacks(); | 258 surface->RunDrawCallbacks(); |
| 259 } | 259 } |
| 260 | 260 |
| 261 DelegatedFrameData* frame_data = frame.delegated_frame_data.get(); | |
| 262 | |
| 263 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(), | 261 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(), |
| 264 stored_latency_info_.begin(), | 262 stored_latency_info_.begin(), |
| 265 stored_latency_info_.end()); | 263 stored_latency_info_.end()); |
| 266 stored_latency_info_.clear(); | 264 stored_latency_info_.clear(); |
| 267 bool have_copy_requests = false; | 265 bool have_copy_requests = false; |
| 268 for (const auto& pass : frame_data->render_pass_list) { | 266 for (const auto& pass : frame.render_pass_list) { |
| 269 have_copy_requests |= !pass->copy_requests.empty(); | 267 have_copy_requests |= !pass->copy_requests.empty(); |
| 270 } | 268 } |
| 271 | 269 |
| 272 gfx::Size surface_size; | 270 gfx::Size surface_size; |
| 273 bool have_damage = false; | 271 bool have_damage = false; |
| 274 if (!frame_data->render_pass_list.empty()) { | 272 if (!frame.render_pass_list.empty()) { |
| 275 RenderPass& last_render_pass = *frame_data->render_pass_list.back(); | 273 RenderPass& last_render_pass = *frame.render_pass_list.back(); |
| 276 if (last_render_pass.output_rect.size() != current_surface_size_ && | 274 if (last_render_pass.output_rect.size() != current_surface_size_ && |
| 277 last_render_pass.damage_rect == last_render_pass.output_rect && | 275 last_render_pass.damage_rect == last_render_pass.output_rect && |
| 278 !current_surface_size_.IsEmpty()) { | 276 !current_surface_size_.IsEmpty()) { |
| 279 // Resize the output rect to the current surface size so that we won't | 277 // Resize the output rect to the current surface size so that we won't |
| 280 // skip the draw and so that the GL swap won't stretch the output. | 278 // skip the draw and so that the GL swap won't stretch the output. |
| 281 last_render_pass.output_rect.set_size(current_surface_size_); | 279 last_render_pass.output_rect.set_size(current_surface_size_); |
| 282 last_render_pass.damage_rect = last_render_pass.output_rect; | 280 last_render_pass.damage_rect = last_render_pass.output_rect; |
| 283 } | 281 } |
| 284 surface_size = last_render_pass.output_rect.size(); | 282 surface_size = last_render_pass.output_rect.size(); |
| 285 have_damage = !last_render_pass.damage_rect.size().IsEmpty(); | 283 have_damage = !last_render_pass.damage_rect.size().IsEmpty(); |
| 286 } | 284 } |
| 287 | 285 |
| 288 bool size_matches = surface_size == current_surface_size_; | 286 bool size_matches = surface_size == current_surface_size_; |
| 289 if (!size_matches) | 287 if (!size_matches) |
| 290 TRACE_EVENT_INSTANT0("cc", "Size mismatch.", TRACE_EVENT_SCOPE_THREAD); | 288 TRACE_EVENT_INSTANT0("cc", "Size mismatch.", TRACE_EVENT_SCOPE_THREAD); |
| 291 | 289 |
| 292 bool should_draw = have_copy_requests || (have_damage && size_matches); | 290 bool should_draw = have_copy_requests || (have_damage && size_matches); |
| 293 | 291 |
| 294 // If the surface is suspended then the resources to be used by the draw are | 292 // If the surface is suspended then the resources to be used by the draw are |
| 295 // likely destroyed. | 293 // likely destroyed. |
| 296 if (output_surface_->SurfaceIsSuspendForRecycle()) { | 294 if (output_surface_->SurfaceIsSuspendForRecycle()) { |
| 297 TRACE_EVENT_INSTANT0("cc", "Surface is suspended for recycle.", | 295 TRACE_EVENT_INSTANT0("cc", "Surface is suspended for recycle.", |
| 298 TRACE_EVENT_SCOPE_THREAD); | 296 TRACE_EVENT_SCOPE_THREAD); |
| 299 should_draw = false; | 297 should_draw = false; |
| 300 } | 298 } |
| 301 | 299 |
| 302 client_->DisplayWillDrawAndSwap(should_draw, frame_data->render_pass_list); | 300 client_->DisplayWillDrawAndSwap(should_draw, frame.render_pass_list); |
| 303 | 301 |
| 304 if (should_draw) { | 302 if (should_draw) { |
| 305 bool disable_image_filtering = | 303 bool disable_image_filtering = |
| 306 frame.metadata.is_resourceless_software_draw_with_scroll_or_animation; | 304 frame.metadata.is_resourceless_software_draw_with_scroll_or_animation; |
| 307 if (software_renderer_) { | 305 if (software_renderer_) { |
| 308 software_renderer_->SetDisablePictureQuadImageFiltering( | 306 software_renderer_->SetDisablePictureQuadImageFiltering( |
| 309 disable_image_filtering); | 307 disable_image_filtering); |
| 310 } else { | 308 } else { |
| 311 // This should only be set for software draws in synchronous compositor. | 309 // This should only be set for software draws in synchronous compositor. |
| 312 DCHECK(!disable_image_filtering); | 310 DCHECK(!disable_image_filtering); |
| 313 } | 311 } |
| 314 | 312 |
| 315 renderer_->DecideRenderPassAllocationsForFrame( | 313 renderer_->DecideRenderPassAllocationsForFrame(frame.render_pass_list); |
| 316 frame_data->render_pass_list); | 314 renderer_->DrawFrame(&frame.render_pass_list, device_scale_factor_, |
| 317 renderer_->DrawFrame(&frame_data->render_pass_list, device_scale_factor_, | |
| 318 device_color_space_, current_surface_size_); | 315 device_color_space_, current_surface_size_); |
| 319 } else { | 316 } else { |
| 320 TRACE_EVENT_INSTANT0("cc", "Draw skipped.", TRACE_EVENT_SCOPE_THREAD); | 317 TRACE_EVENT_INSTANT0("cc", "Draw skipped.", TRACE_EVENT_SCOPE_THREAD); |
| 321 } | 318 } |
| 322 | 319 |
| 323 bool should_swap = should_draw && size_matches; | 320 bool should_swap = should_draw && size_matches; |
| 324 if (should_swap) { | 321 if (should_swap) { |
| 325 swapped_since_resize_ = true; | 322 swapped_since_resize_ = true; |
| 326 for (auto& latency : frame.metadata.latency_info) { | 323 for (auto& latency : frame.metadata.latency_info) { |
| 327 TRACE_EVENT_WITH_FLOW1( | 324 TRACE_EVENT_WITH_FLOW1( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 aggregator_->SetFullDamageForSurface(current_surface_id_); | 365 aggregator_->SetFullDamageForSurface(current_surface_id_); |
| 369 if (scheduler_) | 366 if (scheduler_) |
| 370 scheduler_->SurfaceDamaged(current_surface_id_); | 367 scheduler_->SurfaceDamaged(current_surface_id_); |
| 371 } | 368 } |
| 372 | 369 |
| 373 void Display::OnSurfaceDamaged(const SurfaceId& surface_id, bool* changed) { | 370 void Display::OnSurfaceDamaged(const SurfaceId& surface_id, bool* changed) { |
| 374 if (aggregator_ && | 371 if (aggregator_ && |
| 375 aggregator_->previous_contained_surfaces().count(surface_id)) { | 372 aggregator_->previous_contained_surfaces().count(surface_id)) { |
| 376 Surface* surface = surface_manager_->GetSurfaceForId(surface_id); | 373 Surface* surface = surface_manager_->GetSurfaceForId(surface_id); |
| 377 if (surface) { | 374 if (surface) { |
| 378 const CompositorFrame& current_frame = surface->GetEligibleFrame(); | 375 if (!surface->HasFrame() || |
| 379 if (!current_frame.delegated_frame_data || | 376 surface->GetEligibleFrame().resource_list.empty()) { |
| 380 current_frame.delegated_frame_data->resource_list.empty()) { | |
| 381 aggregator_->ReleaseResources(surface_id); | 377 aggregator_->ReleaseResources(surface_id); |
| 382 } | 378 } |
| 383 } | 379 } |
| 384 if (scheduler_) | 380 if (scheduler_) |
| 385 scheduler_->SurfaceDamaged(surface_id); | 381 scheduler_->SurfaceDamaged(surface_id); |
| 386 *changed = true; | 382 *changed = true; |
| 387 } else if (surface_id == current_surface_id_) { | 383 } else if (surface_id == current_surface_id_) { |
| 388 if (scheduler_) | 384 if (scheduler_) |
| 389 scheduler_->SurfaceDamaged(surface_id); | 385 scheduler_->SurfaceDamaged(surface_id); |
| 390 *changed = true; | 386 *changed = true; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 401 const SurfaceId& Display::CurrentSurfaceId() { | 397 const SurfaceId& Display::CurrentSurfaceId() { |
| 402 return current_surface_id_; | 398 return current_surface_id_; |
| 403 } | 399 } |
| 404 | 400 |
| 405 void Display::ForceImmediateDrawAndSwapIfPossible() { | 401 void Display::ForceImmediateDrawAndSwapIfPossible() { |
| 406 if (scheduler_) | 402 if (scheduler_) |
| 407 scheduler_->ForceImmediateSwapIfPossible(); | 403 scheduler_->ForceImmediateSwapIfPossible(); |
| 408 } | 404 } |
| 409 | 405 |
| 410 } // namespace cc | 406 } // namespace cc |
| OLD | NEW |