1 // Copyright (c) 2012 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_AURA_IMAGE_TRANSPORT_FACTORY_H_ 6 #define CONTENT_BROWSER_AURA_IMAGE_TRANSPORT_FACTORY_H_ 7 8 #include <string> 9 10 #include "base/memory/ref_counted.h" 11 #include "ui/gfx/native_widget_types.h" 12 13 namespace gfx { 14 class Size; 15 } 16 17 namespace ui { 18 class ContextFactory; 19 class Texture; 20 } 21 22 namespace WebKit { 23 class WebGraphicsContext3D; 24 } 25 26 namespace content { 27 class GLHelper; 28 29 // This class provides a way to get notified when surface handles get lost. 30 class ImageTransportFactoryObserver { 31 public: 32 virtual ~ImageTransportFactoryObserver() {} 33 34 // Notifies that the surface handles generated by ImageTransportFactory were 35 // lost. 36 // When this is called, the old resources (e.g. shared context, GL helper) 37 // still exist, but are about to be destroyed. Getting a reference to those 38 // resources from the ImageTransportFactory (e.g. through GetGLHelper) will 39 // return newly recreated, valid resources. 40 virtual void OnLostResources() = 0; 41 }; 42 43 // This class provides the interface for creating the support for the 44 // cross-process image transport, both for creating the shared surface handle 45 // (destination surface for the GPU process) and the transport client (logic for 46 // using that surface as a texture). The factory is a process-wide singleton. 47 class ImageTransportFactory { 48 public: 49 virtual ~ImageTransportFactory() {} 50 51 // Initialize the global transport factory. 52 static void Initialize(); 53 54 // Terminates the global transport factory. 55 static void Terminate(); 56 57 // Gets the factory instance. 58 static ImageTransportFactory* GetInstance(); 59 60 // Gets the image transport factory as a context factory for the compositor. 61 virtual ui::ContextFactory* AsContextFactory() = 0; 62 63 // Creates a shared surface handle. 64 // Note: the handle may get lost at any time, a state that an 65 // ImageTransportFactoryObserver gets notified of. 66 virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() = 0; 67 68 // Destroys a shared surface handle. 69 virtual void DestroySharedSurfaceHandle(gfx::GLSurfaceHandle surface) = 0; 70 71 // Creates a transport texture for a given scale factor. 72 virtual scoped_refptr<ui::Texture> CreateTransportClient( 73 float device_scale_factor) = 0; 74 75 // Variant of CreateTransportClient() that deletes the texture on the GPU when 76 // the returned value is deleted. 77 virtual scoped_refptr<ui::Texture> CreateOwnedTexture( 78 const gfx::Size& size, 79 float device_scale_factor, 80 unsigned int texture_id) = 0; 81 82 // Gets a GLHelper instance, associated with the shared context. This 83 // GLHelper will get destroyed whenever the shared context is lost 84 // (ImageTransportFactoryObserver::OnLostResources is called). 85 virtual GLHelper* GetGLHelper() = 0; 86 87 // Inserts a SyncPoint into the shared context. 88 virtual uint32 InsertSyncPoint() = 0; 89 90 // Blocks waiting for the sync point on the service side. 91 virtual void WaitSyncPoint(uint32 sync_point) = 0; 92 93 virtual void AddObserver(ImageTransportFactoryObserver* observer) = 0; 94 virtual void RemoveObserver(ImageTransportFactoryObserver* observer) = 0; 95 }; 96 97 } // namespace content 98 99 #endif // CONTENT_BROWSER_AURA_IMAGE_TRANSPORT_FACTORY_H_ 100