• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_SYNCHRONOUS_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_SYNCHRONOUS_IMPL_H_
7 
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/observer_list.h"
11 #include "content/renderer/media/android/stream_texture_factory.h"
12 
13 namespace gfx {
14 class SurfaceTexture;
15 }
16 
17 namespace gpu {
18 namespace gles2 {
19 class GLES2Interface;
20 }  //  namespace gles2
21 }  //  namespace gpu
22 
23 namespace content {
24 
25 // Factory for when using synchronous compositor in Android WebView.
26 class StreamTextureFactorySynchronousImpl : public StreamTextureFactory {
27  public:
28   class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
29    public:
30     virtual scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture(
31         uint32 stream_id) = 0;
32 
33     virtual gpu::gles2::GLES2Interface* ContextGL() = 0;
34 
35     virtual void AddObserver(StreamTextureFactoryContextObserver* obs) = 0;
36     virtual void RemoveObserver(StreamTextureFactoryContextObserver* obs) = 0;
37 
38    protected:
39     friend class base::RefCountedThreadSafe<ContextProvider>;
~ContextProvider()40     virtual ~ContextProvider() {}
41   };
42 
43   typedef base::Callback<scoped_refptr<ContextProvider>(void)>
44       CreateContextProviderCallback;
45 
46   static scoped_refptr<StreamTextureFactorySynchronousImpl> Create(
47       const CreateContextProviderCallback& try_create_callback,
48       int frame_id);
49 
50   virtual StreamTextureProxy* CreateProxy() OVERRIDE;
51   virtual void EstablishPeer(int32 stream_id, int player_id) OVERRIDE;
52   virtual unsigned CreateStreamTexture(unsigned texture_target,
53                                        unsigned* texture_id,
54                                        gpu::Mailbox* texture_mailbox) OVERRIDE;
55   virtual void SetStreamTextureSize(int32 stream_id,
56                                     const gfx::Size& size) OVERRIDE;
57   virtual gpu::gles2::GLES2Interface* ContextGL() OVERRIDE;
58   virtual void AddObserver(StreamTextureFactoryContextObserver* obs) OVERRIDE;
59   virtual void RemoveObserver(
60       StreamTextureFactoryContextObserver* obs) OVERRIDE;
61 
62  private:
63   friend class base::RefCounted<StreamTextureFactorySynchronousImpl>;
64   StreamTextureFactorySynchronousImpl(
65       const CreateContextProviderCallback& try_create_callback,
66       int frame_id);
67   virtual ~StreamTextureFactorySynchronousImpl();
68 
69   CreateContextProviderCallback create_context_provider_callback_;
70   scoped_refptr<ContextProvider> context_provider_;
71   int frame_id_;
72   StreamTextureFactoryContextObserver* observer_;
73 
74   DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureFactorySynchronousImpl);
75 };
76 
77 }  // namespace content
78 
79 #endif  // CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_SYNCHRONOUS_IMPL_H_
80