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"
29 class BrowserCompositorOutputSurface
;
30 class CompositorSwapClient
;
31 class ContextProviderCommandBuffer
;
33 class WebGraphicsContext3DCommandBufferImpl
;
35 class GpuProcessTransportFactory
36 : public ui::ContextFactory
,
37 public ImageTransportFactory
{
39 GpuProcessTransportFactory();
41 ~GpuProcessTransportFactory() override
;
43 scoped_ptr
<WebGraphicsContext3DCommandBufferImpl
>
44 CreateOffscreenCommandBufferContext();
46 // ui::ContextFactory implementation.
47 void CreateOutputSurface(base::WeakPtr
<ui::Compositor
> compositor
) override
;
48 scoped_ptr
<ui::Reflector
> CreateReflector(ui::Compositor
* source
,
49 ui::Layer
* target
) override
;
50 void RemoveReflector(ui::Reflector
* reflector
) override
;
51 void RemoveCompositor(ui::Compositor
* compositor
) override
;
52 scoped_refptr
<cc::ContextProvider
> SharedMainThreadContextProvider() override
;
53 bool DoesCreateTestContexts() override
;
54 uint32
GetImageTextureTarget() override
;
55 cc::SharedBitmapManager
* GetSharedBitmapManager() override
;
56 gpu::GpuMemoryBufferManager
* GetGpuMemoryBufferManager() override
;
57 cc::TaskGraphRunner
* GetTaskGraphRunner() override
;
58 scoped_ptr
<cc::SurfaceIdAllocator
> CreateSurfaceIdAllocator() override
;
59 void ResizeDisplay(ui::Compositor
* compositor
,
60 const gfx::Size
& size
) override
;
62 // ImageTransportFactory implementation.
63 ui::ContextFactory
* GetContextFactory() override
;
64 gfx::GLSurfaceHandle
GetSharedSurfaceHandle() override
;
65 cc::SurfaceManager
* GetSurfaceManager() override
;
66 GLHelper
* GetGLHelper() override
;
67 void AddObserver(ImageTransportFactoryObserver
* observer
) override
;
68 void RemoveObserver(ImageTransportFactoryObserver
* observer
) override
;
69 #if defined(OS_MACOSX)
70 void OnSurfaceDisplayed(int surface_id
) override
;
71 void OnCompositorRecycled(ui::Compositor
* compositor
) override
;
72 bool SurfaceShouldNotShowFramesAfterRecycle(int surface_id
) const override
;
76 struct PerCompositorData
;
78 PerCompositorData
* CreatePerCompositorData(ui::Compositor
* compositor
);
79 void EstablishedGpuChannel(base::WeakPtr
<ui::Compositor
> compositor
,
80 bool create_gpu_output_surface
,
82 scoped_ptr
<WebGraphicsContext3DCommandBufferImpl
> CreateContextCommon(
83 scoped_refptr
<GpuChannelHost
> gpu_channel_host
,
86 void OnLostMainThreadSharedContextInsideCallback();
87 void OnLostMainThreadSharedContext();
89 typedef std::map
<ui::Compositor
*, PerCompositorData
*> PerCompositorDataMap
;
90 PerCompositorDataMap per_compositor_data_
;
91 scoped_refptr
<ContextProviderCommandBuffer
> shared_main_thread_contexts_
;
92 scoped_ptr
<GLHelper
> gl_helper_
;
93 ObserverList
<ImageTransportFactoryObserver
> observer_list_
;
94 scoped_ptr
<cc::SurfaceManager
> surface_manager_
;
95 uint32_t next_surface_id_namespace_
;
96 scoped_ptr
<cc::TaskGraphRunner
> task_graph_runner_
;
97 scoped_ptr
<base::SimpleThread
> raster_thread_
;
99 // The contents of this map and its methods may only be used on the compositor
101 IDMap
<BrowserCompositorOutputSurface
> output_surface_map_
;
103 base::WeakPtrFactory
<GpuProcessTransportFactory
> callback_factory_
;
105 DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory
);
108 } // namespace content
110 #endif // CONTENT_BROWSER_COMPOSITOR_GPU_PROCESS_TRANSPORT_FACTORY_H_