1 // Copyright (c) 2013 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_AURA_GPU_PROCESS_TRANSPORT_FACTORY_H_
6 #define CONTENT_BROWSER_AURA_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/aura/image_transport_factory.h"
16 #include "ui/compositor/compositor.h"
19 class BrowserCompositorOutputSurface
;
20 class BrowserCompositorOutputSurfaceProxy
;
21 class CompositorSwapClient
;
22 class ContextProviderCommandBuffer
;
24 class WebGraphicsContext3DCommandBufferImpl
;
26 class GpuProcessTransportFactory
27 : public ui::ContextFactory
,
28 public ImageTransportFactory
{
30 GpuProcessTransportFactory();
32 virtual ~GpuProcessTransportFactory();
34 scoped_ptr
<WebGraphicsContext3DCommandBufferImpl
>
35 CreateOffscreenCommandBufferContext();
37 // ui::ContextFactory implementation.
38 virtual scoped_ptr
<cc::OutputSurface
> CreateOutputSurface(
39 ui::Compositor
* compositor
, bool software_fallback
) OVERRIDE
;
40 virtual scoped_refptr
<ui::Reflector
> CreateReflector(
41 ui::Compositor
* source
,
42 ui::Layer
* target
) OVERRIDE
;
43 virtual void RemoveReflector(
44 scoped_refptr
<ui::Reflector
> reflector
) OVERRIDE
;
45 virtual void RemoveCompositor(ui::Compositor
* compositor
) OVERRIDE
;
46 virtual scoped_refptr
<cc::ContextProvider
>
47 OffscreenCompositorContextProvider() OVERRIDE
;
48 virtual scoped_refptr
<cc::ContextProvider
>
49 SharedMainThreadContextProvider() OVERRIDE
;
50 virtual bool DoesCreateTestContexts() OVERRIDE
;
52 // ImageTransportFactory implementation.
53 virtual ui::ContextFactory
* AsContextFactory() OVERRIDE
;
54 virtual gfx::GLSurfaceHandle
CreateSharedSurfaceHandle() OVERRIDE
;
55 virtual void DestroySharedSurfaceHandle(
56 gfx::GLSurfaceHandle surface
) OVERRIDE
;
57 virtual scoped_refptr
<ui::Texture
> CreateTransportClient(
58 float device_scale_factor
) OVERRIDE
;
59 virtual scoped_refptr
<ui::Texture
> CreateOwnedTexture(
60 const gfx::Size
& size
,
61 float device_scale_factor
,
62 unsigned int texture_id
) OVERRIDE
;
63 virtual GLHelper
* GetGLHelper() OVERRIDE
;
64 virtual void AddObserver(ImageTransportFactoryObserver
* observer
) OVERRIDE
;
65 virtual void RemoveObserver(
66 ImageTransportFactoryObserver
* observer
) OVERRIDE
;
69 struct PerCompositorData
;
71 PerCompositorData
* CreatePerCompositorData(ui::Compositor
* compositor
);
72 scoped_ptr
<WebGraphicsContext3DCommandBufferImpl
>
73 CreateContextCommon(int surface_id
);
75 void OnLostMainThreadSharedContextInsideCallback();
76 void OnLostMainThreadSharedContext();
78 typedef std::map
<ui::Compositor
*, PerCompositorData
*> PerCompositorDataMap
;
79 PerCompositorDataMap per_compositor_data_
;
80 scoped_refptr
<ContextProviderCommandBuffer
> offscreen_compositor_contexts_
;
81 scoped_refptr
<ContextProviderCommandBuffer
> shared_main_thread_contexts_
;
82 scoped_ptr
<GLHelper
> gl_helper_
;
83 ObserverList
<ImageTransportFactoryObserver
> observer_list_
;
84 base::WeakPtrFactory
<GpuProcessTransportFactory
> callback_factory_
;
86 // The contents of this map and its methods may only be used on the compositor
88 IDMap
<BrowserCompositorOutputSurface
> output_surface_map_
;
90 scoped_refptr
<BrowserCompositorOutputSurfaceProxy
> output_surface_proxy_
;
92 DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory
);
95 } // namespace content
97 #endif // CONTENT_BROWSER_AURA_GPU_PROCESS_TRANSPORT_FACTORY_H_