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_GPU_PROCESS_TRANSPORT_FACTORY_H_
6 #define CONTENT_BROWSER_COMPOSITOR_GPU_PROCESS_TRANSPORT_FACTORY_H_
10 #include "base/id_map.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h"
15 #include "content/browser/compositor/image_transport_factory.h"
16 #include "ui/compositor/compositor.h"
27 class BrowserCompositorOutputSurface
;
28 class BrowserCompositorOutputSurfaceProxy
;
29 class CompositorSwapClient
;
30 class ContextProviderCommandBuffer
;
32 class WebGraphicsContext3DCommandBufferImpl
;
34 class GpuProcessTransportFactory
35 : public ui::ContextFactory
,
36 public ImageTransportFactory
{
38 GpuProcessTransportFactory();
40 virtual ~GpuProcessTransportFactory();
42 scoped_ptr
<WebGraphicsContext3DCommandBufferImpl
>
43 CreateOffscreenCommandBufferContext();
45 // ui::ContextFactory implementation.
46 virtual scoped_ptr
<cc::OutputSurface
> CreateOutputSurface(
47 ui::Compositor
* compositor
, bool software_fallback
) OVERRIDE
;
48 virtual scoped_refptr
<ui::Reflector
> CreateReflector(
49 ui::Compositor
* source
,
50 ui::Layer
* target
) OVERRIDE
;
51 virtual void RemoveReflector(
52 scoped_refptr
<ui::Reflector
> reflector
) OVERRIDE
;
53 virtual void RemoveCompositor(ui::Compositor
* compositor
) OVERRIDE
;
54 virtual scoped_refptr
<cc::ContextProvider
>
55 SharedMainThreadContextProvider() OVERRIDE
;
56 virtual bool DoesCreateTestContexts() OVERRIDE
;
57 virtual cc::SharedBitmapManager
* GetSharedBitmapManager() OVERRIDE
;
58 virtual base::MessageLoopProxy
* GetCompositorMessageLoop() OVERRIDE
;
60 // ImageTransportFactory implementation.
61 virtual ui::ContextFactory
* GetContextFactory() OVERRIDE
;
62 virtual gfx::GLSurfaceHandle
GetSharedSurfaceHandle() OVERRIDE
;
63 virtual GLHelper
* GetGLHelper() OVERRIDE
;
64 virtual void AddObserver(ImageTransportFactoryObserver
* observer
) OVERRIDE
;
65 virtual void RemoveObserver(
66 ImageTransportFactoryObserver
* observer
) OVERRIDE
;
67 #if defined(OS_MACOSX)
68 virtual void OnSurfaceDisplayed(int surface_id
) OVERRIDE
;
72 struct PerCompositorData
;
74 PerCompositorData
* CreatePerCompositorData(ui::Compositor
* compositor
);
75 scoped_ptr
<WebGraphicsContext3DCommandBufferImpl
>
76 CreateContextCommon(int surface_id
);
78 void OnLostMainThreadSharedContextInsideCallback();
79 void OnLostMainThreadSharedContext();
81 typedef std::map
<ui::Compositor
*, PerCompositorData
*> PerCompositorDataMap
;
82 scoped_ptr
<base::Thread
> compositor_thread_
;
83 PerCompositorDataMap per_compositor_data_
;
84 scoped_refptr
<ContextProviderCommandBuffer
> shared_main_thread_contexts_
;
85 scoped_ptr
<GLHelper
> gl_helper_
;
86 ObserverList
<ImageTransportFactoryObserver
> observer_list_
;
87 base::WeakPtrFactory
<GpuProcessTransportFactory
> callback_factory_
;
88 scoped_ptr
<cc::SurfaceManager
> surface_manager_
;
90 // The contents of this map and its methods may only be used on the compositor
92 IDMap
<BrowserCompositorOutputSurface
> output_surface_map_
;
94 scoped_refptr
<BrowserCompositorOutputSurfaceProxy
> output_surface_proxy_
;
96 DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory
);
99 } // namespace content
101 #endif // CONTENT_BROWSER_COMPOSITOR_GPU_PROCESS_TRANSPORT_FACTORY_H_