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