Commit da618e25 authored by hamaji@chromium.org's avatar hamaji@chromium.org

Use TimeTicks instead of clock() in gpu::CommandBufferHelper

clock() returns a processor time, which does not change while
a thread is sleeping. So, Flush() would be called less often
than you expected.

TimeTicks uses a monotonic timer so this would be a better
choice than Time because TimeTicks is not affected by host's
time settings.

BUG=264856
TEST=trybots

Review URL: https://codereview.chromium.org/381473004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282593 0039d316-1c4b-4281-b951-d872f2087c98
parent 94b2586c
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "gpu/command_buffer/client/cmd_buffer_helper.h" #include "gpu/command_buffer/client/cmd_buffer_helper.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/time/time.h"
#include "gpu/command_buffer/common/command_buffer.h" #include "gpu/command_buffer/common/command_buffer.h"
#include "gpu/command_buffer/common/trace_event.h" #include "gpu/command_buffer/common/trace_event.h"
...@@ -28,7 +29,6 @@ CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer) ...@@ -28,7 +29,6 @@ CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer)
usable_(true), usable_(true),
context_lost_(false), context_lost_(false),
flush_automatically_(true), flush_automatically_(true),
last_flush_time_(0),
flush_generation_(0) { flush_generation_(0) {
} }
...@@ -151,7 +151,7 @@ void CommandBufferHelper::Flush() { ...@@ -151,7 +151,7 @@ void CommandBufferHelper::Flush() {
put_ = 0; put_ = 0;
if (usable() && last_put_sent_ != put_) { if (usable() && last_put_sent_ != put_) {
last_flush_time_ = clock(); last_flush_time_ = base::TimeTicks::Now();
last_put_sent_ = put_; last_put_sent_ = put_;
command_buffer_->Flush(put_); command_buffer_->Flush(put_);
++flush_generation_; ++flush_generation_;
...@@ -161,9 +161,11 @@ void CommandBufferHelper::Flush() { ...@@ -161,9 +161,11 @@ void CommandBufferHelper::Flush() {
#if defined(CMD_HELPER_PERIODIC_FLUSH_CHECK) #if defined(CMD_HELPER_PERIODIC_FLUSH_CHECK)
void CommandBufferHelper::PeriodicFlushCheck() { void CommandBufferHelper::PeriodicFlushCheck() {
clock_t current_time = clock(); base::TimeTicks current_time = base::TimeTicks::Now();
if (current_time - last_flush_time_ > kPeriodicFlushDelay * CLOCKS_PER_SEC) if (current_time - last_flush_time_ >
base::TimeDelta::FromMicroseconds(kPeriodicFlushDelayInMicroseconds)) {
Flush(); Flush();
}
} }
#endif #endif
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include "base/time/time.h"
#include "gpu/command_buffer/common/cmd_buffer_common.h" #include "gpu/command_buffer/common/cmd_buffer_common.h"
#include "gpu/command_buffer/common/command_buffer.h" #include "gpu/command_buffer/common/command_buffer.h"
#include "gpu/command_buffer/common/constants.h" #include "gpu/command_buffer/common/constants.h"
...@@ -20,7 +21,8 @@ namespace gpu { ...@@ -20,7 +21,8 @@ namespace gpu {
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
#define CMD_HELPER_PERIODIC_FLUSH_CHECK #define CMD_HELPER_PERIODIC_FLUSH_CHECK
const int kCommandsPerFlushCheck = 100; const int kCommandsPerFlushCheck = 100;
const float kPeriodicFlushDelay = 1.0f / (5.0f * 60.0f); const int kPeriodicFlushDelayInMicroseconds =
base::Time::kMicrosecondsPerSecond / (5 * 60);
#endif #endif
const int kAutoFlushSmall = 16; // 1/16 of the buffer const int kAutoFlushSmall = 16; // 1/16 of the buffer
...@@ -325,8 +327,7 @@ class GPU_EXPORT CommandBufferHelper { ...@@ -325,8 +327,7 @@ class GPU_EXPORT CommandBufferHelper {
bool context_lost_; bool context_lost_;
bool flush_automatically_; bool flush_automatically_;
// Using C runtime instead of base because this file cannot depend on base. base::TimeTicks last_flush_time_;
clock_t last_flush_time_;
// Incremented every time the helper flushes the command buffer. // Incremented every time the helper flushes the command buffer.
// Can be used to track when prior commands have been flushed. // Can be used to track when prior commands have been flushed.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment