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

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

Issue 2278283003: Refactor client visibility handling (Closed)
Patch Set: feedback 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
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_provider.h" 5 #include "cc/test/test_context_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <set> 10 #include <set>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/callback_helpers.h" 14 #include "base/callback_helpers.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "cc/output/context_cache_controller.h"
17 #include "cc/test/test_gles2_interface.h" 18 #include "cc/test/test_gles2_interface.h"
18 #include "cc/test/test_web_graphics_context_3d.h" 19 #include "cc/test/test_web_graphics_context_3d.h"
19 #include "third_party/skia/include/gpu/GrContext.h" 20 #include "third_party/skia/include/gpu/GrContext.h"
20 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" 21 #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
21 22
22 namespace cc { 23 namespace cc {
23 24
24 // static 25 // static
25 scoped_refptr<TestContextProvider> TestContextProvider::Create() { 26 scoped_refptr<TestContextProvider> TestContextProvider::Create() {
26 return new TestContextProvider(base::MakeUnique<TestContextSupport>(), 27 auto support = base::MakeUnique<TestContextSupport>();
27 base::MakeUnique<TestGLES2Interface>(), 28 auto cache_controller =
28 TestWebGraphicsContext3D::Create()); 29 base::MakeUnique<ContextCacheController>(support.get());
30 return new TestContextProvider(
31 std::move(support), base::MakeUnique<TestGLES2Interface>(),
32 TestWebGraphicsContext3D::Create(), std::move(cache_controller));
29 } 33 }
30 34
31 // static 35 // static
32 scoped_refptr<TestContextProvider> TestContextProvider::CreateWorker() { 36 scoped_refptr<TestContextProvider> TestContextProvider::CreateWorker() {
37 auto support = base::MakeUnique<TestContextSupport>();
38 auto cache_controller =
39 base::MakeUnique<ContextCacheController>(support.get());
33 scoped_refptr<TestContextProvider> worker_context_provider( 40 scoped_refptr<TestContextProvider> worker_context_provider(
34 new TestContextProvider(base::MakeUnique<TestContextSupport>(), 41 new TestContextProvider(
35 base::MakeUnique<TestGLES2Interface>(), 42 std::move(support), base::MakeUnique<TestGLES2Interface>(),
36 TestWebGraphicsContext3D::Create())); 43 TestWebGraphicsContext3D::Create(), std::move(cache_controller)));
37 // Worker contexts are bound to the thread they are created on. 44 // Worker contexts are bound to the thread they are created on.
38 if (!worker_context_provider->BindToCurrentThread()) 45 if (!worker_context_provider->BindToCurrentThread())
39 return nullptr; 46 return nullptr;
40 return worker_context_provider; 47 return worker_context_provider;
41 } 48 }
42 49
43 // static 50 // static
44 scoped_refptr<TestContextProvider> TestContextProvider::Create( 51 scoped_refptr<TestContextProvider> TestContextProvider::Create(
45 std::unique_ptr<TestWebGraphicsContext3D> context) { 52 std::unique_ptr<TestWebGraphicsContext3D> context) {
46 DCHECK(context); 53 DCHECK(context);
47 return new TestContextProvider(base::MakeUnique<TestContextSupport>(), 54 auto support = base::MakeUnique<TestContextSupport>();
48 base::MakeUnique<TestGLES2Interface>(), 55 auto cache_controller =
49 std::move(context)); 56 base::MakeUnique<ContextCacheController>(support.get());
57 return new TestContextProvider(
58 std::move(support), base::MakeUnique<TestGLES2Interface>(),
59 std::move(context), std::move(cache_controller));
50 } 60 }
51 61
52 // static 62 // static
53 scoped_refptr<TestContextProvider> TestContextProvider::Create( 63 scoped_refptr<TestContextProvider> TestContextProvider::Create(
54 std::unique_ptr<TestGLES2Interface> gl) { 64 std::unique_ptr<TestGLES2Interface> gl) {
55 DCHECK(gl); 65 DCHECK(gl);
56 return new TestContextProvider(base::MakeUnique<TestContextSupport>(), 66 auto support = base::MakeUnique<TestContextSupport>();
57 std::move(gl), 67 auto cache_controller =
58 TestWebGraphicsContext3D::Create()); 68 base::MakeUnique<ContextCacheController>(support.get());
69 return new TestContextProvider(std::move(support), std::move(gl),
70 TestWebGraphicsContext3D::Create(),
71 std::move(cache_controller));
59 } 72 }
60 73
61 // static 74 // static
62 scoped_refptr<TestContextProvider> TestContextProvider::Create( 75 scoped_refptr<TestContextProvider> TestContextProvider::Create(
63 std::unique_ptr<TestWebGraphicsContext3D> context, 76 std::unique_ptr<TestWebGraphicsContext3D> context,
64 std::unique_ptr<TestContextSupport> support) { 77 std::unique_ptr<TestContextSupport> support) {
65 DCHECK(context); 78 DCHECK(context);
66 DCHECK(support); 79 DCHECK(support);
67 return new TestContextProvider(std::move(support), 80 auto cache_controller =
68 base::MakeUnique<TestGLES2Interface>(), 81 base::MakeUnique<ContextCacheController>(support.get());
69 std::move(context)); 82 return new TestContextProvider(
83 std::move(support), base::MakeUnique<TestGLES2Interface>(),
84 std::move(context), std::move(cache_controller));
85 }
86
87 // static
88 scoped_refptr<TestContextProvider> TestContextProvider::Create(
89 std::unique_ptr<TestWebGraphicsContext3D> context,
90 std::unique_ptr<TestContextSupport> support,
91 std::unique_ptr<ContextCacheController> cache_controller) {
92 DCHECK(context);
93 DCHECK(support);
94 DCHECK(cache_controller);
95 return new TestContextProvider(
96 std::move(support), base::MakeUnique<TestGLES2Interface>(),
97 std::move(context), std::move(cache_controller));
70 } 98 }
71 99
72 TestContextProvider::TestContextProvider( 100 TestContextProvider::TestContextProvider(
73 std::unique_ptr<TestContextSupport> support, 101 std::unique_ptr<TestContextSupport> support,
74 std::unique_ptr<TestGLES2Interface> gl, 102 std::unique_ptr<TestGLES2Interface> gl,
75 std::unique_ptr<TestWebGraphicsContext3D> context) 103 std::unique_ptr<TestWebGraphicsContext3D> context,
104 std::unique_ptr<ContextCacheController> cache_controller)
76 : support_(std::move(support)), 105 : support_(std::move(support)),
77 context3d_(std::move(context)), 106 context3d_(std::move(context)),
78 context_gl_(std::move(gl)), 107 context_gl_(std::move(gl)),
108 cache_controller_(std::move(cache_controller)),
79 weak_ptr_factory_(this) { 109 weak_ptr_factory_(this) {
80 DCHECK(main_thread_checker_.CalledOnValidThread()); 110 DCHECK(main_thread_checker_.CalledOnValidThread());
81 DCHECK(context3d_); 111 DCHECK(context3d_);
82 DCHECK(context_gl_); 112 DCHECK(context_gl_);
83 context_thread_checker_.DetachFromThread(); 113 context_thread_checker_.DetachFromThread();
84 context_gl_->set_test_context(context3d_.get()); 114 context_gl_->set_test_context(context3d_.get());
85 context3d_->set_test_support(support_.get()); 115 context3d_->set_test_support(support_.get());
86 } 116 }
87 117
88 TestContextProvider::~TestContextProvider() { 118 TestContextProvider::~TestContextProvider() {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 DCHECK(context_thread_checker_.CalledOnValidThread()); 166 DCHECK(context_thread_checker_.CalledOnValidThread());
137 167
138 if (gr_context_) 168 if (gr_context_)
139 return gr_context_.get(); 169 return gr_context_.get();
140 170
141 sk_sp<const GrGLInterface> gl_interface(GrGLCreateNullInterface()); 171 sk_sp<const GrGLInterface> gl_interface(GrGLCreateNullInterface());
142 gr_context_ = sk_sp<::GrContext>(GrContext::Create( 172 gr_context_ = sk_sp<::GrContext>(GrContext::Create(
143 kOpenGL_GrBackend, 173 kOpenGL_GrBackend,
144 reinterpret_cast<GrBackendContext>(gl_interface.get()))); 174 reinterpret_cast<GrBackendContext>(gl_interface.get())));
145 175
176 cache_controller_->SetGrContext(gr_context_.get());
177
146 // If GlContext is already lost, also abandon the new GrContext. 178 // If GlContext is already lost, also abandon the new GrContext.
147 if (ContextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERROR) 179 if (ContextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERROR)
148 gr_context_->abandonContext(); 180 gr_context_->abandonContext();
149 181
150 return gr_context_.get(); 182 return gr_context_.get();
151 } 183 }
152 184
185 ContextCacheController* TestContextProvider::CacheController() {
186 DCHECK(context_thread_checker_.CalledOnValidThread());
187 return cache_controller_.get();
188 }
189
153 void TestContextProvider::InvalidateGrContext(uint32_t state) { 190 void TestContextProvider::InvalidateGrContext(uint32_t state) {
154 DCHECK(bound_); 191 DCHECK(bound_);
155 DCHECK(context_thread_checker_.CalledOnValidThread()); 192 DCHECK(context_thread_checker_.CalledOnValidThread());
156 193
157 if (gr_context_) 194 if (gr_context_)
158 gr_context_.get()->resetContext(state); 195 gr_context_.get()->resetContext(state);
159 } 196 }
160 197
161 base::Lock* TestContextProvider::GetLock() { 198 base::Lock* TestContextProvider::GetLock() {
162 return &context_lock_; 199 return &context_lock_;
163 } 200 }
164 201
165 void TestContextProvider::DeleteCachedResources() {
166 }
167
168 void TestContextProvider::OnLostContext() { 202 void TestContextProvider::OnLostContext() {
169 DCHECK(context_thread_checker_.CalledOnValidThread()); 203 DCHECK(context_thread_checker_.CalledOnValidThread());
170 if (!lost_context_callback_.is_null()) 204 if (!lost_context_callback_.is_null())
171 lost_context_callback_.Run(); 205 lost_context_callback_.Run();
172 if (gr_context_) 206 if (gr_context_)
173 gr_context_->abandonContext(); 207 gr_context_->abandonContext();
174 } 208 }
175 209
176 TestWebGraphicsContext3D* TestContextProvider::TestContext3d() { 210 TestWebGraphicsContext3D* TestContextProvider::TestContext3d() {
177 DCHECK(bound_); 211 DCHECK(bound_);
178 DCHECK(context_thread_checker_.CalledOnValidThread()); 212 DCHECK(context_thread_checker_.CalledOnValidThread());
179 213
180 return context3d_.get(); 214 return context3d_.get();
181 } 215 }
182 216
183 TestWebGraphicsContext3D* TestContextProvider::UnboundTestContext3d() { 217 TestWebGraphicsContext3D* TestContextProvider::UnboundTestContext3d() {
184 return context3d_.get(); 218 return context3d_.get();
185 } 219 }
186 220
187 void TestContextProvider::SetLostContextCallback( 221 void TestContextProvider::SetLostContextCallback(
188 const LostContextCallback& cb) { 222 const LostContextCallback& cb) {
189 DCHECK(context_thread_checker_.CalledOnValidThread()); 223 DCHECK(context_thread_checker_.CalledOnValidThread());
190 DCHECK(lost_context_callback_.is_null() || cb.is_null()); 224 DCHECK(lost_context_callback_.is_null() || cb.is_null());
191 lost_context_callback_ = cb; 225 lost_context_callback_ = cb;
192 } 226 }
193 227
194 } // namespace cc 228 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698