| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/output/output_surface.h" | 5 #include "cc/output/output_surface.h" |
| 6 | 6 |
| 7 #include <algorithm> |
| 7 #include <set> | 8 #include <set> |
| 8 #include <string> | 9 #include <string> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 15 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 skipped_begin_frame_args_ = args; | 213 skipped_begin_frame_args_ = args; |
| 213 } else { | 214 } else { |
| 214 begin_frame_pending_ = true; | 215 begin_frame_pending_ = true; |
| 215 client_->BeginFrame(args); | 216 client_->BeginFrame(args); |
| 216 // args might be an alias for skipped_begin_frame_args_. | 217 // args might be an alias for skipped_begin_frame_args_. |
| 217 // Do not reset it before calling BeginFrame! | 218 // Do not reset it before calling BeginFrame! |
| 218 skipped_begin_frame_args_ = BeginFrameArgs(); | 219 skipped_begin_frame_args_ = BeginFrameArgs(); |
| 219 } | 220 } |
| 220 } | 221 } |
| 221 | 222 |
| 222 base::TimeDelta OutputSurface::RetroactiveBeginFramePeriod() { | 223 base::TimeTicks OutputSurface::RetroactiveBeginFrameDeadline() { |
| 223 return BeginFrameArgs::DefaultRetroactiveBeginFramePeriod(); | 224 base::TimeTicks alternative_deadline = |
| 225 skipped_begin_frame_args_.frame_time + |
| 226 BeginFrameArgs::DefaultRetroactiveBeginFramePeriod(); |
| 227 return std::max(skipped_begin_frame_args_.deadline, alternative_deadline); |
| 224 } | 228 } |
| 225 | 229 |
| 226 void OutputSurface::PostCheckForRetroactiveBeginFrame() { | 230 void OutputSurface::PostCheckForRetroactiveBeginFrame() { |
| 227 if (!skipped_begin_frame_args_.IsValid() || | 231 if (!skipped_begin_frame_args_.IsValid() || |
| 228 check_for_retroactive_begin_frame_pending_) | 232 check_for_retroactive_begin_frame_pending_) |
| 229 return; | 233 return; |
| 230 | 234 |
| 231 base::MessageLoop::current()->PostTask( | 235 base::MessageLoop::current()->PostTask( |
| 232 FROM_HERE, | 236 FROM_HERE, |
| 233 base::Bind(&OutputSurface::CheckForRetroactiveBeginFrame, | 237 base::Bind(&OutputSurface::CheckForRetroactiveBeginFrame, |
| 234 weak_ptr_factory_.GetWeakPtr())); | 238 weak_ptr_factory_.GetWeakPtr())); |
| 235 check_for_retroactive_begin_frame_pending_ = true; | 239 check_for_retroactive_begin_frame_pending_ = true; |
| 236 } | 240 } |
| 237 | 241 |
| 238 void OutputSurface::CheckForRetroactiveBeginFrame() { | 242 void OutputSurface::CheckForRetroactiveBeginFrame() { |
| 239 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginFrame"); | 243 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginFrame"); |
| 240 check_for_retroactive_begin_frame_pending_ = false; | 244 check_for_retroactive_begin_frame_pending_ = false; |
| 241 base::TimeTicks now = base::TimeTicks::Now(); | 245 if (base::TimeTicks::Now() < RetroactiveBeginFrameDeadline()) |
| 242 base::TimeTicks alternative_deadline = | |
| 243 skipped_begin_frame_args_.frame_time + | |
| 244 RetroactiveBeginFramePeriod(); | |
| 245 if (now < skipped_begin_frame_args_.deadline || | |
| 246 now < alternative_deadline) { | |
| 247 BeginFrame(skipped_begin_frame_args_); | 246 BeginFrame(skipped_begin_frame_args_); |
| 248 } | |
| 249 } | 247 } |
| 250 | 248 |
| 251 void OutputSurface::DidSwapBuffers() { | 249 void OutputSurface::DidSwapBuffers() { |
| 252 begin_frame_pending_ = false; | 250 begin_frame_pending_ = false; |
| 253 pending_swap_buffers_++; | 251 pending_swap_buffers_++; |
| 254 TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers", | 252 TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers", |
| 255 "pending_swap_buffers_", pending_swap_buffers_); | 253 "pending_swap_buffers_", pending_swap_buffers_); |
| 256 if (frame_rate_controller_) | 254 if (frame_rate_controller_) |
| 257 frame_rate_controller_->DidSwapBuffers(); | 255 frame_rate_controller_->DidSwapBuffers(); |
| 258 PostCheckForRetroactiveBeginFrame(); | 256 PostCheckForRetroactiveBeginFrame(); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 "discard_backbuffer", discard_backbuffer); | 448 "discard_backbuffer", discard_backbuffer); |
| 451 // Just ignore the memory manager when it says to set the limit to zero | 449 // Just ignore the memory manager when it says to set the limit to zero |
| 452 // bytes. This will happen when the memory manager thinks that the renderer | 450 // bytes. This will happen when the memory manager thinks that the renderer |
| 453 // is not visible (which the renderer knows better). | 451 // is not visible (which the renderer knows better). |
| 454 if (policy.bytes_limit_when_visible) | 452 if (policy.bytes_limit_when_visible) |
| 455 client_->SetMemoryPolicy(policy); | 453 client_->SetMemoryPolicy(policy); |
| 456 client_->SetDiscardBackBufferWhenNotVisible(discard_backbuffer); | 454 client_->SetDiscardBackBufferWhenNotVisible(discard_backbuffer); |
| 457 } | 455 } |
| 458 | 456 |
| 459 } // namespace cc | 457 } // namespace cc |
| OLD | NEW |