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_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 "cc/test/test_gles2_interface.h" | 17 #include "cc/test/test_gles2_interface.h" |
17 #include "cc/test/test_web_graphics_context_3d.h" | 18 #include "cc/test/test_web_graphics_context_3d.h" |
18 #include "third_party/skia/include/gpu/GrContext.h" | 19 #include "third_party/skia/include/gpu/GrContext.h" |
19 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 20 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
20 | 21 |
21 namespace cc { | 22 namespace cc { |
22 | 23 |
23 // static | 24 // static |
24 scoped_refptr<TestContextProvider> TestContextProvider::Create() { | 25 scoped_refptr<TestContextProvider> TestContextProvider::Create() { |
25 return Create(TestWebGraphicsContext3D::Create()); | 26 return Create(TestWebGraphicsContext3D::Create()); |
26 } | 27 } |
27 | 28 |
28 // static | 29 // static |
29 scoped_refptr<TestContextProvider> TestContextProvider::CreateWorker() { | 30 scoped_refptr<TestContextProvider> TestContextProvider::CreateWorker() { |
30 scoped_refptr<TestContextProvider> worker_context_provider = | 31 scoped_refptr<TestContextProvider> worker_context_provider = |
31 Create(TestWebGraphicsContext3D::Create()); | 32 Create(TestWebGraphicsContext3D::Create()); |
32 // Worker contexts are bound to the thread they are created on. | 33 // Worker contexts are bound to the thread they are created on. |
33 if (!worker_context_provider->BindToCurrentThread()) | 34 if (!worker_context_provider->BindToCurrentThread()) |
34 return nullptr; | 35 return nullptr; |
35 return worker_context_provider; | 36 return worker_context_provider; |
36 } | 37 } |
37 | 38 |
38 // static | 39 // static |
39 scoped_refptr<TestContextProvider> TestContextProvider::Create( | 40 scoped_refptr<TestContextProvider> TestContextProvider::Create( |
40 std::unique_ptr<TestWebGraphicsContext3D> context) { | 41 std::unique_ptr<TestWebGraphicsContext3D> context) { |
42 DCHECK(context); | |
vmpstr
2016/07/20 01:11:22
We don't usually
DCHECK(foo);
if (!foo)
...
do
danakj
2016/07/20 18:57:41
No, I was fishing and left that in. I'll remove th
| |
41 if (!context) | 43 if (!context) |
42 return NULL; | 44 return nullptr; |
43 return new TestContextProvider(std::move(context)); | 45 return new TestContextProvider(base::MakeUnique<TestGLES2Interface>(), |
46 std::move(context)); | |
47 } | |
48 | |
49 // static | |
50 scoped_refptr<TestContextProvider> TestContextProvider::Create( | |
51 std::unique_ptr<TestGLES2Interface> gl) { | |
52 DCHECK(gl); | |
53 return new TestContextProvider(std::move(gl), | |
54 TestWebGraphicsContext3D::Create()); | |
44 } | 55 } |
45 | 56 |
46 TestContextProvider::TestContextProvider( | 57 TestContextProvider::TestContextProvider( |
58 std::unique_ptr<TestGLES2Interface> gl, | |
47 std::unique_ptr<TestWebGraphicsContext3D> context) | 59 std::unique_ptr<TestWebGraphicsContext3D> context) |
48 : context3d_(std::move(context)), | 60 : context3d_(std::move(context)), |
49 context_gl_(new TestGLES2Interface(context3d_.get())), | 61 context_gl_(std::move(gl)), |
50 bound_(false), | 62 bound_(false), |
51 weak_ptr_factory_(this) { | 63 weak_ptr_factory_(this) { |
52 DCHECK(main_thread_checker_.CalledOnValidThread()); | 64 DCHECK(main_thread_checker_.CalledOnValidThread()); |
53 DCHECK(context3d_); | 65 DCHECK(context3d_); |
66 DCHECK(context_gl_); | |
54 context_thread_checker_.DetachFromThread(); | 67 context_thread_checker_.DetachFromThread(); |
68 context_gl_->set_test_context(context3d_.get()); | |
55 context3d_->set_test_support(&support_); | 69 context3d_->set_test_support(&support_); |
56 } | 70 } |
57 | 71 |
58 TestContextProvider::~TestContextProvider() { | 72 TestContextProvider::~TestContextProvider() { |
59 DCHECK(main_thread_checker_.CalledOnValidThread() || | 73 DCHECK(main_thread_checker_.CalledOnValidThread() || |
60 context_thread_checker_.CalledOnValidThread()); | 74 context_thread_checker_.CalledOnValidThread()); |
61 } | 75 } |
62 | 76 |
63 bool TestContextProvider::BindToCurrentThread() { | 77 bool TestContextProvider::BindToCurrentThread() { |
64 // This is called on the thread the context will be used. | 78 // This is called on the thread the context will be used. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 } | 169 } |
156 | 170 |
157 void TestContextProvider::SetLostContextCallback( | 171 void TestContextProvider::SetLostContextCallback( |
158 const LostContextCallback& cb) { | 172 const LostContextCallback& cb) { |
159 DCHECK(context_thread_checker_.CalledOnValidThread()); | 173 DCHECK(context_thread_checker_.CalledOnValidThread()); |
160 DCHECK(lost_context_callback_.is_null() || cb.is_null()); | 174 DCHECK(lost_context_callback_.is_null() || cb.is_null()); |
161 lost_context_callback_ = cb; | 175 lost_context_callback_ = cb; |
162 } | 176 } |
163 | 177 |
164 } // namespace cc | 178 } // namespace cc |
OLD | NEW |