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.
5 #ifndef CONTENT_BROWSER_COMPOSITOR_IMAGE_TRANSPORT_FACTORY_H_
6 #define CONTENT_BROWSER_COMPOSITOR_IMAGE_TRANSPORT_FACTORY_H_
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"
31 class WebGraphicsContext3D
;
37 // This class provides a way to get notified when surface handles get lost.
38 class CONTENT_EXPORT ImageTransportFactoryObserver
{
40 virtual ~ImageTransportFactoryObserver() {}
42 // Notifies that the surface handles generated by ImageTransportFactory were
44 // When this is called, the old resources (e.g. shared context, GL helper)
45 // still exist, but are about to be destroyed. Getting a reference to those
46 // resources from the ImageTransportFactory (e.g. through GetGLHelper) will
47 // return newly recreated, valid resources.
48 virtual void OnLostResources() = 0;
51 // This class provides the interface for creating the support for the
52 // cross-process image transport, both for creating the shared surface handle
53 // (destination surface for the GPU process) and the transport client (logic for
54 // using that surface as a texture). The factory is a process-wide singleton.
55 class CONTENT_EXPORT ImageTransportFactory
{
57 virtual ~ImageTransportFactory() {}
59 // Initializes the global transport factory.
60 static void Initialize();
62 // Initializes the global transport factory for unit tests using the provided
64 static void InitializeForUnitTests(scoped_ptr
<ImageTransportFactory
> factory
);
66 // Terminates the global transport factory.
67 static void Terminate();
69 // Gets the factory instance.
70 static ImageTransportFactory
* GetInstance();
72 // Gets the image transport factory as a context factory for the compositor.
73 virtual ui::ContextFactory
* GetContextFactory() = 0;
75 virtual gfx::GLSurfaceHandle
GetSharedSurfaceHandle() = 0;
76 virtual cc::SurfaceManager
* GetSurfaceManager() = 0;
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;
83 virtual void AddObserver(ImageTransportFactoryObserver
* observer
) = 0;
84 virtual void RemoveObserver(ImageTransportFactoryObserver
* observer
) = 0;
86 #if defined(OS_MACOSX)
87 virtual void OnSurfaceDisplayed(int surface_id
) = 0;
88 // Called with |suspended| as true when the ui::Compositor has been
89 // disconnected from an NSView and may be attached to another one. Called
90 // with |suspended| as false after the ui::Compositor has been connected to
91 // a new NSView and the first commit targeted at the new NSView has
92 // completed. This ensures that content and frames intended for the old
93 // NSView will not flash in the new NSView.
94 virtual void SetCompositorSuspendedForRecycle(ui::Compositor
* compositor
,
96 // Used by GpuProcessHostUIShim to determine if a frame should not be
97 // displayed because it is targetted to an NSView that has been disconnected.
98 virtual bool SurfaceShouldNotShowFramesAfterSuspendForRecycle(
99 int surface_id
) const = 0;
103 } // namespace content
105 #endif // CONTENT_BROWSER_COMPOSITOR_IMAGE_TRANSPORT_FACTORY_H_