| 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( | 
| 45       FROM_HERE, base::Bind(&TestContextSupport::CallAllSyncPointCallbacks, | 52       FROM_HERE, base::Bind(&TestContextSupport::CallAllSyncPointCallbacks, | 
| 46                             weak_ptr_factory_.GetWeakPtr())); | 53                             weak_ptr_factory_.GetWeakPtr())); | 
| 47 } | 54 } | 
| 48 | 55 | 
| 49 void TestContextSupport::SignalQuery(uint32_t query, | 56 void TestContextSupport::SignalQuery(uint32_t query, | 
| 50                                      const base::Closure& callback) { | 57                                      const base::Closure& callback) { | 
| 51   sync_point_callbacks_.push_back(callback); | 58   sync_point_callbacks_.push_back(callback); | 
| 52   base::ThreadTaskRunnerHandle::Get()->PostTask( | 59   base::ThreadTaskRunnerHandle::Get()->PostTask( | 
| 53       FROM_HERE, base::Bind(&TestContextSupport::CallAllSyncPointCallbacks, | 60       FROM_HERE, base::Bind(&TestContextSupport::CallAllSyncPointCallbacks, | 
| 54                             weak_ptr_factory_.GetWeakPtr())); | 61                             weak_ptr_factory_.GetWeakPtr())); | 
| 55 } | 62 } | 
| 56 | 63 | 
| 57 void TestContextSupport::SetAggressivelyFreeResources( | 64 void TestContextSupport::SetAggressivelyFreeResources( | 
| 58     bool aggressively_free_resources) { | 65     bool aggressively_free_resources) { | 
| 59 } | 66 } | 
| 60 | 67 | 
|  | 68 void TestContextSupport::TrimResources() {} | 
|  | 69 | 
| 61 void TestContextSupport::CallAllSyncPointCallbacks() { | 70 void TestContextSupport::CallAllSyncPointCallbacks() { | 
| 62   size_t size = sync_point_callbacks_.size(); | 71   size_t size = sync_point_callbacks_.size(); | 
| 63   if (out_of_order_callbacks_) { | 72   if (out_of_order_callbacks_) { | 
| 64     for (size_t i = size; i > 0; --i) { | 73     for (size_t i = size; i > 0; --i) { | 
| 65       base::ThreadTaskRunnerHandle::Get()->PostTask( | 74       base::ThreadTaskRunnerHandle::Get()->PostTask( | 
| 66           FROM_HERE, sync_point_callbacks_[i - 1]); | 75           FROM_HERE, sync_point_callbacks_[i - 1]); | 
| 67     } | 76     } | 
| 68   } else { | 77   } else { | 
| 69     for (size_t i = 0; i < size; ++i) { | 78     for (size_t i = 0; i < size; ++i) { | 
| 70       base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 79       base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 121   DCHECK(visibility); | 130   DCHECK(visibility); | 
| 122   DCHECK_GT(num_visible_clients_, 0u); | 131   DCHECK_GT(num_visible_clients_, 0u); | 
| 123   --num_visible_clients_; | 132   --num_visible_clients_; | 
| 124   static_cast<ScopedVisibilityImpl*>(visibility.get())->Release(this); | 133   static_cast<ScopedVisibilityImpl*>(visibility.get())->Release(this); | 
| 125 } | 134 } | 
| 126 | 135 | 
| 127 bool TestContextSupport::AnyClientsVisible() const { | 136 bool TestContextSupport::AnyClientsVisible() const { | 
| 128   return num_visible_clients_ > 0; | 137   return num_visible_clients_ > 0; | 
| 129 } | 138 } | 
| 130 | 139 | 
|  | 140 std::unique_ptr<gpu::ContextSupport::ScopedBusy> | 
|  | 141 TestContextSupport::ClientBecameBusy() { | 
|  | 142   return base::MakeUnique<ScopedBusyImpl>(this); | 
|  | 143 } | 
|  | 144 | 
|  | 145 void TestContextSupport::ClientBecameNotBusy(std::unique_ptr<ScopedBusy> busy) { | 
|  | 146   static_cast<ScopedBusyImpl*>(busy.get())->Release(this); | 
|  | 147 } | 
|  | 148 | 
|  | 149 void TestContextSupport::SetIdleCallback( | 
|  | 150     const base::Closure& callback, | 
|  | 151     scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner) {} | 
|  | 152 | 
| 131 }  // namespace cc | 153 }  // namespace cc | 
| OLD | NEW | 
|---|