| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 skipped_begin_frame_args_ = args; | 155 skipped_begin_frame_args_ = args; |
| 155 } else { | 156 } else { |
| 156 begin_frame_pending_ = true; | 157 begin_frame_pending_ = true; |
| 157 client_->BeginFrame(args); | 158 client_->BeginFrame(args); |
| 158 // args might be an alias for skipped_begin_frame_args_. | 159 // args might be an alias for skipped_begin_frame_args_. |
| 159 // Do not reset it before calling BeginFrame! | 160 // Do not reset it before calling BeginFrame! |
| 160 skipped_begin_frame_args_ = BeginFrameArgs(); | 161 skipped_begin_frame_args_ = BeginFrameArgs(); |
| 161 } | 162 } |
| 162 } | 163 } |
| 163 | 164 |
| 164 base::TimeDelta OutputSurface::AlternateRetroactiveBeginFramePeriod() { | 165 base::TimeTicks OutputSurface::RetroactiveBeginFrameDeadline() { |
| 165 return BeginFrameArgs::DefaultRetroactiveBeginFramePeriod(); | 166 // TODO(brianderson): Remove the alternative deadline once we have better |
| 167 // deadline estimations. |
| 168 base::TimeTicks alternative_deadline = |
| 169 skipped_begin_frame_args_.frame_time + |
| 170 BeginFrameArgs::DefaultRetroactiveBeginFramePeriod(); |
| 171 return std::max(skipped_begin_frame_args_.deadline, alternative_deadline); |
| 166 } | 172 } |
| 167 | 173 |
| 168 void OutputSurface::PostCheckForRetroactiveBeginFrame() { | 174 void OutputSurface::PostCheckForRetroactiveBeginFrame() { |
| 169 if (!skipped_begin_frame_args_.IsValid() || | 175 if (!skipped_begin_frame_args_.IsValid() || |
| 170 check_for_retroactive_begin_frame_pending_) | 176 check_for_retroactive_begin_frame_pending_) |
| 171 return; | 177 return; |
| 172 | 178 |
| 173 base::MessageLoop::current()->PostTask( | 179 base::MessageLoop::current()->PostTask( |
| 174 FROM_HERE, | 180 FROM_HERE, |
| 175 base::Bind(&OutputSurface::CheckForRetroactiveBeginFrame, | 181 base::Bind(&OutputSurface::CheckForRetroactiveBeginFrame, |
| 176 weak_ptr_factory_.GetWeakPtr())); | 182 weak_ptr_factory_.GetWeakPtr())); |
| 177 check_for_retroactive_begin_frame_pending_ = true; | 183 check_for_retroactive_begin_frame_pending_ = true; |
| 178 } | 184 } |
| 179 | 185 |
| 180 void OutputSurface::CheckForRetroactiveBeginFrame() { | 186 void OutputSurface::CheckForRetroactiveBeginFrame() { |
| 181 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginFrame"); | 187 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginFrame"); |
| 182 check_for_retroactive_begin_frame_pending_ = false; | 188 check_for_retroactive_begin_frame_pending_ = false; |
| 183 base::TimeTicks now = base::TimeTicks::Now(); | 189 if (base::TimeTicks::Now() < RetroactiveBeginFrameDeadline()) |
| 184 // TODO(brianderson): Remove the alternative deadline once we have better | |
| 185 // deadline estimations. | |
| 186 base::TimeTicks alternative_deadline = | |
| 187 skipped_begin_frame_args_.frame_time + | |
| 188 AlternateRetroactiveBeginFramePeriod(); | |
| 189 if (now < skipped_begin_frame_args_.deadline || | |
| 190 now < alternative_deadline) { | |
| 191 BeginFrame(skipped_begin_frame_args_); | 190 BeginFrame(skipped_begin_frame_args_); |
| 192 } | |
| 193 } | 191 } |
| 194 | 192 |
| 195 void OutputSurface::DidSwapBuffers() { | 193 void OutputSurface::DidSwapBuffers() { |
| 196 begin_frame_pending_ = false; | 194 begin_frame_pending_ = false; |
| 197 pending_swap_buffers_++; | 195 pending_swap_buffers_++; |
| 198 TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers", | 196 TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers", |
| 199 "pending_swap_buffers_", pending_swap_buffers_); | 197 "pending_swap_buffers_", pending_swap_buffers_); |
| 200 if (frame_rate_controller_) | 198 if (frame_rate_controller_) |
| 201 frame_rate_controller_->DidSwapBuffers(); | 199 frame_rate_controller_->DidSwapBuffers(); |
| 202 PostCheckForRetroactiveBeginFrame(); | 200 PostCheckForRetroactiveBeginFrame(); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 "discard_backbuffer", discard_backbuffer); | 399 "discard_backbuffer", discard_backbuffer); |
| 402 // Just ignore the memory manager when it says to set the limit to zero | 400 // Just ignore the memory manager when it says to set the limit to zero |
| 403 // bytes. This will happen when the memory manager thinks that the renderer | 401 // bytes. This will happen when the memory manager thinks that the renderer |
| 404 // is not visible (which the renderer knows better). | 402 // is not visible (which the renderer knows better). |
| 405 if (policy.bytes_limit_when_visible) | 403 if (policy.bytes_limit_when_visible) |
| 406 client_->SetMemoryPolicy(policy); | 404 client_->SetMemoryPolicy(policy); |
| 407 client_->SetDiscardBackBufferWhenNotVisible(discard_backbuffer); | 405 client_->SetDiscardBackBufferWhenNotVisible(discard_backbuffer); |
| 408 } | 406 } |
| 409 | 407 |
| 410 } // namespace cc | 408 } // namespace cc |
| OLD | NEW |