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

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: feedback Created 4 years, 4 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
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 {
18
19 class ScopedVisibilityImpl : public gpu::ContextSupport::ScopedVisibility {
20 public:
21 explicit ScopedVisibilityImpl(gpu::ContextSupport* context_support)
22 : initial_context_support_(context_support) {}
23 ~ScopedVisibilityImpl() { DCHECK(!initial_context_support_); }
24
25 void Release(gpu::ContextSupport* context_support) {
26 DCHECK_EQ(initial_context_support_, context_support);
27 initial_context_support_ = nullptr;
28 }
29
30 private:
31 // |initial_context_support_| is just stored/used for sanity-checking Release.
danakj 2016/08/19 18:29:55 Comment not quite true now
ericrk 2016/08/19 18:49:57 Done.
32 const gpu::ContextSupport* initial_context_support_;
33 };
34
35 } // namespace
16 36
17 TestContextSupport::TestContextSupport() 37 TestContextSupport::TestContextSupport()
18 : out_of_order_callbacks_(false), weak_ptr_factory_(this) {} 38 : out_of_order_callbacks_(false),
39 visible_clients_(0),
danakj 2016/08/19 18:29:55 can you do this in the header? (mayeb move out_of_
ericrk 2016/08/19 18:49:57 Done.
40 weak_ptr_factory_(this) {}
19 41
20 TestContextSupport::~TestContextSupport() {} 42 TestContextSupport::~TestContextSupport() {}
21 43
22 void TestContextSupport::SignalSyncToken(const gpu::SyncToken& sync_token, 44 void TestContextSupport::SignalSyncToken(const gpu::SyncToken& sync_token,
23 const base::Closure& callback) { 45 const base::Closure& callback) {
24 sync_point_callbacks_.push_back(callback); 46 sync_point_callbacks_.push_back(callback);
25 base::ThreadTaskRunnerHandle::Get()->PostTask( 47 base::ThreadTaskRunnerHandle::Get()->PostTask(
26 FROM_HERE, base::Bind(&TestContextSupport::CallAllSyncPointCallbacks, 48 FROM_HERE, base::Bind(&TestContextSupport::CallAllSyncPointCallbacks,
27 weak_ptr_factory_.GetWeakPtr())); 49 weak_ptr_factory_.GetWeakPtr()));
28 } 50 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 106 }
85 107
86 uint64_t TestContextSupport::ShareGroupTracingGUID() const { 108 uint64_t TestContextSupport::ShareGroupTracingGUID() const {
87 NOTIMPLEMENTED(); 109 NOTIMPLEMENTED();
88 return 0; 110 return 0;
89 } 111 }
90 112
91 void TestContextSupport::SetErrorMessageCallback( 113 void TestContextSupport::SetErrorMessageCallback(
92 const base::Callback<void(const char*, int32_t)>& callback) {} 114 const base::Callback<void(const char*, int32_t)>& callback) {}
93 115
94 void TestContextSupport::SetClientVisible(int client_id, bool is_visible) { 116 std::unique_ptr<gpu::ContextSupport::ScopedVisibility>
95 if (is_visible) { 117 TestContextSupport::ClientBecameVisible() {
96 visible_clients_.insert(client_id); 118 ++visible_clients_;
97 } else { 119 return base::MakeUnique<ScopedVisibilityImpl>(this);
98 auto found = visible_clients_.find(client_id); 120 }
99 if (found != visible_clients_.end()) 121
100 visible_clients_.erase(found); 122 void TestContextSupport::ClientBecameNotVisible(
101 } 123 std::unique_ptr<ScopedVisibility> visibility) {
124 DCHECK_GT(visible_clients_, 0u);
125 --visible_clients_;
126 static_cast<ScopedVisibilityImpl*>(visibility.get())->Release(this);
102 } 127 }
103 128
104 bool TestContextSupport::AnyClientsVisible() const { 129 bool TestContextSupport::AnyClientsVisible() const {
105 return !visible_clients_.empty(); 130 return visible_clients_ > 0;
106 } 131 }
107 132
108 } // namespace cc 133 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698