Home | History | Annotate | Download | only in gpu
      1 // Copyright (c) 2012 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_COMMON_GPU_STREAM_TEXTURE_MANAGER_ANDROID_H_
      6 #define CONTENT_COMMON_GPU_STREAM_TEXTURE_MANAGER_ANDROID_H_
      7 
      8 #include "base/callback.h"
      9 #include "base/id_map.h"
     10 #include "base/memory/scoped_ptr.h"
     11 #include "base/memory/weak_ptr.h"
     12 #include "content/common/android/surface_texture_peer.h"
     13 #include "gpu/command_buffer/service/stream_texture.h"
     14 #include "gpu/command_buffer/service/stream_texture_manager.h"
     15 
     16 struct GpuStreamTextureMsg_MatrixChanged_Params;
     17 
     18 namespace gfx {
     19 class Size;
     20 class SurfaceTextureBridge;
     21 }
     22 
     23 namespace content {
     24 class GpuChannel;
     25 
     26 // Class for managing the stream texture.
     27 class StreamTextureManagerAndroid : public gpu::StreamTextureManager {
     28  public:
     29   StreamTextureManagerAndroid(GpuChannel* channel);
     30   virtual ~StreamTextureManagerAndroid();
     31 
     32   // implement gpu::StreamTextureManager:
     33   virtual uint32 CreateStreamTexture(uint32 service_id,
     34                                      uint32 client_id) OVERRIDE;
     35   virtual void DestroyStreamTexture(uint32 service_id) OVERRIDE;
     36   virtual gpu::StreamTexture* LookupStreamTexture(uint32 service_id) OVERRIDE;
     37 
     38   // Methods invoked from GpuChannel.
     39   void RegisterStreamTextureProxy(int32 stream_id, int32 route_id);
     40   void EstablishStreamTexture(
     41       int32 stream_id, int32 primary_id, int32 secondary_id);
     42   void SetStreamTextureSize(int32 stream_id, const gfx::Size& size);
     43 
     44   // Send new transform matrix.
     45   void SendMatrixChanged(int route_id,
     46       const GpuStreamTextureMsg_MatrixChanged_Params& params);
     47 
     48  private:
     49   // The stream texture class for android.
     50   class StreamTextureAndroid
     51       : public gpu::StreamTexture,
     52         public base::SupportsWeakPtr<StreamTextureAndroid> {
     53    public:
     54     StreamTextureAndroid(GpuChannel* channel, int service_id);
     55     virtual ~StreamTextureAndroid();
     56 
     57     virtual void Update() OVERRIDE;
     58     virtual gfx::Size GetSize() OVERRIDE;
     59 
     60     scoped_refptr<gfx::SurfaceTextureBridge> surface_texture_bridge() {
     61         return surface_texture_bridge_;
     62     }
     63 
     64     // Called when a new frame is available.
     65     void OnFrameAvailable(int route_id);
     66 
     67     // Set surface texture size.
     68     void SetSize(const gfx::Size& size) { size_ = size; }
     69 
     70     // Callback function when transform matrix of the surface texture
     71     // has changed.
     72     typedef base::Callback<
     73         void(const GpuStreamTextureMsg_MatrixChanged_Params&)>
     74             MatrixChangedCB;
     75 
     76     void set_matrix_changed_callback(const MatrixChangedCB& callback) {
     77         matrix_callback_ = callback;
     78     }
     79 
     80    private:
     81     scoped_refptr<gfx::SurfaceTextureBridge> surface_texture_bridge_;
     82 
     83     // Current transform matrix of the surface texture.
     84     float current_matrix_[16];
     85 
     86     // Current size of the surface texture.
     87     gfx::Size size_;
     88 
     89     // Whether the surface texture has been updated.
     90     bool has_updated_;
     91 
     92     MatrixChangedCB matrix_callback_;
     93 
     94     GpuChannel* channel_;
     95     DISALLOW_COPY_AND_ASSIGN(StreamTextureAndroid);
     96   };
     97 
     98   GpuChannel* channel_;
     99 
    100   typedef IDMap<StreamTextureAndroid, IDMapOwnPointer> TextureMap;
    101   TextureMap textures_;
    102 
    103   // Map for more convenient lookup.
    104   typedef IDMap<gpu::StreamTexture, IDMapExternalPointer> TextureServiceIdMap;
    105   TextureServiceIdMap textures_from_service_id_;
    106 
    107   DISALLOW_COPY_AND_ASSIGN(StreamTextureManagerAndroid);
    108 };
    109 
    110 }  // namespace content
    111 
    112 #endif  // CONTENT_COMMON_GPU_STREAM_TEXTURE_MANAGER_ANDROID_H_
    113