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