• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COMMON_GPU_STREAM_TEXTURE_ANDROID_H_
6 #define CONTENT_COMMON_GPU_STREAM_TEXTURE_ANDROID_H_
7 
8 #include "base/basictypes.h"
9 #include "base/memory/weak_ptr.h"
10 #include "content/common/gpu/gpu_command_buffer_stub.h"
11 #include "ipc/ipc_listener.h"
12 #include "ui/gl/android/surface_texture.h"
13 #include "ui/gl/gl_image.h"
14 
15 namespace gfx {
16 class Size;
17 }
18 
19 namespace content {
20 
21 class StreamTexture : public gfx::GLImage,
22                       public IPC::Listener,
23                       public GpuCommandBufferStub::DestructionObserver {
24  public:
25   static bool Create(GpuCommandBufferStub* owner_stub,
26                      uint32 client_texture_id,
27                      int stream_id);
28 
29  private:
30   StreamTexture(GpuCommandBufferStub* owner_stub,
31                 int32 route_id,
32                 uint32 texture_id);
33   virtual ~StreamTexture();
34 
35   // gfx::GLImage implementation:
36   virtual void Destroy() OVERRIDE;
37   virtual gfx::Size GetSize() OVERRIDE;
38   virtual bool BindTexImage(unsigned target) OVERRIDE;
39   virtual void ReleaseTexImage(unsigned target) OVERRIDE;
40   virtual void WillUseTexImage() OVERRIDE;
DidUseTexImage()41   virtual void DidUseTexImage() OVERRIDE {}
WillModifyTexImage()42   virtual void WillModifyTexImage() OVERRIDE {}
DidModifyTexImage()43   virtual void DidModifyTexImage() OVERRIDE {}
44 
45   // GpuCommandBufferStub::DestructionObserver implementation.
46   virtual void OnWillDestroyStub() OVERRIDE;
47 
48   // Called when a new frame is available for the SurfaceTexture.
49   void OnFrameAvailable();
50 
51   // IPC::Listener implementation:
52   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
53 
54   // IPC message handlers:
55   void OnStartListening();
56   void OnEstablishPeer(int32 primary_id, int32 secondary_id);
OnSetSize(const gfx::Size & size)57   void OnSetSize(const gfx::Size& size) { size_ = size; }
58 
59   scoped_refptr<gfx::SurfaceTexture> surface_texture_;
60 
61   // Current transform matrix of the surface texture.
62   float current_matrix_[16];
63 
64   // Current size of the surface texture.
65   gfx::Size size_;
66 
67   // Whether we ever bound a valid frame.
68   bool has_valid_frame_;
69 
70   // Whether a new frame is available that we should update to.
71   bool has_pending_frame_;
72 
73   GpuCommandBufferStub* owner_stub_;
74   int32 route_id_;
75   bool has_listener_;
76 
77   base::WeakPtrFactory<StreamTexture> weak_factory_;
78   DISALLOW_COPY_AND_ASSIGN(StreamTexture);
79 };
80 
81 }  // namespace content
82 
83 #endif  // CONTENT_COMMON_GPU_STREAM_TEXTURE_ANDROID_H_
84