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) { |
41 if (!context) | 42 DCHECK(context); |
42 return NULL; | 43 return new TestContextProvider(base::MakeUnique<TestGLES2Interface>(), |
43 return new TestContextProvider(std::move(context)); | 44 std::move(context)); |
| 45 } |
| 46 |
| 47 // static |
| 48 scoped_refptr<TestContextProvider> TestContextProvider::Create( |
| 49 std::unique_ptr<TestGLES2Interface> gl) { |
| 50 DCHECK(gl); |
| 51 return new TestContextProvider(std::move(gl), |
| 52 TestWebGraphicsContext3D::Create()); |
44 } | 53 } |
45 | 54 |
46 TestContextProvider::TestContextProvider( | 55 TestContextProvider::TestContextProvider( |
| 56 std::unique_ptr<TestGLES2Interface> gl, |
47 std::unique_ptr<TestWebGraphicsContext3D> context) | 57 std::unique_ptr<TestWebGraphicsContext3D> context) |
48 : context3d_(std::move(context)), | 58 : context3d_(std::move(context)), |
49 context_gl_(new TestGLES2Interface(context3d_.get())), | 59 context_gl_(std::move(gl)), |
50 bound_(false), | 60 bound_(false), |
51 weak_ptr_factory_(this) { | 61 weak_ptr_factory_(this) { |
52 DCHECK(main_thread_checker_.CalledOnValidThread()); | 62 DCHECK(main_thread_checker_.CalledOnValidThread()); |
53 DCHECK(context3d_); | 63 DCHECK(context3d_); |
| 64 DCHECK(context_gl_); |
54 context_thread_checker_.DetachFromThread(); | 65 context_thread_checker_.DetachFromThread(); |
| 66 context_gl_->set_test_context(context3d_.get()); |
55 context3d_->set_test_support(&support_); | 67 context3d_->set_test_support(&support_); |
56 } | 68 } |
57 | 69 |
58 TestContextProvider::~TestContextProvider() { | 70 TestContextProvider::~TestContextProvider() { |
59 DCHECK(main_thread_checker_.CalledOnValidThread() || | 71 DCHECK(main_thread_checker_.CalledOnValidThread() || |
60 context_thread_checker_.CalledOnValidThread()); | 72 context_thread_checker_.CalledOnValidThread()); |
61 } | 73 } |
62 | 74 |
63 bool TestContextProvider::BindToCurrentThread() { | 75 bool TestContextProvider::BindToCurrentThread() { |
64 // This is called on the thread the context will be used. | 76 // 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 } | 167 } |
156 | 168 |
157 void TestContextProvider::SetLostContextCallback( | 169 void TestContextProvider::SetLostContextCallback( |
158 const LostContextCallback& cb) { | 170 const LostContextCallback& cb) { |
159 DCHECK(context_thread_checker_.CalledOnValidThread()); | 171 DCHECK(context_thread_checker_.CalledOnValidThread()); |
160 DCHECK(lost_context_callback_.is_null() || cb.is_null()); | 172 DCHECK(lost_context_callback_.is_null() || cb.is_null()); |
161 lost_context_callback_ = cb; | 173 lost_context_callback_ = cb; |
162 } | 174 } |
163 | 175 |
164 } // namespace cc | 176 } // namespace cc |
OLD | NEW |