OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/gpu/test_context_provider_factory.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "cc/context_provider.h" |
| 9 #include "webkit/gpu/context_provider_in_process.h" |
| 10 |
| 11 namespace webkit { |
| 12 namespace gpu { |
| 13 |
| 14 #ifndef NDEBUG |
| 15 static bool factory_set_up = false; |
| 16 #endif |
| 17 static ContextProviderInProcess::InProcessType context_provider_type; |
| 18 static TestContextProviderFactory* context_provider_instance = NULL; |
| 19 |
| 20 // static |
| 21 void TestContextProviderFactory::SetUpFactoryForTesting( |
| 22 webkit_support::GraphicsContext3DImplementation implementation) { |
| 23 #ifndef NDEBUG |
| 24 factory_set_up = true; |
| 25 #endif |
| 26 |
| 27 switch (implementation) { |
| 28 case webkit_support::IN_PROCESS: |
| 29 context_provider_type = webkit::gpu::ContextProviderInProcess::IN_PROCESS; |
| 30 return; |
| 31 case webkit_support::IN_PROCESS_COMMAND_BUFFER: |
| 32 context_provider_type = |
| 33 webkit::gpu::ContextProviderInProcess::IN_PROCESS_COMMAND_BUFFER; |
| 34 return; |
| 35 } |
| 36 NOTREACHED(); |
| 37 context_provider_type = webkit::gpu::ContextProviderInProcess::IN_PROCESS; |
| 38 } |
| 39 |
| 40 // static |
| 41 TestContextProviderFactory* TestContextProviderFactory::GetInstance() { |
| 42 #ifndef NDEBUG |
| 43 DCHECK(factory_set_up); |
| 44 #endif |
| 45 if (!context_provider_instance) |
| 46 context_provider_instance = new TestContextProviderFactory(); |
| 47 return context_provider_instance; |
| 48 } |
| 49 |
| 50 TestContextProviderFactory::TestContextProviderFactory() {} |
| 51 |
| 52 TestContextProviderFactory::~TestContextProviderFactory() {} |
| 53 |
| 54 scoped_refptr<cc::ContextProvider> TestContextProviderFactory:: |
| 55 OffscreenContextProviderForMainThread() { |
| 56 if (!main_thread_ || main_thread_->DestroyedOnMainThread()) { |
| 57 main_thread_ = new ContextProviderInProcess(context_provider_type); |
| 58 } |
| 59 return main_thread_; |
| 60 } |
| 61 |
| 62 scoped_refptr<cc::ContextProvider> TestContextProviderFactory:: |
| 63 OffscreenContextProviderForCompositorThread() { |
| 64 if (!compositor_thread_ || |
| 65 compositor_thread_->DestroyedOnMainThread()) { |
| 66 compositor_thread_ = new ContextProviderInProcess(context_provider_type); |
| 67 } |
| 68 return compositor_thread_; |
| 69 } |
| 70 |
| 71 } // namespace gpu |
| 72 } // namespace webkit |
OLD | NEW |