| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 skipped_begin_frame_args_ = args; | 154 skipped_begin_frame_args_ = args; |
| 154 } else { | 155 } else { |
| 155 begin_frame_pending_ = true; | 156 begin_frame_pending_ = true; |
| 156 client_->BeginFrame(args); | 157 client_->BeginFrame(args); |
| 157 // args might be an alias for skipped_begin_frame_args_. | 158 // args might be an alias for skipped_begin_frame_args_. |
| 158 // Do not reset it before calling BeginFrame! | 159 // Do not reset it before calling BeginFrame! |
| 159 skipped_begin_frame_args_ = BeginFrameArgs(); | 160 skipped_begin_frame_args_ = BeginFrameArgs(); |
| 160 } | 161 } |
| 161 } | 162 } |
| 162 | 163 |
| 163 base::TimeDelta OutputSurface::AlternateRetroactiveBeginFramePeriod() { | 164 base::TimeTicks OutputSurface::RetroactiveBeginFrameDeadline() { |
| 164 return BeginFrameArgs::DefaultRetroactiveBeginFramePeriod(); | 165 // TODO(brianderson): Remove the alternative deadline once we have better |
| 166 // deadline estimations. |
| 167 base::TimeTicks alternative_deadline = |
| 168 skipped_begin_frame_args_.frame_time + |
| 169 BeginFrameArgs::DefaultRetroactiveBeginFramePeriod(); |
| 170 return std::max(skipped_begin_frame_args_.deadline, alternative_deadline); |
| 165 } | 171 } |
| 166 | 172 |
| 167 void OutputSurface::PostCheckForRetroactiveBeginFrame() { | 173 void OutputSurface::PostCheckForRetroactiveBeginFrame() { |
| 168 if (!skipped_begin_frame_args_.IsValid() || | 174 if (!skipped_begin_frame_args_.IsValid() || |
| 169 check_for_retroactive_begin_frame_pending_) | 175 check_for_retroactive_begin_frame_pending_) |
| 170 return; | 176 return; |
| 171 | 177 |
| 172 base::MessageLoop::current()->PostTask( | 178 base::MessageLoop::current()->PostTask( |
| 173 FROM_HERE, | 179 FROM_HERE, |
| 174 base::Bind(&OutputSurface::CheckForRetroactiveBeginFrame, | 180 base::Bind(&OutputSurface::CheckForRetroactiveBeginFrame, |
| 175 weak_ptr_factory_.GetWeakPtr())); | 181 weak_ptr_factory_.GetWeakPtr())); |
| 176 check_for_retroactive_begin_frame_pending_ = true; | 182 check_for_retroactive_begin_frame_pending_ = true; |
| 177 } | 183 } |
| 178 | 184 |
| 179 void OutputSurface::CheckForRetroactiveBeginFrame() { | 185 void OutputSurface::CheckForRetroactiveBeginFrame() { |
| 180 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginFrame"); | 186 TRACE_EVENT0("cc", "OutputSurface::CheckForRetroactiveBeginFrame"); |
| 181 check_for_retroactive_begin_frame_pending_ = false; | 187 check_for_retroactive_begin_frame_pending_ = false; |
| 182 base::TimeTicks now = base::TimeTicks::Now(); | 188 if (base::TimeTicks::Now() < RetroactiveBeginFrameDeadline()) |
| 183 // TODO(brianderson): Remove the alternative deadline once we have better | |
| 184 // deadline estimations. | |
| 185 base::TimeTicks alternative_deadline = | |
| 186 skipped_begin_frame_args_.frame_time + | |
| 187 AlternateRetroactiveBeginFramePeriod(); | |
| 188 if (now < skipped_begin_frame_args_.deadline || | |
| 189 now < alternative_deadline) { | |
| 190 BeginFrame(skipped_begin_frame_args_); | 189 BeginFrame(skipped_begin_frame_args_); |
| 191 } | |
| 192 } | 190 } |
| 193 | 191 |
| 194 void OutputSurface::DidSwapBuffers() { | 192 void OutputSurface::DidSwapBuffers() { |
| 195 pending_swap_buffers_++; | 193 pending_swap_buffers_++; |
| 196 TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers", | 194 TRACE_EVENT1("cc", "OutputSurface::DidSwapBuffers", |
| 197 "pending_swap_buffers_", pending_swap_buffers_); | 195 "pending_swap_buffers_", pending_swap_buffers_); |
| 198 if (frame_rate_controller_) | 196 if (frame_rate_controller_) |
| 199 frame_rate_controller_->DidSwapBuffers(); | 197 frame_rate_controller_->DidSwapBuffers(); |
| 200 PostCheckForRetroactiveBeginFrame(); | 198 PostCheckForRetroactiveBeginFrame(); |
| 201 } | 199 } |
| 202 | 200 |
| 203 void OutputSurface::OnSwapBuffersComplete(const CompositorFrameAck* ack) { | 201 void OutputSurface::OnSwapBuffersComplete(const CompositorFrameAck* ack) { |
| 204 pending_swap_buffers_--; | 202 pending_swap_buffers_--; |
| 205 TRACE_EVENT1("cc", "OutputSurface::OnSwapBuffersComplete", | 203 TRACE_EVENT1("cc", "OutputSurface::OnSwapBuffersComplete", |
| 206 "pending_swap_buffers_", pending_swap_buffers_); | 204 "pending_swap_buffers_", pending_swap_buffers_); |
| 207 client_->OnSwapBuffersComplete(ack); | 205 client_->OnSwapBuffersComplete(ack); |
| 208 if (frame_rate_controller_) | 206 if (frame_rate_controller_) |
| 209 frame_rate_controller_->DidSwapBuffersComplete(); | 207 frame_rate_controller_->DidSwapBuffersComplete(); |
| 210 PostCheckForRetroactiveBeginFrame(); | 208 PostCheckForRetroactiveBeginFrame(); |
| 211 } | 209 } |
| 212 | 210 |
| 213 void OutputSurface::DidLoseOutputSurface() { | 211 void OutputSurface::DidLoseOutputSurface() { |
| 214 TRACE_EVENT0("cc", "OutputSurface::DidLoseOutputSurface"); | 212 TRACE_EVENT0("cc", "OutputSurface::DidLoseOutputSurface"); |
| 215 begin_frame_pending_ = false; | 213 begin_frame_pending_ = false; |
| 216 pending_swap_buffers_ = 0; | 214 pending_swap_buffers_ = 0; |
| 215 skipped_begin_frame_args_ = BeginFrameArgs(); |
| 216 if (frame_rate_controller_) |
| 217 frame_rate_controller_->SetActive(false); |
| 217 client_->DidLoseOutputSurface(); | 218 client_->DidLoseOutputSurface(); |
| 218 } | 219 } |
| 219 | 220 |
| 220 void OutputSurface::SetExternalStencilTest(bool enabled) { | 221 void OutputSurface::SetExternalStencilTest(bool enabled) { |
| 221 external_stencil_test_enabled_ = enabled; | 222 external_stencil_test_enabled_ = enabled; |
| 222 } | 223 } |
| 223 | 224 |
| 224 void OutputSurface::SetExternalDrawConstraints(const gfx::Transform& transform, | 225 void OutputSurface::SetExternalDrawConstraints(const gfx::Transform& transform, |
| 225 gfx::Rect viewport, | 226 gfx::Rect viewport, |
| 226 gfx::Rect clip, | 227 gfx::Rect clip, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 "discard_backbuffer", discard_backbuffer); | 399 "discard_backbuffer", discard_backbuffer); |
| 399 // 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 |
| 400 // 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 |
| 401 // is not visible (which the renderer knows better). | 402 // is not visible (which the renderer knows better). |
| 402 if (policy.bytes_limit_when_visible) | 403 if (policy.bytes_limit_when_visible) |
| 403 client_->SetMemoryPolicy(policy); | 404 client_->SetMemoryPolicy(policy); |
| 404 client_->SetDiscardBackBufferWhenNotVisible(discard_backbuffer); | 405 client_->SetDiscardBackBufferWhenNotVisible(discard_backbuffer); |
| 405 } | 406 } |
| 406 | 407 |
| 407 } // namespace cc | 408 } // namespace cc |
| OLD | NEW |