| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/test/test_context_support.h" | 5 #include "cc/test/test_context_support.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 | 15 |
| 16 namespace cc { | 16 namespace cc { |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Class that DCHECKs if it is destructed without first having Release called. | 19 // Class that DCHECKs if it is destructed without first having Release called. |
| 20 class ScopedVisibilityImpl : public gpu::ContextSupport::ScopedVisibility { | 20 template <typename T> |
| 21 class ScopedContextSupportToken : public T { |
| 21 public: | 22 public: |
| 22 explicit ScopedVisibilityImpl(gpu::ContextSupport* context_support) | 23 explicit ScopedContextSupportToken(gpu::ContextSupport* context_support) |
| 23 : initial_context_support_(context_support) {} | 24 : initial_context_support_(context_support) {} |
| 24 ~ScopedVisibilityImpl() { DCHECK(!initial_context_support_); } | 25 |
| 26 ~ScopedContextSupportToken() { DCHECK(!initial_context_support_); } |
| 25 | 27 |
| 26 void Release(gpu::ContextSupport* context_support) { | 28 void Release(gpu::ContextSupport* context_support) { |
| 27 DCHECK_EQ(initial_context_support_, context_support); | 29 DCHECK_EQ(initial_context_support_, context_support); |
| 28 initial_context_support_ = nullptr; | 30 initial_context_support_ = nullptr; |
| 29 } | 31 } |
| 30 | 32 |
| 31 private: | 33 private: |
| 32 const gpu::ContextSupport* initial_context_support_; | 34 const gpu::ContextSupport* initial_context_support_; |
| 33 }; | 35 }; |
| 34 | 36 |
| 37 using ScopedVisibilityImpl = |
| 38 ScopedContextSupportToken<gpu::ContextSupport::ScopedVisibility>; |
| 39 using ScopedBusyImpl = |
| 40 ScopedContextSupportToken<gpu::ContextSupport::ScopedBusy>; |
| 41 |
| 35 } // namespace | 42 } // namespace |
| 36 | 43 |
| 37 TestContextSupport::TestContextSupport() : weak_ptr_factory_(this) {} | 44 TestContextSupport::TestContextSupport() : weak_ptr_factory_(this) {} |
| 38 | 45 |
| 39 TestContextSupport::~TestContextSupport() {} | 46 TestContextSupport::~TestContextSupport() {} |
| 40 | 47 |
| 41 void TestContextSupport::SignalSyncToken(const gpu::SyncToken& sync_token, | 48 void TestContextSupport::SignalSyncToken(const gpu::SyncToken& sync_token, |
| 42 const base::Closure& callback) { | 49 const base::Closure& callback) { |
| 43 sync_point_callbacks_.push_back(callback); | 50 sync_point_callbacks_.push_back(callback); |
| 44 base::ThreadTaskRunnerHandle::Get()->PostTask( | 51 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 DCHECK(visibility); | 126 DCHECK(visibility); |
| 120 DCHECK_GT(num_visible_clients_, 0u); | 127 DCHECK_GT(num_visible_clients_, 0u); |
| 121 --num_visible_clients_; | 128 --num_visible_clients_; |
| 122 static_cast<ScopedVisibilityImpl*>(visibility.get())->Release(this); | 129 static_cast<ScopedVisibilityImpl*>(visibility.get())->Release(this); |
| 123 } | 130 } |
| 124 | 131 |
| 125 bool TestContextSupport::AnyClientsVisible() const { | 132 bool TestContextSupport::AnyClientsVisible() const { |
| 126 return num_visible_clients_ > 0; | 133 return num_visible_clients_ > 0; |
| 127 } | 134 } |
| 128 | 135 |
| 136 std::unique_ptr<gpu::ContextSupport::ScopedBusy> |
| 137 TestContextSupport::ClientBecameBusy() { |
| 138 return base::MakeUnique<ScopedBusyImpl>(this); |
| 139 } |
| 140 |
| 141 void TestContextSupport::ClientBecameNotBusy(std::unique_ptr<ScopedBusy> busy) { |
| 142 static_cast<ScopedBusyImpl*>(busy.get())->Release(this); |
| 143 } |
| 144 |
| 145 void TestContextSupport::SetIdleCallback(const base::Closure& callback) {} |
| 146 |
| 129 } // namespace cc | 147 } // namespace cc |
| OLD | NEW |