| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/compositor/image_transport_factory.h" | 5 #include "content/browser/compositor/image_transport_factory.h" | 
| 6 | 6 | 
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" | 
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" | 
| 9 #include "content/browser/compositor/gpu_process_transport_factory.h" | 9 #include "content/browser/compositor/gpu_process_transport_factory.h" | 
| 10 #include "ui/compositor/compositor.h" | 10 #include "ui/compositor/compositor.h" | 
| 11 #include "ui/compositor/compositor_switches.h" | 11 #include "ui/compositor/compositor_switches.h" | 
| 12 #include "ui/gl/gl_implementation.h" | 12 #include "ui/gl/gl_implementation.h" | 
| 13 | 13 | 
| 14 namespace content { | 14 namespace content { | 
| 15 | 15 | 
| 16 namespace { | 16 namespace { | 
| 17 ImageTransportFactory* g_factory = NULL; | 17 ImageTransportFactory* g_image_transport_factory = NULL; | 
| 18 bool g_initialized_for_unit_tests = false; | 18 bool g_initialized_for_unit_tests = false; | 
| 19 static gl::DisableNullDrawGLBindings* g_disable_null_draw = NULL; | 19 static gl::DisableNullDrawGLBindings* g_disable_null_draw = NULL; | 
| 20 | 20 | 
| 21 void SetFactory(ImageTransportFactory* factory) { | 21 void SetFactory(ImageTransportFactory* factory) { | 
| 22   g_factory = factory; | 22   g_image_transport_factory = factory; | 
| 23 } | 23 } | 
| 24 | 24 | 
| 25 } | 25 } | 
| 26 | 26 | 
| 27 // static | 27 // static | 
| 28 void ImageTransportFactory::Initialize( | 28 void ImageTransportFactory::Initialize( | 
| 29     scoped_refptr<base::SingleThreadTaskRunner> resize_task_runner) { | 29     scoped_refptr<base::SingleThreadTaskRunner> resize_task_runner) { | 
| 30   DCHECK(!g_factory || g_initialized_for_unit_tests); | 30   DCHECK(!g_image_transport_factory || g_initialized_for_unit_tests); | 
| 31   if (g_initialized_for_unit_tests) | 31   if (g_initialized_for_unit_tests) | 
| 32     return; | 32     return; | 
| 33   SetFactory(new GpuProcessTransportFactory(std::move(resize_task_runner))); | 33   SetFactory(new GpuProcessTransportFactory(std::move(resize_task_runner))); | 
| 34 } | 34 } | 
| 35 | 35 | 
| 36 void ImageTransportFactory::InitializeForUnitTests( | 36 void ImageTransportFactory::InitializeForUnitTests( | 
| 37     std::unique_ptr<ImageTransportFactory> factory) { | 37     std::unique_ptr<ImageTransportFactory> factory) { | 
| 38   DCHECK(!g_factory); | 38   DCHECK(!g_image_transport_factory); | 
| 39   DCHECK(!g_initialized_for_unit_tests); | 39   DCHECK(!g_initialized_for_unit_tests); | 
| 40   g_initialized_for_unit_tests = true; | 40   g_initialized_for_unit_tests = true; | 
| 41 | 41 | 
| 42   const base::CommandLine* command_line = | 42   const base::CommandLine* command_line = | 
| 43       base::CommandLine::ForCurrentProcess(); | 43       base::CommandLine::ForCurrentProcess(); | 
| 44   if (command_line->HasSwitch(switches::kEnablePixelOutputInTests)) | 44   if (command_line->HasSwitch(switches::kEnablePixelOutputInTests)) | 
| 45     g_disable_null_draw = new gl::DisableNullDrawGLBindings; | 45     g_disable_null_draw = new gl::DisableNullDrawGLBindings; | 
| 46 | 46 | 
| 47   SetFactory(factory.release()); | 47   SetFactory(factory.release()); | 
| 48 } | 48 } | 
| 49 | 49 | 
| 50 // static | 50 // static | 
| 51 void ImageTransportFactory::Terminate() { | 51 void ImageTransportFactory::Terminate() { | 
| 52   delete g_factory; | 52   delete g_image_transport_factory; | 
| 53   g_factory = NULL; | 53   g_image_transport_factory = NULL; | 
| 54   delete g_disable_null_draw; | 54   delete g_disable_null_draw; | 
| 55   g_disable_null_draw = NULL; | 55   g_disable_null_draw = NULL; | 
| 56   g_initialized_for_unit_tests = false; | 56   g_initialized_for_unit_tests = false; | 
| 57 } | 57 } | 
| 58 | 58 | 
| 59 // static | 59 // static | 
| 60 ImageTransportFactory* ImageTransportFactory::GetInstance() { | 60 ImageTransportFactory* ImageTransportFactory::GetInstance() { | 
| 61   return g_factory; | 61   return g_image_transport_factory; | 
| 62 } | 62 } | 
| 63 | 63 | 
| 64 }  // namespace content | 64 }  // namespace content | 
| OLD | NEW | 
|---|