| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_ANDROID_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_ANDROID_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_ANDROID_H_ | 6 #define CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_ANDROID_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "cc/layers/video_frame_provider.h" | 9 #include "cc/layers/video_frame_provider.h" |
| 10 #include "content/renderer/gpu/stream_texture_host_android.h" | |
| 11 #include "gpu/command_buffer/common/mailbox.h" | 10 #include "gpu/command_buffer/common/mailbox.h" |
| 12 | 11 #include "ui/gfx/size.h" |
| 13 namespace WebKit { | |
| 14 class WebGraphicsContext3D; | |
| 15 } | |
| 16 | 12 |
| 17 namespace content { | 13 namespace content { |
| 18 | 14 |
| 19 // The proxy class for the gpu thread to notify the compositor thread | 15 // The proxy class for the gpu thread to notify the compositor thread |
| 20 // when a new video frame is available. | 16 // when a new video frame is available. |
| 21 class StreamTextureProxy : public StreamTextureHost::Listener { | 17 class StreamTextureProxy { |
| 22 public: | 18 public: |
| 23 explicit StreamTextureProxy(StreamTextureHost* host); | 19 virtual ~StreamTextureProxy() {} |
| 24 virtual ~StreamTextureProxy(); | |
| 25 | 20 |
| 26 // Initialize and bind to the current thread, which becomes the thread that | 21 // Initialize and bind to the current thread, which becomes the thread that |
| 27 // a connected client will receive callbacks on. | 22 // a connected client will receive callbacks on. |
| 28 void BindToCurrentThread(int32 stream_id); | 23 virtual void BindToCurrentThread(int32 stream_id) = 0; |
| 29 | 24 |
| 30 bool IsBoundToThread() { return loop_.get() != NULL; } | 25 virtual bool IsBoundToThread() = 0; |
| 31 | 26 |
| 32 // Setting the target for callback when a frame is available. This function | 27 // Setting the target for callback when a frame is available. This function |
| 33 // could be called on both the main thread and the compositor thread. | 28 // could be called on both the main thread and the compositor thread. |
| 34 void SetClient(cc::VideoFrameProvider::Client* client); | 29 virtual void SetClient(cc::VideoFrameProvider::Client* client) = 0; |
| 35 | 30 |
| 36 // StreamTextureHost::Listener implementation: | 31 // Causes this instance to be deleted on the thread it is bound to. |
| 37 virtual void OnFrameAvailable() OVERRIDE; | 32 virtual void Release() = 0; |
| 38 virtual void OnMatrixChanged(const float matrix[16]) OVERRIDE; | |
| 39 | 33 |
| 40 struct Deleter { | 34 struct Deleter { |
| 41 inline void operator()(StreamTextureProxy* ptr) const { ptr->Release(); } | 35 inline void operator()(StreamTextureProxy* ptr) const { ptr->Release(); } |
| 42 }; | 36 }; |
| 43 | |
| 44 private: | |
| 45 // Causes this instance to be deleted on the thread it is bound to. | |
| 46 void Release(); | |
| 47 | |
| 48 scoped_ptr<StreamTextureHost> host_; | |
| 49 scoped_refptr<base::MessageLoopProxy> loop_; | |
| 50 | |
| 51 base::Lock client_lock_; | |
| 52 cc::VideoFrameProvider::Client* client_; | |
| 53 | |
| 54 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxy); | |
| 55 }; | 37 }; |
| 56 | 38 |
| 57 typedef scoped_ptr<StreamTextureProxy, StreamTextureProxy::Deleter> | 39 typedef scoped_ptr<StreamTextureProxy, StreamTextureProxy::Deleter> |
| 58 ScopedStreamTextureProxy; | 40 ScopedStreamTextureProxy; |
| 59 | 41 |
| 60 // Factory class for managing stream textures. | 42 // Factory class for managing stream textures. |
| 61 class StreamTextureFactory { | 43 class StreamTextureFactory { |
| 62 public: | 44 public: |
| 63 StreamTextureFactory(WebKit::WebGraphicsContext3D* context, | 45 virtual ~StreamTextureFactory() {} |
| 64 GpuChannelHost* channel, | |
| 65 int view_id); | |
| 66 ~StreamTextureFactory(); | |
| 67 | 46 |
| 68 // Create the StreamTextureProxy object. | 47 // Create the StreamTextureProxy object. |
| 69 StreamTextureProxy* CreateProxy(); | 48 virtual StreamTextureProxy* CreateProxy() = 0; |
| 70 | 49 |
| 71 // Send an IPC message to the browser process to request a java surface | 50 // Send an IPC message to the browser process to request a java surface |
| 72 // object for the given stream_id. After the the surface is created, | 51 // object for the given stream_id. After the the surface is created, |
| 73 // it will be passed back to the WebMediaPlayerAndroid object identified by | 52 // it will be passed back to the WebMediaPlayerAndroid object identified by |
| 74 // the player_id. | 53 // the player_id. |
| 75 void EstablishPeer(int32 stream_id, int player_id); | 54 virtual void EstablishPeer(int32 stream_id, int player_id) = 0; |
| 76 | 55 |
| 77 // Create the streamTexture and return the stream Id and create a client-side | 56 // Create the streamTexture and return the stream Id and create a client-side |
| 78 // texture id to refer to the streamTexture. The texture id is produced into | 57 // texture id to refer to the streamTexture. The texture id is produced into |
| 79 // a mailbox so it can be used to ship in a VideoFrame, with a sync point for | 58 // a mailbox so it can be used to ship in a VideoFrame, with a sync point for |
| 80 // when the mailbox can be accessed. | 59 // when the mailbox can be accessed. |
| 81 unsigned CreateStreamTexture( | 60 virtual unsigned CreateStreamTexture( |
| 82 unsigned texture_target, | 61 unsigned texture_target, |
| 83 unsigned* texture_id, | 62 unsigned* texture_id, |
| 84 gpu::Mailbox* texture_mailbox, | 63 gpu::Mailbox* texture_mailbox, |
| 85 unsigned* texture_mailbox_sync_point); | 64 unsigned* texture_mailbox_sync_point) = 0; |
| 86 | 65 |
| 87 // Destroy the streamTexture for the given texture id, as well as the | 66 // Destroy the streamTexture for the given texture id, as well as the |
| 88 // client side texture. | 67 // client side texture. |
| 89 void DestroyStreamTexture(unsigned texture_id); | 68 virtual void DestroyStreamTexture(unsigned texture_id) = 0; |
| 90 | 69 |
| 91 // Set the streamTexture size for the given stream Id. | 70 // Set the streamTexture size for the given stream Id. |
| 92 void SetStreamTextureSize(int32 texture_id, const gfx::Size& size); | 71 virtual void SetStreamTextureSize(int32 texture_id, |
| 93 | 72 const gfx::Size& size) = 0; |
| 94 private: | |
| 95 WebKit::WebGraphicsContext3D* context_; | |
| 96 scoped_refptr<GpuChannelHost> channel_; | |
| 97 int view_id_; | |
| 98 | |
| 99 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureFactory); | |
| 100 }; | 73 }; |
| 101 | 74 |
| 102 } // namespace content | 75 } // namespace content |
| 103 | 76 |
| 104 #endif // CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_ANDROID_H_ | 77 #endif // CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_ANDROID_H_ |
| OLD | NEW |