| 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 <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "cc/test/test_gles2_interface.h" | 13 #include "cc/test/test_gles2_interface.h" |
| 14 #include "cc/test/test_web_graphics_context_3d.h" | 14 #include "cc/test/test_web_graphics_context_3d.h" |
| 15 #include "third_party/skia/include/gpu/GrContext.h" | 15 #include "third_party/skia/include/gpu/GrContext.h" |
| 16 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 16 #include "third_party/skia/include/gpu/gl/SkNullGLContext.h" |
| 17 | 17 |
| 18 namespace cc { | 18 namespace cc { |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 scoped_refptr<TestContextProvider> TestContextProvider::Create() { | 21 scoped_refptr<TestContextProvider> TestContextProvider::Create() { |
| 22 return Create(TestWebGraphicsContext3D::Create().Pass()); | 22 return Create(TestWebGraphicsContext3D::Create().Pass()); |
| 23 } | 23 } |
| 24 | 24 |
| 25 // static | 25 // static |
| 26 scoped_refptr<TestContextProvider> TestContextProvider::Create( | 26 scoped_refptr<TestContextProvider> TestContextProvider::Create( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 62 } |
| 63 bound_ = true; | 63 bound_ = true; |
| 64 | 64 |
| 65 context3d_->set_context_lost_callback( | 65 context3d_->set_context_lost_callback( |
| 66 base::Bind(&TestContextProvider::OnLostContext, | 66 base::Bind(&TestContextProvider::OnLostContext, |
| 67 base::Unretained(this))); | 67 base::Unretained(this))); |
| 68 | 68 |
| 69 return true; | 69 return true; |
| 70 } | 70 } |
| 71 | 71 |
| 72 void TestContextProvider::DetachFromThread() { |
| 73 context_thread_checker_.DetachFromThread(); |
| 74 } |
| 75 |
| 72 ContextProvider::Capabilities TestContextProvider::ContextCapabilities() { | 76 ContextProvider::Capabilities TestContextProvider::ContextCapabilities() { |
| 73 DCHECK(bound_); | 77 DCHECK(bound_); |
| 74 DCHECK(context_thread_checker_.CalledOnValidThread()); | 78 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 75 | 79 |
| 76 return context3d_->test_capabilities(); | 80 return context3d_->test_capabilities(); |
| 77 } | 81 } |
| 78 | 82 |
| 79 gpu::gles2::GLES2Interface* TestContextProvider::ContextGL() { | 83 gpu::gles2::GLES2Interface* TestContextProvider::ContextGL() { |
| 80 DCHECK(context3d_); | 84 DCHECK(context3d_); |
| 81 DCHECK(bound_); | 85 DCHECK(bound_); |
| 82 DCHECK(context_thread_checker_.CalledOnValidThread()); | 86 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 83 | 87 |
| 84 return context_gl_.get(); | 88 return context_gl_.get(); |
| 85 } | 89 } |
| 86 | 90 |
| 87 gpu::ContextSupport* TestContextProvider::ContextSupport() { | 91 gpu::ContextSupport* TestContextProvider::ContextSupport() { |
| 88 return &support_; | 92 return &support_; |
| 89 } | 93 } |
| 90 | 94 |
| 91 class GrContext* TestContextProvider::GrContext() { | 95 class GrContext* TestContextProvider::GrContext() { |
| 92 DCHECK(bound_); | 96 DCHECK(bound_); |
| 93 DCHECK(context_thread_checker_.CalledOnValidThread()); | 97 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 94 | 98 |
| 95 if (gr_context_) | 99 if (gr_context_) |
| 96 return gr_context_.get(); | 100 return gr_context_.get(); |
| 97 | 101 |
| 98 skia::RefPtr<const GrGLInterface> null_interface = | 102 skia::RefPtr<class SkGLContext> gl_context = |
| 99 skia::AdoptRef(GrGLCreateNullInterface()); | 103 skia::AdoptRef(SkNullGLContext::Create(kNone_GrGLStandard)); |
| 104 gl_context->makeCurrent(); |
| 100 gr_context_ = skia::AdoptRef(GrContext::Create( | 105 gr_context_ = skia::AdoptRef(GrContext::Create( |
| 101 kOpenGL_GrBackend, | 106 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(gl_context->gl()))); |
| 102 reinterpret_cast<GrBackendContext>(null_interface.get()))); | |
| 103 return gr_context_.get(); | 107 return gr_context_.get(); |
| 104 } | 108 } |
| 105 | 109 |
| 110 void TestContextProvider::SetupLock() { |
| 111 } |
| 112 |
| 113 base::Lock* TestContextProvider::GetLock() { |
| 114 return &context_lock_; |
| 115 } |
| 116 |
| 106 bool TestContextProvider::IsContextLost() { | 117 bool TestContextProvider::IsContextLost() { |
| 107 DCHECK(bound_); | 118 DCHECK(bound_); |
| 108 DCHECK(context_thread_checker_.CalledOnValidThread()); | 119 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 109 | 120 |
| 110 return context3d_->isContextLost(); | 121 return context3d_->isContextLost(); |
| 111 } | 122 } |
| 112 | 123 |
| 113 void TestContextProvider::VerifyContexts() { | 124 void TestContextProvider::VerifyContexts() { |
| 114 DCHECK(bound_); | 125 DCHECK(bound_); |
| 115 DCHECK(context_thread_checker_.CalledOnValidThread()); | 126 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 DCHECK(memory_policy_changed_callback_.is_null() || cb.is_null()); | 184 DCHECK(memory_policy_changed_callback_.is_null() || cb.is_null()); |
| 174 memory_policy_changed_callback_ = cb; | 185 memory_policy_changed_callback_ = cb; |
| 175 } | 186 } |
| 176 | 187 |
| 177 void TestContextProvider::SetMaxTransferBufferUsageBytes( | 188 void TestContextProvider::SetMaxTransferBufferUsageBytes( |
| 178 size_t max_transfer_buffer_usage_bytes) { | 189 size_t max_transfer_buffer_usage_bytes) { |
| 179 context3d_->SetMaxTransferBufferUsageBytes(max_transfer_buffer_usage_bytes); | 190 context3d_->SetMaxTransferBufferUsageBytes(max_transfer_buffer_usage_bytes); |
| 180 } | 191 } |
| 181 | 192 |
| 182 } // namespace cc | 193 } // namespace cc |
| OLD | NEW |