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 "content/common/gpu/client/gpu_channel_host.h"
17 #include "ui/compositor/compositor.h"
28 class BrowserCompositorOutputSurface
;
29 class CompositorSwapClient
;
30 class ContextProviderCommandBuffer
;
32 class WebGraphicsContext3DCommandBufferImpl
;
34 class GpuProcessTransportFactory
35 : public ui::ContextFactory
,
36 public ImageTransportFactory
{
38 GpuProcessTransportFactory();
40 ~GpuProcessTransportFactory() override
;
42 scoped_ptr
<WebGraphicsContext3DCommandBufferImpl
>
43 CreateOffscreenCommandBufferContext();
45 // ui::ContextFactory implementation.
46 void CreateOutputSurface(base::WeakPtr
<ui::Compositor
> compositor
) override
;
47 scoped_ptr
<ui::Reflector
> CreateReflector(ui::Compositor
* source
,
48 ui::Layer
* target
) override
;
49 void RemoveReflector(ui::Reflector
* reflector
) override
;
50 void RemoveCompositor(ui::Compositor
* compositor
) override
;
51 scoped_refptr
<cc::ContextProvider
> SharedMainThreadContextProvider() override
;
52 bool DoesCreateTestContexts() override
;
53 uint32
GetImageTextureTarget() override
;
54 cc::SharedBitmapManager
* GetSharedBitmapManager() override
;
55 gpu::GpuMemoryBufferManager
* GetGpuMemoryBufferManager() override
;
56 scoped_ptr
<cc::SurfaceIdAllocator
> CreateSurfaceIdAllocator() override
;
57 void ResizeDisplay(ui::Compositor
* compositor
,
58 const gfx::Size
& size
) override
;
60 // ImageTransportFactory implementation.
61 ui::ContextFactory
* GetContextFactory() override
;
62 gfx::GLSurfaceHandle
GetSharedSurfaceHandle() override
;
63 cc::SurfaceManager
* GetSurfaceManager() override
;
64 GLHelper
* GetGLHelper() override
;
65 void AddObserver(ImageTransportFactoryObserver
* observer
) override
;
66 void RemoveObserver(ImageTransportFactoryObserver
* observer
) override
;
67 #if defined(OS_MACOSX)
68 void OnSurfaceDisplayed(int surface_id
) override
;
69 void OnCompositorRecycled(ui::Compositor
* compositor
) override
;
70 bool SurfaceShouldNotShowFramesAfterRecycle(int surface_id
) const override
;
74 struct PerCompositorData
;
76 PerCompositorData
* CreatePerCompositorData(ui::Compositor
* compositor
);
77 void EstablishedGpuChannel(base::WeakPtr
<ui::Compositor
> compositor
,
78 bool create_gpu_output_surface
,
80 scoped_ptr
<WebGraphicsContext3DCommandBufferImpl
> CreateContextCommon(
81 scoped_refptr
<GpuChannelHost
> gpu_channel_host
,
84 void OnLostMainThreadSharedContextInsideCallback();
85 void OnLostMainThreadSharedContext();
87 typedef std::map
<ui::Compositor
*, PerCompositorData
*> PerCompositorDataMap
;
88 PerCompositorDataMap per_compositor_data_
;
89 scoped_refptr
<ContextProviderCommandBuffer
> shared_main_thread_contexts_
;
90 scoped_ptr
<GLHelper
> gl_helper_
;
91 ObserverList
<ImageTransportFactoryObserver
> observer_list_
;
92 scoped_ptr
<cc::SurfaceManager
> surface_manager_
;
93 uint32_t next_surface_id_namespace_
;
95 // The contents of this map and its methods may only be used on the compositor
97 IDMap
<BrowserCompositorOutputSurface
> output_surface_map_
;
99 base::WeakPtrFactory
<GpuProcessTransportFactory
> callback_factory_
;
101 DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory
);
104 } // namespace content
106 #endif // CONTENT_BROWSER_COMPOSITOR_GPU_PROCESS_TRANSPORT_FACTORY_H_