Skip to content

Commit

Permalink
cc: Change #if !defined(NDEBUG) to #if DCHECK_IS_ON.
Browse files Browse the repository at this point in the history
Some places in cc enabled DCHECK code only when in a debug build since
they added member variables to classes in order to perform their
checks, and we could not check for DCHECK at compile time.

Since we can now, we can guard these DCHECKS with DCHECK_IS_ON. Yay!

DCHECK_IS_ON is always defined by base/logging.h. It is set to 1 when
DCHECKS are enabled, and 0 otherwise.

R=enne
BUG=350462

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257761 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
danakj@chromium.org committed Mar 18, 2014
1 parent 9d11b52 commit 767f38d
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 48 deletions.
10 changes: 5 additions & 5 deletions cc/base/completion_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ class CompletionEvent {
public:
CompletionEvent()
: event_(false /* manual_reset */, false /* initially_signaled */) {
#ifndef NDEBUG
#if DCHECK_IS_ON
waited_ = false;
signaled_ = false;
#endif
}

~CompletionEvent() {
#ifndef NDEBUG
#if DCHECK_IS_ON
DCHECK(waited_);
DCHECK(signaled_);
#endif
}

void Wait() {
#ifndef NDEBUG
#if DCHECK_IS_ON
DCHECK(!waited_);
waited_ = true;
#endif
Expand All @@ -42,7 +42,7 @@ class CompletionEvent {
}

void Signal() {
#ifndef NDEBUG
#if DCHECK_IS_ON
DCHECK(!signaled_);
signaled_ = true;
#endif
Expand All @@ -51,7 +51,7 @@ class CompletionEvent {

private:
base::WaitableEvent event_;
#ifndef NDEBUG
#if DCHECK_IS_ON
// Used to assert that Wait() and Signal() are each called exactly once.
bool waited_;
bool signaled_;
Expand Down
9 changes: 3 additions & 6 deletions cc/layers/picture_layer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "cc/test/fake_proxy.h"
#include "cc/test/impl_side_painting_settings.h"
#include "cc/trees/occlusion_tracker.h"
#include "cc/trees/single_thread_proxy.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace cc {
Expand Down Expand Up @@ -45,10 +46,9 @@ TEST(PictureLayerTest, NoTilesIfEmptyBounds) {
// a layer with empty bounds.

FakeProxy proxy;
#ifndef NDEBUG
proxy.SetCurrentThreadIsImplThread(true);
#endif
{
DebugScopedSetImplThread impl_thread(&proxy);

FakeLayerTreeHostImpl host_impl(ImplSidePaintingSettings(), &proxy);
host_impl.CreatePendingTree();
scoped_ptr<FakePictureLayerImpl> layer_impl =
Expand All @@ -60,9 +60,6 @@ TEST(PictureLayerTest, NoTilesIfEmptyBounds) {
EXPECT_TRUE(layer_impl->pile()->size() == gfx::Size(0, 0));
EXPECT_TRUE(layer_impl->pile()->recorded_region().IsEmpty());
}
#ifndef NDEBUG
proxy.SetCurrentThreadIsImplThread(false);
#endif
}

} // namespace
Expand Down
9 changes: 5 additions & 4 deletions cc/resources/prioritized_resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ PrioritizedResource::Backing::Backing(unsigned id,
was_above_priority_cutoff_at_last_priority_update_(false),
in_drawing_impl_tree_(false),
in_parent_compositor_(false),
#ifdef NDEBUG
resource_has_been_deleted_(false) {}
#if !DCHECK_IS_ON
resource_has_been_deleted_(false) {
#else
resource_has_been_deleted_(false),
resource_provider_(resource_provider) {}
resource_provider_(resource_provider) {
#endif
}

PrioritizedResource::Backing::~Backing() {
DCHECK(!owner_);
Expand All @@ -142,7 +143,7 @@ void PrioritizedResource::Backing::DeleteResource(
ResourceProvider* resource_provider) {
DCHECK(!proxy() || proxy()->IsImplThread());
DCHECK(!resource_has_been_deleted_);
#ifndef NDEBUG
#if DCHECK_IS_ON
DCHECK(resource_provider == resource_provider_);
#endif

Expand Down
2 changes: 1 addition & 1 deletion cc/resources/prioritized_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class CC_EXPORT PrioritizedResource {

bool resource_has_been_deleted_;

#ifndef NDEBUG
#if DCHECK_IS_ON
ResourceProvider* resource_provider_;
#endif
DISALLOW_COPY_AND_ASSIGN(Backing);
Expand Down
4 changes: 2 additions & 2 deletions cc/resources/prioritized_resource_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void PrioritizedResourceManager::EvictFirstBackingResource(
}

void PrioritizedResourceManager::AssertInvariants() {
#ifndef NDEBUG
#if DCHECK_IS_ON
DCHECK(proxy_->IsImplThread() && proxy_->IsMainThreadBlocked());

// If we hit any of these asserts, there is a bug in this class. To see
Expand Down Expand Up @@ -541,7 +541,7 @@ void PrioritizedResourceManager::AssertInvariants() {
DCHECK(backing->CanBeRecycledIfNotInExternalUse());
previous_backing = backing;
}
#endif
#endif // DCHECK_IS_ON
}

const Proxy* PrioritizedResourceManager::ProxyForDebug() const {
Expand Down
2 changes: 0 additions & 2 deletions cc/resources/prioritized_resource_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@ class PrioritizedResourceTest : public testing::Test {

void ResourceManagerAssertInvariants(
PrioritizedResourceManager* resource_manager) {
#ifndef NDEBUG
DebugScopedSetImplThreadAndMainThreadBlocked
impl_thread_and_main_thread_blocked(&proxy_);
resource_manager->AssertInvariants();
#endif
}

bool TextureBackingIsAbovePriorityCutoff(PrioritizedResource* texture) {
Expand Down
6 changes: 3 additions & 3 deletions cc/resources/scoped_resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void ScopedResource::Allocate(const gfx::Size& size,
set_id(resource_provider_->CreateResource(
size, GL_CLAMP_TO_EDGE, hint, format));

#ifndef NDEBUG
#if DCHECK_IS_ON
allocate_thread_id_ = base::PlatformThread::CurrentId();
#endif
}
Expand All @@ -44,14 +44,14 @@ void ScopedResource::AllocateManaged(const gfx::Size& size,
ResourceProvider::TextureUsageAny,
format));

#ifndef NDEBUG
#if DCHECK_IS_ON
allocate_thread_id_ = base::PlatformThread::CurrentId();
#endif
}

void ScopedResource::Free() {
if (id()) {
#ifndef NDEBUG
#if DCHECK_IS_ON
DCHECK(allocate_thread_id_ == base::PlatformThread::CurrentId());
#endif
resource_provider_->DeleteResource(id());
Expand Down
4 changes: 2 additions & 2 deletions cc/resources/scoped_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "cc/base/cc_export.h"
#include "cc/resources/resource.h"

#ifndef NDEBUG
#if DCHECK_IS_ON
#include "base/threading/platform_thread.h"
#endif

Expand Down Expand Up @@ -40,7 +40,7 @@ class CC_EXPORT ScopedResource : public Resource {
private:
ResourceProvider* resource_provider_;

#ifndef NDEBUG
#if DCHECK_IS_ON
base::PlatformThreadId allocate_thread_id_;
#endif

Expand Down
8 changes: 4 additions & 4 deletions cc/trees/layer_tree_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ LayerTreeHostImpl::LayerTreeHostImpl(
rendering_stats_instrumentation_(rendering_stats_instrumentation),
micro_benchmark_controller_(this),
need_to_update_visible_tiles_before_draw_(false),
#ifndef NDEBUG
#if DCHECK_IS_ON
did_lose_called_(false),
#endif
shared_bitmap_manager_(manager),
Expand Down Expand Up @@ -886,7 +886,7 @@ DrawSwapReadbackResult::DrawResult LayerTreeHostImpl::CalculateRenderPasses(
output_surface_->capabilities().draw_and_swap_full_viewport_every_frame)
draw_result = DrawSwapReadbackResult::DRAW_SUCCESS;

#ifndef NDEBUG
#if DCHECK_IS_ON
for (size_t i = 0; i < frame->render_passes.size(); ++i) {
for (size_t j = 0; j < frame->render_passes[i]->quad_list.size(); ++j)
DCHECK(frame->render_passes[i]->quad_list[j]->shared_quad_state);
Expand Down Expand Up @@ -1529,7 +1529,7 @@ void LayerTreeHostImpl::DidLoseOutputSurface() {
// important) in production. We should adjust the test to not need this.
if (renderer_)
client_->DidLoseOutputSurfaceOnImplThread();
#ifndef NDEBUG
#if DCHECK_IS_ON
did_lose_called_ = true;
#endif
}
Expand Down Expand Up @@ -1792,7 +1792,7 @@ void LayerTreeHostImpl::EnforceZeroBudget(bool zero_budget) {

bool LayerTreeHostImpl::InitializeRenderer(
scoped_ptr<OutputSurface> output_surface) {
#ifndef NDEBUG
#if DCHECK_IS_ON
DCHECK(!renderer_ || did_lose_called_);
#endif

Expand Down
2 changes: 1 addition & 1 deletion cc/trees/layer_tree_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ class CC_EXPORT LayerTreeHostImpl
MicroBenchmarkControllerImpl micro_benchmark_controller_;

bool need_to_update_visible_tiles_before_draw_;
#ifndef NDEBUG
#if DCHECK_IS_ON
bool did_lose_called_;
#endif

Expand Down
20 changes: 10 additions & 10 deletions cc/trees/proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ base::SingleThreadTaskRunner* Proxy::ImplThreadTaskRunner() const {
}

bool Proxy::IsMainThread() const {
#ifndef NDEBUG
#if DCHECK_IS_ON
DCHECK(main_task_runner_.get());
if (impl_thread_is_overridden_)
return false;
Expand All @@ -31,7 +31,7 @@ bool Proxy::IsMainThread() const {
}

bool Proxy::IsImplThread() const {
#ifndef NDEBUG
#if DCHECK_IS_ON
if (impl_thread_is_overridden_)
return true;
if (!impl_task_runner_.get())
Expand All @@ -42,36 +42,36 @@ bool Proxy::IsImplThread() const {
#endif
}

#ifndef NDEBUG
#if DCHECK_IS_ON
void Proxy::SetCurrentThreadIsImplThread(bool is_impl_thread) {
impl_thread_is_overridden_ = is_impl_thread;
}
#endif

bool Proxy::IsMainThreadBlocked() const {
#ifndef NDEBUG
#if DCHECK_IS_ON
return is_main_thread_blocked_;
#else
return true;
#endif
}

#ifndef NDEBUG
#if DCHECK_IS_ON
void Proxy::SetMainThreadBlocked(bool is_main_thread_blocked) {
is_main_thread_blocked_ = is_main_thread_blocked;
}
#endif

Proxy::Proxy(
scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner)
Proxy::Proxy(scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner)
: main_task_runner_(base::MessageLoopProxy::current()),
#ifdef NDEBUG
impl_task_runner_(impl_task_runner) {}
#if !DCHECK_IS_ON
impl_task_runner_(impl_task_runner) {
#else
impl_task_runner_(impl_task_runner),
impl_thread_is_overridden_(false),
is_main_thread_blocked_(false) {}
is_main_thread_blocked_(false) {
#endif
}

Proxy::~Proxy() {
DCHECK(IsMainThread());
Expand Down
6 changes: 3 additions & 3 deletions cc/trees/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CC_EXPORT Proxy {
bool IsMainThread() const;
bool IsImplThread() const;
bool IsMainThreadBlocked() const;
#ifndef NDEBUG
#if DCHECK_IS_ON
void SetMainThreadBlocked(bool is_main_thread_blocked);
void SetCurrentThreadIsImplThread(bool is_impl_thread);
#endif
Expand Down Expand Up @@ -112,15 +112,15 @@ class CC_EXPORT Proxy {
private:
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_;
#ifndef NDEBUG
#if DCHECK_IS_ON
bool impl_thread_is_overridden_;
bool is_main_thread_blocked_;
#endif

DISALLOW_COPY_AND_ASSIGN(Proxy);
};

#ifndef NDEBUG
#if DCHECK_IS_ON
class DebugScopedSetMainThreadBlocked {
public:
explicit DebugScopedSetMainThreadBlocked(Proxy* proxy) : proxy_(proxy) {
Expand Down
2 changes: 1 addition & 1 deletion cc/trees/single_thread_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) {

layer_tree_host_impl_->CommitComplete();

#ifndef NDEBUG
#if DCHECK_IS_ON
// In the single-threaded case, the scale and scroll deltas should never be
// touched on the impl layer tree.
scoped_ptr<ScrollAndScaleSet> scroll_info =
Expand Down
8 changes: 4 additions & 4 deletions cc/trees/single_thread_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ class SingleThreadProxy : public Proxy, LayerTreeHostImplClient {
class DebugScopedSetImplThread {
public:
explicit DebugScopedSetImplThread(Proxy* proxy) : proxy_(proxy) {
#ifndef NDEBUG
#if DCHECK_IS_ON
previous_value_ = proxy_->impl_thread_is_overridden_;
proxy_->SetCurrentThreadIsImplThread(true);
#endif
}
~DebugScopedSetImplThread() {
#ifndef NDEBUG
#if DCHECK_IS_ON
proxy_->SetCurrentThreadIsImplThread(previous_value_);
#endif
}
Expand All @@ -149,13 +149,13 @@ class DebugScopedSetImplThread {
class DebugScopedSetMainThread {
public:
explicit DebugScopedSetMainThread(Proxy* proxy) : proxy_(proxy) {
#ifndef NDEBUG
#if DCHECK_IS_ON
previous_value_ = proxy_->impl_thread_is_overridden_;
proxy_->SetCurrentThreadIsImplThread(false);
#endif
}
~DebugScopedSetMainThread() {
#ifndef NDEBUG
#if DCHECK_IS_ON
proxy_->SetCurrentThreadIsImplThread(previous_value_);
#endif
}
Expand Down

0 comments on commit 767f38d

Please sign in to comment.