| 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/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 void Display::DidLoseOutputSurface() { | 200 void Display::DidLoseOutputSurface() { |
| 201 if (scheduler_) | 201 if (scheduler_) |
| 202 scheduler_->OutputSurfaceLost(); | 202 scheduler_->OutputSurfaceLost(); |
| 203 // WARNING: The client may delete the Display in this method call. Do not | 203 // WARNING: The client may delete the Display in this method call. Do not |
| 204 // make any additional references to members after this call. | 204 // make any additional references to members after this call. |
| 205 client_->DisplayOutputSurfaceLost(); | 205 client_->DisplayOutputSurfaceLost(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void Display::UpdateRootSurfaceResourcesLocked() { | 208 void Display::UpdateRootSurfaceResourcesLocked() { |
| 209 Surface* surface = surface_manager_->GetSurfaceForId(current_surface_id_); | 209 Surface* surface = surface_manager_->GetSurfaceForId(current_surface_id_); |
| 210 bool root_surface_resources_locked = | 210 bool root_surface_resources_locked = !surface || !surface->GetEligibleFrame(); |
| 211 !surface || !surface->GetEligibleFrame().delegated_frame_data; | |
| 212 if (scheduler_) | 211 if (scheduler_) |
| 213 scheduler_->SetRootSurfaceResourcesLocked(root_surface_resources_locked); | 212 scheduler_->SetRootSurfaceResourcesLocked(root_surface_resources_locked); |
| 214 } | 213 } |
| 215 | 214 |
| 216 bool Display::DrawAndSwap() { | 215 bool Display::DrawAndSwap() { |
| 217 TRACE_EVENT0("cc", "Display::DrawAndSwap"); | 216 TRACE_EVENT0("cc", "Display::DrawAndSwap"); |
| 218 | 217 |
| 219 if (current_surface_id_.is_null()) { | 218 if (current_surface_id_.is_null()) { |
| 220 TRACE_EVENT_INSTANT0("cc", "No root surface.", TRACE_EVENT_SCOPE_THREAD); | 219 TRACE_EVENT_INSTANT0("cc", "No root surface.", TRACE_EVENT_SCOPE_THREAD); |
| 221 return false; | 220 return false; |
| 222 } | 221 } |
| 223 | 222 |
| 224 InitializeRenderer(); | 223 InitializeRenderer(); |
| 225 if (!output_surface_) { | 224 if (!output_surface_) { |
| 226 TRACE_EVENT_INSTANT0("cc", "No output surface", TRACE_EVENT_SCOPE_THREAD); | 225 TRACE_EVENT_INSTANT0("cc", "No output surface", TRACE_EVENT_SCOPE_THREAD); |
| 227 return false; | 226 return false; |
| 228 } | 227 } |
| 229 | 228 |
| 230 CompositorFrame frame = aggregator_->Aggregate(current_surface_id_); | 229 std::unique_ptr<CompositorFrame> frame = |
| 231 if (!frame.delegated_frame_data) { | 230 aggregator_->Aggregate(current_surface_id_); |
| 231 if (!frame) { |
| 232 TRACE_EVENT_INSTANT0("cc", "Empty aggregated frame.", | 232 TRACE_EVENT_INSTANT0("cc", "Empty aggregated frame.", |
| 233 TRACE_EVENT_SCOPE_THREAD); | 233 TRACE_EVENT_SCOPE_THREAD); |
| 234 return false; | 234 return false; |
| 235 } | 235 } |
| 236 | 236 |
| 237 // Run callbacks early to allow pipelining. | 237 // Run callbacks early to allow pipelining. |
| 238 for (const auto& id_entry : aggregator_->previous_contained_surfaces()) { | 238 for (const auto& id_entry : aggregator_->previous_contained_surfaces()) { |
| 239 Surface* surface = surface_manager_->GetSurfaceForId(id_entry.first); | 239 Surface* surface = surface_manager_->GetSurfaceForId(id_entry.first); |
| 240 if (surface) | 240 if (surface) |
| 241 surface->RunDrawCallbacks(SurfaceDrawStatus::DRAWN); | 241 surface->RunDrawCallbacks(SurfaceDrawStatus::DRAWN); |
| 242 } | 242 } |
| 243 | 243 |
| 244 DelegatedFrameData* frame_data = frame.delegated_frame_data.get(); | 244 DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); |
| 245 | 245 |
| 246 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(), | 246 frame->metadata.latency_info.insert(frame->metadata.latency_info.end(), |
| 247 stored_latency_info_.begin(), | 247 stored_latency_info_.begin(), |
| 248 stored_latency_info_.end()); | 248 stored_latency_info_.end()); |
| 249 stored_latency_info_.clear(); | 249 stored_latency_info_.clear(); |
| 250 bool have_copy_requests = false; | 250 bool have_copy_requests = false; |
| 251 for (const auto& pass : frame_data->render_pass_list) { | 251 for (const auto& pass : frame_data->render_pass_list) { |
| 252 have_copy_requests |= !pass->copy_requests.empty(); | 252 have_copy_requests |= !pass->copy_requests.empty(); |
| 253 } | 253 } |
| 254 | 254 |
| 255 gfx::Size surface_size; | 255 gfx::Size surface_size; |
| 256 bool have_damage = false; | 256 bool have_damage = false; |
| 257 if (!frame_data->render_pass_list.empty()) { | 257 if (!frame_data->render_pass_list.empty()) { |
| 258 RenderPass& last_render_pass = *frame_data->render_pass_list.back(); | 258 RenderPass& last_render_pass = *frame_data->render_pass_list.back(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 renderer_->DrawFrame(&frame_data->render_pass_list, device_scale_factor_, | 293 renderer_->DrawFrame(&frame_data->render_pass_list, device_scale_factor_, |
| 294 device_viewport_rect, device_clip_rect, | 294 device_viewport_rect, device_clip_rect, |
| 295 disable_picture_quad_image_filtering); | 295 disable_picture_quad_image_filtering); |
| 296 } else { | 296 } else { |
| 297 TRACE_EVENT_INSTANT0("cc", "Draw skipped.", TRACE_EVENT_SCOPE_THREAD); | 297 TRACE_EVENT_INSTANT0("cc", "Draw skipped.", TRACE_EVENT_SCOPE_THREAD); |
| 298 } | 298 } |
| 299 | 299 |
| 300 bool should_swap = should_draw && size_matches; | 300 bool should_swap = should_draw && size_matches; |
| 301 if (should_swap) { | 301 if (should_swap) { |
| 302 swapped_since_resize_ = true; | 302 swapped_since_resize_ = true; |
| 303 for (auto& latency : frame.metadata.latency_info) { | 303 for (auto& latency : frame->metadata.latency_info) { |
| 304 TRACE_EVENT_WITH_FLOW1("input,benchmark", "LatencyInfo.Flow", | 304 TRACE_EVENT_WITH_FLOW1("input,benchmark", "LatencyInfo.Flow", |
| 305 TRACE_ID_DONT_MANGLE(latency.trace_id()), | 305 TRACE_ID_DONT_MANGLE(latency.trace_id()), |
| 306 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, | 306 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, |
| 307 "step", "Display::DrawAndSwap"); | 307 "step", "Display::DrawAndSwap"); |
| 308 } | 308 } |
| 309 benchmark_instrumentation::IssueDisplayRenderingStatsEvent(); | 309 benchmark_instrumentation::IssueDisplayRenderingStatsEvent(); |
| 310 renderer_->SwapBuffers(std::move(frame.metadata)); | 310 renderer_->SwapBuffers(std::move(frame->metadata)); |
| 311 } else { | 311 } else { |
| 312 if (have_damage && !size_matches) | 312 if (have_damage && !size_matches) |
| 313 aggregator_->SetFullDamageForSurface(current_surface_id_); | 313 aggregator_->SetFullDamageForSurface(current_surface_id_); |
| 314 TRACE_EVENT_INSTANT0("cc", "Swap skipped.", TRACE_EVENT_SCOPE_THREAD); | 314 TRACE_EVENT_INSTANT0("cc", "Swap skipped.", TRACE_EVENT_SCOPE_THREAD); |
| 315 stored_latency_info_.insert(stored_latency_info_.end(), | 315 stored_latency_info_.insert(stored_latency_info_.end(), |
| 316 frame.metadata.latency_info.begin(), | 316 frame->metadata.latency_info.begin(), |
| 317 frame.metadata.latency_info.end()); | 317 frame->metadata.latency_info.end()); |
| 318 DidSwapBuffers(); | 318 DidSwapBuffers(); |
| 319 DidSwapBuffersComplete(); | 319 DidSwapBuffersComplete(); |
| 320 } | 320 } |
| 321 | 321 |
| 322 return true; | 322 return true; |
| 323 } | 323 } |
| 324 | 324 |
| 325 void Display::DidSwapBuffers() { | 325 void Display::DidSwapBuffers() { |
| 326 if (scheduler_) | 326 if (scheduler_) |
| 327 scheduler_->DidSwapBuffers(); | 327 scheduler_->DidSwapBuffers(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 void Display::SetFullRootLayerDamage() { | 386 void Display::SetFullRootLayerDamage() { |
| 387 if (aggregator_ && !current_surface_id_.is_null()) | 387 if (aggregator_ && !current_surface_id_.is_null()) |
| 388 aggregator_->SetFullDamageForSurface(current_surface_id_); | 388 aggregator_->SetFullDamageForSurface(current_surface_id_); |
| 389 } | 389 } |
| 390 | 390 |
| 391 void Display::OnSurfaceDamaged(SurfaceId surface_id, bool* changed) { | 391 void Display::OnSurfaceDamaged(SurfaceId surface_id, bool* changed) { |
| 392 if (aggregator_ && | 392 if (aggregator_ && |
| 393 aggregator_->previous_contained_surfaces().count(surface_id)) { | 393 aggregator_->previous_contained_surfaces().count(surface_id)) { |
| 394 Surface* surface = surface_manager_->GetSurfaceForId(surface_id); | 394 Surface* surface = surface_manager_->GetSurfaceForId(surface_id); |
| 395 if (surface) { | 395 if (surface) { |
| 396 const CompositorFrame& current_frame = surface->GetEligibleFrame(); | 396 const CompositorFrame* current_frame = surface->GetEligibleFrame(); |
| 397 if (!current_frame.delegated_frame_data || | 397 if (!current_frame || !current_frame->delegated_frame_data || |
| 398 !current_frame.delegated_frame_data->resource_list.size()) { | 398 !current_frame->delegated_frame_data->resource_list.size()) { |
| 399 aggregator_->ReleaseResources(surface_id); | 399 aggregator_->ReleaseResources(surface_id); |
| 400 } | 400 } |
| 401 } | 401 } |
| 402 if (scheduler_) | 402 if (scheduler_) |
| 403 scheduler_->SurfaceDamaged(surface_id); | 403 scheduler_->SurfaceDamaged(surface_id); |
| 404 *changed = true; | 404 *changed = true; |
| 405 } else if (surface_id == current_surface_id_) { | 405 } else if (surface_id == current_surface_id_) { |
| 406 if (scheduler_) | 406 if (scheduler_) |
| 407 scheduler_->SurfaceDamaged(surface_id); | 407 scheduler_->SurfaceDamaged(surface_id); |
| 408 *changed = true; | 408 *changed = true; |
| 409 } | 409 } |
| 410 | 410 |
| 411 if (surface_id == current_surface_id_) | 411 if (surface_id == current_surface_id_) |
| 412 UpdateRootSurfaceResourcesLocked(); | 412 UpdateRootSurfaceResourcesLocked(); |
| 413 } | 413 } |
| 414 | 414 |
| 415 SurfaceId Display::CurrentSurfaceId() { | 415 SurfaceId Display::CurrentSurfaceId() { |
| 416 return current_surface_id_; | 416 return current_surface_id_; |
| 417 } | 417 } |
| 418 | 418 |
| 419 } // namespace cc | 419 } // namespace cc |
| OLD | NEW |