Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / common / gpu / stream_texture_android.h
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 int32 Create(GpuCommandBufferStub* owner_stub,
26                       uint32 client_texture_id);
27
28  private:
29   StreamTexture(GpuCommandBufferStub* owner_stub,
30                 int32 route_id,
31                 uint32 texture_id);
32   virtual ~StreamTexture();
33
34   // gfx::GLImage implementation:
35   virtual void Destroy() OVERRIDE;
36   virtual gfx::Size GetSize() OVERRIDE;
37   virtual void WillUseTexImage() OVERRIDE;
38   virtual void DidUseTexImage() OVERRIDE {}
39
40   // GpuCommandBufferStub::DestructionObserver implementation.
41   virtual void OnWillDestroyStub() OVERRIDE;
42
43   // Called when a new frame is available for the SurfaceTexture.
44   void OnFrameAvailable();
45
46   // IPC::Listener implementation:
47   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
48
49   // IPC message handlers:
50   void OnStartListening();
51   void OnEstablishPeer(int32 primary_id, int32 secondary_id);
52   void OnSetSize(const gfx::Size& size) { size_ = size; }
53
54   scoped_refptr<gfx::SurfaceTexture> surface_texture_;
55
56   // Current transform matrix of the surface texture.
57   float current_matrix_[16];
58
59   // Current size of the surface texture.
60   gfx::Size size_;
61
62   // Whether we ever bound a valid frame.
63   bool has_valid_frame_;
64
65   // Whether a new frame is available that we should update to.
66   bool has_pending_frame_;
67
68   GpuCommandBufferStub* owner_stub_;
69   int32 route_id_;
70   bool has_listener_;
71
72   base::WeakPtrFactory<StreamTexture> weak_factory_;
73   DISALLOW_COPY_AND_ASSIGN(StreamTexture);
74 };
75
76 }  // namespace content
77
78 #endif  // CONTENT_COMMON_GPU_STREAM_TEXTURE_ANDROID_H_