Home | History | Annotate | Download | only in android
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_ANDROID_H_
      6 #define CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_ANDROID_H_
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "cc/layers/video_frame_provider.h"
     10 #include "gpu/command_buffer/common/mailbox.h"
     11 #include "ui/gfx/size.h"
     12 
     13 namespace content {
     14 
     15 // The proxy class for the gpu thread to notify the compositor thread
     16 // when a new video frame is available.
     17 class StreamTextureProxy {
     18  public:
     19   virtual ~StreamTextureProxy() {}
     20 
     21   // Initialize and bind to the current thread, which becomes the thread that
     22   // a connected client will receive callbacks on.
     23   virtual void BindToCurrentThread(int32 stream_id) = 0;
     24 
     25   virtual bool IsBoundToThread() = 0;
     26 
     27   // Setting the target for callback when a frame is available. This function
     28   // could be called on both the main thread and the compositor thread.
     29   virtual void SetClient(cc::VideoFrameProvider::Client* client) = 0;
     30 
     31   // Causes this instance to be deleted on the thread it is bound to.
     32   virtual void Release() = 0;
     33 
     34   struct Deleter {
     35     inline void operator()(StreamTextureProxy* ptr) const { ptr->Release(); }
     36   };
     37 };
     38 
     39 typedef scoped_ptr<StreamTextureProxy, StreamTextureProxy::Deleter>
     40     ScopedStreamTextureProxy;
     41 
     42 // Factory class for managing stream textures.
     43 class StreamTextureFactory {
     44  public:
     45   virtual ~StreamTextureFactory() {}
     46 
     47   // Create the StreamTextureProxy object.
     48   virtual StreamTextureProxy* CreateProxy() = 0;
     49 
     50   // Send an IPC message to the browser process to request a java surface
     51   // object for the given stream_id. After the the surface is created,
     52   // it will be passed back to the WebMediaPlayerAndroid object identified by
     53   // the player_id.
     54   virtual void EstablishPeer(int32 stream_id, int player_id) = 0;
     55 
     56   // Create the streamTexture and return the stream Id and create a client-side
     57   // texture id to refer to the streamTexture. The texture id is produced into
     58   // a mailbox so it can be used to ship in a VideoFrame, with a sync point for
     59   // when the mailbox can be accessed.
     60   virtual unsigned CreateStreamTexture(
     61       unsigned texture_target,
     62       unsigned* texture_id,
     63       gpu::Mailbox* texture_mailbox,
     64       unsigned* texture_mailbox_sync_point) = 0;
     65 
     66   // Destroy the streamTexture for the given texture id, as well as the
     67   // client side texture.
     68   virtual void DestroyStreamTexture(unsigned texture_id) = 0;
     69 
     70   // Set the streamTexture size for the given stream Id.
     71   virtual void SetStreamTextureSize(int32 texture_id,
     72                                     const gfx::Size& size) = 0;
     73 };
     74 
     75 }  // namespace content
     76 
     77 #endif  // CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_ANDROID_H_
     78