Home | History | Annotate | Download | only in aura
      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.
      4 
      5 #ifndef CONTENT_BROWSER_AURA_GPU_PROCESS_TRANSPORT_FACTORY_H_
      6 #define CONTENT_BROWSER_AURA_GPU_PROCESS_TRANSPORT_FACTORY_H_
      7 
      8 #include <map>
      9 
     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"
     17 
     18 namespace content {
     19 class BrowserCompositorOutputSurface;
     20 class BrowserCompositorOutputSurfaceProxy;
     21 class CompositorSwapClient;
     22 class ContextProviderCommandBuffer;
     23 class ReflectorImpl;
     24 class WebGraphicsContext3DCommandBufferImpl;
     25 class WebGraphicsContext3DSwapBuffersClient;
     26 
     27 class GpuProcessTransportFactory
     28     : public ui::ContextFactory,
     29       public ImageTransportFactory {
     30  public:
     31   GpuProcessTransportFactory();
     32 
     33   virtual ~GpuProcessTransportFactory();
     34 
     35   scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
     36   CreateOffscreenCommandBufferContext();
     37 
     38   // ContextFactory implementation.
     39   virtual scoped_ptr<WebKit::WebGraphicsContext3D> CreateOffscreenContext()
     40       OVERRIDE;
     41   virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(
     42       ui::Compositor* compositor) OVERRIDE;
     43   virtual scoped_refptr<ui::Reflector> CreateReflector(
     44       ui::Compositor* source,
     45       ui::Layer* target) OVERRIDE;
     46   virtual void RemoveReflector(
     47       scoped_refptr<ui::Reflector> reflector) OVERRIDE;
     48   virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE;
     49   virtual bool DoesCreateTestContexts() OVERRIDE;
     50 
     51   // ImageTransportFactory implementation.
     52   virtual ui::ContextFactory* AsContextFactory() OVERRIDE;
     53   virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE;
     54   virtual void DestroySharedSurfaceHandle(
     55       gfx::GLSurfaceHandle surface) OVERRIDE;
     56   virtual scoped_refptr<ui::Texture> CreateTransportClient(
     57       float device_scale_factor) OVERRIDE;
     58   virtual scoped_refptr<ui::Texture> CreateOwnedTexture(
     59       const gfx::Size& size,
     60       float device_scale_factor,
     61       unsigned int texture_id) OVERRIDE;
     62   virtual GLHelper* GetGLHelper() OVERRIDE;
     63   virtual uint32 InsertSyncPoint() OVERRIDE;
     64   virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE;
     65   virtual void AddObserver(ImageTransportFactoryObserver* observer) OVERRIDE;
     66   virtual void RemoveObserver(
     67       ImageTransportFactoryObserver* observer) OVERRIDE;
     68 
     69   // ui::ContextFactory implementation.
     70   virtual scoped_refptr<cc::ContextProvider>
     71       OffscreenContextProviderForMainThread() OVERRIDE;
     72   virtual scoped_refptr<cc::ContextProvider>
     73       OffscreenContextProviderForCompositorThread() OVERRIDE;
     74 
     75   void OnLostContext(ui::Compositor* compositor);
     76 
     77  private:
     78   struct PerCompositorData;
     79 
     80   PerCompositorData* CreatePerCompositorData(ui::Compositor* compositor);
     81   scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateContextCommon(
     82       const base::WeakPtr<WebGraphicsContext3DSwapBuffersClient>& swap_client,
     83       int surface_id);
     84 
     85   void CreateSharedContextLazy();
     86 
     87   void OnLostMainThreadSharedContextInsideCallback();
     88   void OnLostMainThreadSharedContext();
     89 
     90   typedef std::map<ui::Compositor*, PerCompositorData*> PerCompositorDataMap;
     91   PerCompositorDataMap per_compositor_data_;
     92   scoped_refptr<ContextProviderCommandBuffer> shared_contexts_main_thread_;
     93   scoped_refptr<ContextProviderCommandBuffer>
     94       shared_contexts_compositor_thread_;
     95   scoped_ptr<GLHelper> gl_helper_;
     96   ObserverList<ImageTransportFactoryObserver> observer_list_;
     97   base::WeakPtrFactory<GpuProcessTransportFactory> callback_factory_;
     98 
     99   // The contents of this map and its methods may only be used on the compositor
    100   // thread.
    101   IDMap<BrowserCompositorOutputSurface> output_surface_map_;
    102 
    103   scoped_refptr<BrowserCompositorOutputSurfaceProxy> output_surface_proxy_;
    104 
    105   DISALLOW_COPY_AND_ASSIGN(GpuProcessTransportFactory);
    106 };
    107 
    108 }  // namespace content
    109 
    110 #endif  // CONTENT_BROWSER_AURA_GPU_PROCESS_TRANSPORT_FACTORY_H_
    111