Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: cc/test/test_context_support.cc

Issue 2252163003: Update Context Client Visibility to use Scoped Pattern (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix webview Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/test/test_context_support.h ('k') | cc/test/test_in_process_context_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
13 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
14 15
15 namespace cc { 16 namespace cc {
17 namespace {
16 18
17 TestContextSupport::TestContextSupport() 19 // Class that DCHECKs if it is destructed without first having Release called.
18 : out_of_order_callbacks_(false), weak_ptr_factory_(this) {} 20 class ScopedVisibilityImpl : public gpu::ContextSupport::ScopedVisibility {
21 public:
22 explicit ScopedVisibilityImpl(gpu::ContextSupport* context_support)
23 : initial_context_support_(context_support) {}
24 ~ScopedVisibilityImpl() { DCHECK(!initial_context_support_); }
25
26 void Release(gpu::ContextSupport* context_support) {
27 DCHECK_EQ(initial_context_support_, context_support);
28 initial_context_support_ = nullptr;
29 }
30
31 private:
32 const gpu::ContextSupport* initial_context_support_;
33 };
34
35 } // namespace
36
37 TestContextSupport::TestContextSupport() : weak_ptr_factory_(this) {}
19 38
20 TestContextSupport::~TestContextSupport() {} 39 TestContextSupport::~TestContextSupport() {}
21 40
22 void TestContextSupport::SignalSyncToken(const gpu::SyncToken& sync_token, 41 void TestContextSupport::SignalSyncToken(const gpu::SyncToken& sync_token,
23 const base::Closure& callback) { 42 const base::Closure& callback) {
24 sync_point_callbacks_.push_back(callback); 43 sync_point_callbacks_.push_back(callback);
25 base::ThreadTaskRunnerHandle::Get()->PostTask( 44 base::ThreadTaskRunnerHandle::Get()->PostTask(
26 FROM_HERE, base::Bind(&TestContextSupport::CallAllSyncPointCallbacks, 45 FROM_HERE, base::Bind(&TestContextSupport::CallAllSyncPointCallbacks,
27 weak_ptr_factory_.GetWeakPtr())); 46 weak_ptr_factory_.GetWeakPtr()));
28 } 47 }
29 48
30 void TestContextSupport::SignalQuery(uint32_t query, 49 void TestContextSupport::SignalQuery(uint32_t query,
31 const base::Closure& callback) { 50 const base::Closure& callback) {
32 sync_point_callbacks_.push_back(callback); 51 sync_point_callbacks_.push_back(callback);
33 base::ThreadTaskRunnerHandle::Get()->PostTask( 52 base::ThreadTaskRunnerHandle::Get()->PostTask(
34 FROM_HERE, base::Bind(&TestContextSupport::CallAllSyncPointCallbacks, 53 FROM_HERE, base::Bind(&TestContextSupport::CallAllSyncPointCallbacks,
35 weak_ptr_factory_.GetWeakPtr())); 54 weak_ptr_factory_.GetWeakPtr()));
36 } 55 }
37 56
38 void TestContextSupport::SetAggressivelyFreeResources( 57 void TestContextSupport::TrimResources() {}
39 bool aggressively_free_resources) {
40 }
41 58
42 void TestContextSupport::CallAllSyncPointCallbacks() { 59 void TestContextSupport::CallAllSyncPointCallbacks() {
43 size_t size = sync_point_callbacks_.size(); 60 size_t size = sync_point_callbacks_.size();
44 if (out_of_order_callbacks_) { 61 if (out_of_order_callbacks_) {
45 for (size_t i = size; i > 0; --i) { 62 for (size_t i = size; i > 0; --i) {
46 base::ThreadTaskRunnerHandle::Get()->PostTask( 63 base::ThreadTaskRunnerHandle::Get()->PostTask(
47 FROM_HERE, sync_point_callbacks_[i - 1]); 64 FROM_HERE, sync_point_callbacks_[i - 1]);
48 } 65 }
49 } else { 66 } else {
50 for (size_t i = 0; i < size; ++i) { 67 for (size_t i = 0; i < size; ++i) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 101 }
85 102
86 uint64_t TestContextSupport::ShareGroupTracingGUID() const { 103 uint64_t TestContextSupport::ShareGroupTracingGUID() const {
87 NOTIMPLEMENTED(); 104 NOTIMPLEMENTED();
88 return 0; 105 return 0;
89 } 106 }
90 107
91 void TestContextSupport::SetErrorMessageCallback( 108 void TestContextSupport::SetErrorMessageCallback(
92 const base::Callback<void(const char*, int32_t)>& callback) {} 109 const base::Callback<void(const char*, int32_t)>& callback) {}
93 110
94 void TestContextSupport::SetClientVisible(int client_id, bool is_visible) { 111 std::unique_ptr<gpu::ContextSupport::ScopedVisibility>
95 if (is_visible) { 112 TestContextSupport::ClientBecameVisible() {
96 visible_clients_.insert(client_id); 113 ++num_visible_clients_;
97 } else { 114 return base::MakeUnique<ScopedVisibilityImpl>(this);
98 auto found = visible_clients_.find(client_id); 115 }
99 if (found != visible_clients_.end()) 116
100 visible_clients_.erase(found); 117 void TestContextSupport::ClientBecameNotVisible(
101 } 118 std::unique_ptr<ScopedVisibility> visibility) {
119 DCHECK(visibility);
120 DCHECK_GT(num_visible_clients_, 0u);
121 --num_visible_clients_;
122 static_cast<ScopedVisibilityImpl*>(visibility.get())->Release(this);
102 } 123 }
103 124
104 bool TestContextSupport::AnyClientsVisible() const { 125 bool TestContextSupport::AnyClientsVisible() const {
105 return !visible_clients_.empty(); 126 return num_visible_clients_ > 0;
106 } 127 }
107 128
108 } // namespace cc 129 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/test_context_support.h ('k') | cc/test/test_in_process_context_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698