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 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_BROWSER_COMPOSITOR_IMAGE_TRANSPORT_FACTORY_H_ 6 #define CONTENT_BROWSER_COMPOSITOR_IMAGE_TRANSPORT_FACTORY_H_ 7 8 #include <string> 9 10 #include "base/memory/ref_counted.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "cc/surfaces/surface_id_allocator.h" 13 #include "content/common/content_export.h" 14 #include "ui/gfx/native_widget_types.h" 15 16 namespace cc { 17 class SurfaceManager; 18 } 19 20 namespace gfx { 21 class Size; 22 } 23 24 namespace ui { 25 class ContextFactory; 26 class Texture; 27 } 28 29 namespace blink { 30 class WebGraphicsContext3D; 31 } 32 33 namespace content { 34 class GLHelper; 35 36 // This class provides a way to get notified when surface handles get lost. 37 class CONTENT_EXPORT ImageTransportFactoryObserver { 38 public: 39 virtual ~ImageTransportFactoryObserver() {} 40 41 // Notifies that the surface handles generated by ImageTransportFactory were 42 // lost. 43 // When this is called, the old resources (e.g. shared context, GL helper) 44 // still exist, but are about to be destroyed. Getting a reference to those 45 // resources from the ImageTransportFactory (e.g. through GetGLHelper) will 46 // return newly recreated, valid resources. 47 virtual void OnLostResources() = 0; 48 }; 49 50 // This class provides the interface for creating the support for the 51 // cross-process image transport, both for creating the shared surface handle 52 // (destination surface for the GPU process) and the transport client (logic for 53 // using that surface as a texture). The factory is a process-wide singleton. 54 class CONTENT_EXPORT ImageTransportFactory { 55 public: 56 virtual ~ImageTransportFactory() {} 57 58 // Initializes the global transport factory. 59 static void Initialize(); 60 61 // Initializes the global transport factory for unit tests using the provided 62 // context factory. 63 static void InitializeForUnitTests(scoped_ptr<ImageTransportFactory> factory); 64 65 // Terminates the global transport factory. 66 static void Terminate(); 67 68 // Gets the factory instance. 69 static ImageTransportFactory* GetInstance(); 70 71 // Gets the image transport factory as a context factory for the compositor. 72 virtual ui::ContextFactory* GetContextFactory() = 0; 73 74 virtual gfx::GLSurfaceHandle GetSharedSurfaceHandle() = 0; 75 virtual scoped_ptr<cc::SurfaceIdAllocator> CreateSurfaceIdAllocator() = 0; 76 virtual cc::SurfaceManager* GetSurfaceManager() = 0; 77 78 // Gets a GLHelper instance, associated with the shared context. This 79 // GLHelper will get destroyed whenever the shared context is lost 80 // (ImageTransportFactoryObserver::OnLostResources is called). 81 virtual GLHelper* GetGLHelper() = 0; 82 83 virtual void AddObserver(ImageTransportFactoryObserver* observer) = 0; 84 virtual void RemoveObserver(ImageTransportFactoryObserver* observer) = 0; 85 86 #if defined(OS_MACOSX) 87 virtual void OnSurfaceDisplayed(int surface_id) = 0; 88 #endif 89 }; 90 91 } // namespace content 92 93 #endif // CONTENT_BROWSER_COMPOSITOR_IMAGE_TRANSPORT_FACTORY_H_ 94