Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / content / browser / compositor / gpu_process_transport_factory.h
blob564b3cd97eb2d2b3140e413dd10def1539ea246b
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_
8 #include <map>
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"
19 namespace base {
20 class SimpleThread;
21 class Thread;
24 namespace cc {
25 class SoftwareOutputDevice;
26 class SurfaceManager;
29 namespace content {
30 class BrowserCompositorOutputSurface;
31 class CompositorSwapClient;
32 class ContextProviderCommandBuffer;
33 class OutputDeviceBacking;
34 class ReflectorImpl;
35 class WebGraphicsContext3DCommandBufferImpl;
37 class GpuProcessTransportFactory
38 : public ui::ContextFactory,
39 public ImageTransportFactory {
40 public:
41 GpuProcessTransportFactory();
43 ~GpuProcessTransportFactory() override;
45 scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
46 CreateOffscreenCommandBufferContext();
48 // ui::ContextFactory implementation.
49 void CreateOutputSurface(base::WeakPtr<ui::Compositor> compositor) override;
50 scoped_ptr<ui::Reflector> CreateReflector(ui::Compositor* source,
51 ui::Layer* target) override;
52 void RemoveReflector(ui::Reflector* reflector) override;
53 void RemoveCompositor(ui::Compositor* compositor) override;
54 scoped_refptr<cc::ContextProvider> SharedMainThreadContextProvider() override;
55 bool DoesCreateTestContexts() override;
56 uint32 GetImageTextureTarget(gfx::BufferFormat format,
57 gfx::BufferUsage usage) override;
58 cc::SharedBitmapManager* GetSharedBitmapManager() override;
59 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override;
60 cc::TaskGraphRunner* GetTaskGraphRunner() override;
61 scoped_ptr<cc::SurfaceIdAllocator> CreateSurfaceIdAllocator() override;
62 void ResizeDisplay(ui::Compositor* compositor,
63 const gfx::Size& size) override;
65 // ImageTransportFactory implementation.
66 ui::ContextFactory* GetContextFactory() override;
67 gfx::GLSurfaceHandle GetSharedSurfaceHandle() override;
68 cc::SurfaceManager* GetSurfaceManager() override;
69 GLHelper* GetGLHelper() override;
70 void AddObserver(ImageTransportFactoryObserver* observer) override;
71 void RemoveObserver(ImageTransportFactoryObserver* observer) override;
72 #if defined(OS_MACOSX)
73 void OnSurfaceDisplayed(int surface_id) override;
74 void SetCompositorSuspendedForRecycle(ui::Compositor* compositor,
75 bool suspended) override;
76 bool SurfaceShouldNotShowFramesAfterSuspendForRecycle(
77 int surface_id) const override;
78 #endif
80 private:
81 struct PerCompositorData;
83 PerCompositorData* CreatePerCompositorData(ui::Compositor* compositor);
84 scoped_ptr<cc::SoftwareOutputDevice> CreateSoftwareOutputDevice(
85 ui::Compositor* compositor);
86 void EstablishedGpuChannel(base::WeakPtr<ui::Compositor> compositor,
87 bool create_gpu_output_surface,
88 int num_attempts);
89 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateContextCommon(
90 scoped_refptr<GpuChannelHost> gpu_channel_host,
91 int surface_id);
93 void OnLostMainThreadSharedContextInsideCallback();
94 void OnLostMainThreadSharedContext();
96 typedef std::map<ui::Compositor*, PerCompositorData*> PerCompositorDataMap;
97 PerCompositorDataMap per_compositor_data_;
98 scoped_refptr<ContextProviderCommandBuffer> shared_main_thread_contexts_;
99 scoped_ptr<GLHelper> gl_helper_;
100 base::ObserverList<ImageTransportFactoryObserver> observer_list_;
101 scoped_ptr<cc::SurfaceManager> surface_manager_;
102 uint32_t next_surface_id_namespace_;
103 scoped_ptr<cc::TaskGraphRunner> task_graph_runner_;
104 scoped_ptr<base::SimpleThread> raster_thread_;
105 scoped_refptr<ContextProviderCommandBuffer> shared_worker_context_provider_;
107 #if defined(OS_WIN)
108 scoped_ptr<OutputDeviceBacking> software_backing_;
109 #endif
111 // The contents of this map and its methods may only be used on the compositor
112 // thread.
113 IDMap<BrowserCompositorOutputSurface> output_surface_map_;
115 base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_;
117 DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory);
120 } // namespace content
122 #endif // CONTENT_BROWSER_COMPOSITOR_GPU_PROCESS_TRANSPORT_FACTORY_H_