| 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 "base/memory/ptr_util.h" |
| 17 #include "cc/test/test_gles2_interface.h" | 17 #include "cc/test/test_gles2_interface.h" |
| 18 #include "cc/test/test_web_graphics_context_3d.h" | 18 #include "cc/test/test_web_graphics_context_3d.h" |
| 19 #include "third_party/skia/include/gpu/GrContext.h" | 19 #include "third_party/skia/include/gpu/GrContext.h" |
| 20 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 20 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
| 21 | 21 |
| 22 namespace cc { | 22 namespace cc { |
| 23 | 23 |
| 24 // static | 24 // static |
| 25 scoped_refptr<TestContextProvider> TestContextProvider::Create() { | 25 scoped_refptr<TestContextProvider> TestContextProvider::Create() { |
| 26 return new TestContextProvider(base::MakeUnique<TestContextSupport>(), | 26 return Create(TestWebGraphicsContext3D::Create()); |
| 27 base::MakeUnique<TestGLES2Interface>(), | |
| 28 TestWebGraphicsContext3D::Create()); | |
| 29 } | 27 } |
| 30 | 28 |
| 31 // static | 29 // static |
| 32 scoped_refptr<TestContextProvider> TestContextProvider::CreateWorker() { | 30 scoped_refptr<TestContextProvider> TestContextProvider::CreateWorker() { |
| 33 scoped_refptr<TestContextProvider> worker_context_provider( | 31 scoped_refptr<TestContextProvider> worker_context_provider = |
| 34 new TestContextProvider(base::MakeUnique<TestContextSupport>(), | 32 Create(TestWebGraphicsContext3D::Create()); |
| 35 base::MakeUnique<TestGLES2Interface>(), | |
| 36 TestWebGraphicsContext3D::Create())); | |
| 37 // Worker contexts are bound to the thread they are created on. | 33 // Worker contexts are bound to the thread they are created on. |
| 38 if (!worker_context_provider->BindToCurrentThread()) | 34 if (!worker_context_provider->BindToCurrentThread()) |
| 39 return nullptr; | 35 return nullptr; |
| 40 return worker_context_provider; | 36 return worker_context_provider; |
| 41 } | 37 } |
| 42 | 38 |
| 43 // static | 39 // static |
| 44 scoped_refptr<TestContextProvider> TestContextProvider::Create( | 40 scoped_refptr<TestContextProvider> TestContextProvider::Create( |
| 45 std::unique_ptr<TestWebGraphicsContext3D> context) { | 41 std::unique_ptr<TestWebGraphicsContext3D> context) { |
| 46 DCHECK(context); | 42 DCHECK(context); |
| 47 return new TestContextProvider(base::MakeUnique<TestContextSupport>(), | 43 return new TestContextProvider(base::MakeUnique<TestGLES2Interface>(), |
| 48 base::MakeUnique<TestGLES2Interface>(), | |
| 49 std::move(context)); | 44 std::move(context)); |
| 50 } | 45 } |
| 51 | 46 |
| 52 // static | 47 // static |
| 53 scoped_refptr<TestContextProvider> TestContextProvider::Create( | 48 scoped_refptr<TestContextProvider> TestContextProvider::Create( |
| 54 std::unique_ptr<TestGLES2Interface> gl) { | 49 std::unique_ptr<TestGLES2Interface> gl) { |
| 55 DCHECK(gl); | 50 DCHECK(gl); |
| 56 return new TestContextProvider(base::MakeUnique<TestContextSupport>(), | 51 return new TestContextProvider(std::move(gl), |
| 57 std::move(gl), | |
| 58 TestWebGraphicsContext3D::Create()); | 52 TestWebGraphicsContext3D::Create()); |
| 59 } | 53 } |
| 60 | 54 |
| 61 // static | |
| 62 scoped_refptr<TestContextProvider> TestContextProvider::Create( | |
| 63 std::unique_ptr<TestWebGraphicsContext3D> context, | |
| 64 std::unique_ptr<TestContextSupport> support) { | |
| 65 DCHECK(context); | |
| 66 DCHECK(support); | |
| 67 return new TestContextProvider(std::move(support), | |
| 68 base::MakeUnique<TestGLES2Interface>(), | |
| 69 std::move(context)); | |
| 70 } | |
| 71 | |
| 72 TestContextProvider::TestContextProvider( | 55 TestContextProvider::TestContextProvider( |
| 73 std::unique_ptr<TestContextSupport> support, | |
| 74 std::unique_ptr<TestGLES2Interface> gl, | 56 std::unique_ptr<TestGLES2Interface> gl, |
| 75 std::unique_ptr<TestWebGraphicsContext3D> context) | 57 std::unique_ptr<TestWebGraphicsContext3D> context) |
| 76 : support_(std::move(support)), | 58 : context3d_(std::move(context)), |
| 77 context3d_(std::move(context)), | |
| 78 context_gl_(std::move(gl)), | 59 context_gl_(std::move(gl)), |
| 60 bound_(false), |
| 79 weak_ptr_factory_(this) { | 61 weak_ptr_factory_(this) { |
| 80 DCHECK(main_thread_checker_.CalledOnValidThread()); | 62 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 81 DCHECK(context3d_); | 63 DCHECK(context3d_); |
| 82 DCHECK(context_gl_); | 64 DCHECK(context_gl_); |
| 83 context_thread_checker_.DetachFromThread(); | 65 context_thread_checker_.DetachFromThread(); |
| 84 context_gl_->set_test_context(context3d_.get()); | 66 context_gl_->set_test_context(context3d_.get()); |
| 85 context3d_->set_test_support(support_.get()); | 67 context3d_->set_test_support(&support_); |
| 86 } | 68 } |
| 87 | 69 |
| 88 TestContextProvider::~TestContextProvider() { | 70 TestContextProvider::~TestContextProvider() { |
| 89 DCHECK(main_thread_checker_.CalledOnValidThread() || | 71 DCHECK(main_thread_checker_.CalledOnValidThread() || |
| 90 context_thread_checker_.CalledOnValidThread()); | 72 context_thread_checker_.CalledOnValidThread()); |
| 91 } | 73 } |
| 92 | 74 |
| 93 bool TestContextProvider::BindToCurrentThread() { | 75 bool TestContextProvider::BindToCurrentThread() { |
| 94 // This is called on the thread the context will be used. | 76 // This is called on the thread the context will be used. |
| 95 DCHECK(context_thread_checker_.CalledOnValidThread()); | 77 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 121 | 103 |
| 122 gpu::gles2::GLES2Interface* TestContextProvider::ContextGL() { | 104 gpu::gles2::GLES2Interface* TestContextProvider::ContextGL() { |
| 123 DCHECK(context3d_); | 105 DCHECK(context3d_); |
| 124 DCHECK(bound_); | 106 DCHECK(bound_); |
| 125 DCHECK(context_thread_checker_.CalledOnValidThread()); | 107 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 126 | 108 |
| 127 return context_gl_.get(); | 109 return context_gl_.get(); |
| 128 } | 110 } |
| 129 | 111 |
| 130 gpu::ContextSupport* TestContextProvider::ContextSupport() { | 112 gpu::ContextSupport* TestContextProvider::ContextSupport() { |
| 131 return support(); | 113 return &support_; |
| 132 } | 114 } |
| 133 | 115 |
| 134 class GrContext* TestContextProvider::GrContext() { | 116 class GrContext* TestContextProvider::GrContext() { |
| 135 DCHECK(bound_); | 117 DCHECK(bound_); |
| 136 DCHECK(context_thread_checker_.CalledOnValidThread()); | 118 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 137 | 119 |
| 138 if (gr_context_) | 120 if (gr_context_) |
| 139 return gr_context_.get(); | 121 return gr_context_.get(); |
| 140 | 122 |
| 141 sk_sp<const GrGLInterface> gl_interface(GrGLCreateNullInterface()); | 123 sk_sp<const GrGLInterface> gl_interface(GrGLCreateNullInterface()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 } | 167 } |
| 186 | 168 |
| 187 void TestContextProvider::SetLostContextCallback( | 169 void TestContextProvider::SetLostContextCallback( |
| 188 const LostContextCallback& cb) { | 170 const LostContextCallback& cb) { |
| 189 DCHECK(context_thread_checker_.CalledOnValidThread()); | 171 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 190 DCHECK(lost_context_callback_.is_null() || cb.is_null()); | 172 DCHECK(lost_context_callback_.is_null() || cb.is_null()); |
| 191 lost_context_callback_ = cb; | 173 lost_context_callback_ = cb; |
| 192 } | 174 } |
| 193 | 175 |
| 194 } // namespace cc | 176 } // namespace cc |
| OLD | NEW |