OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "content/renderer/media/stream_texture_factory_impl_android.h" | 5 #include "content/renderer/media/stream_texture_factory_impl_android.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
11 #include "content/common/android/surface_texture_peer.h" | 11 #include "content/common/android/surface_texture_peer.h" |
12 #include "content/common/gpu/client/gpu_channel_host.h" | 12 #include "content/common/gpu/client/gpu_channel_host.h" |
13 #include "content/common/gpu/gpu_messages.h" | 13 #include "content/common/gpu/gpu_messages.h" |
14 #include "content/renderer/render_thread_impl.h" | 14 #include "content/renderer/render_thread_impl.h" |
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStreamTextureClien
t.h" | |
17 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 static void DeleteStreamTextureHost(content::StreamTextureHost* host) { | 20 static void DeleteStreamTextureHost(content::StreamTextureHost* host) { |
22 delete host; | 21 delete host; |
23 } | 22 } |
24 | 23 |
25 // Implementation of the StreamTextureProxy class. This class listens to all | 24 // Implementation of the StreamTextureProxy class. This class listens to all |
26 // the stream texture updates and forward them to the WebStreamTextureClient. | 25 // the stream texture updates and forward them to the |
| 26 // cc::VideoFrameProvider::Client. |
27 class StreamTextureProxyImpl : public webkit_media::StreamTextureProxy, | 27 class StreamTextureProxyImpl : public webkit_media::StreamTextureProxy, |
28 public content::StreamTextureHost::Listener { | 28 public content::StreamTextureHost::Listener { |
29 public: | 29 public: |
30 explicit StreamTextureProxyImpl(content::StreamTextureHost* host); | 30 explicit StreamTextureProxyImpl(content::StreamTextureHost* host); |
31 virtual ~StreamTextureProxyImpl(); | 31 virtual ~StreamTextureProxyImpl(); |
32 | 32 |
33 // webkit_media::StreamTextureProxy implementation: | 33 // webkit_media::StreamTextureProxy implementation: |
34 virtual bool Initialize(int stream_id, int width, int height) OVERRIDE; | 34 virtual bool Initialize(int stream_id, int width, int height) OVERRIDE; |
35 virtual bool IsInitialized() OVERRIDE { return initialized_; } | 35 virtual bool IsInitialized() OVERRIDE { return initialized_; } |
36 virtual void SetClient(WebKit::WebStreamTextureClient* client) OVERRIDE; | 36 virtual void SetClient(cc::VideoFrameProvider::Client* client) OVERRIDE; |
37 | 37 |
38 // StreamTextureHost::Listener implementation: | 38 // StreamTextureHost::Listener implementation: |
39 virtual void OnFrameAvailable() OVERRIDE; | 39 virtual void OnFrameAvailable() OVERRIDE; |
40 virtual void OnMatrixChanged(const float matrix[16]) OVERRIDE; | 40 virtual void OnMatrixChanged(const float matrix[16]) OVERRIDE; |
41 | 41 |
42 private: | 42 private: |
43 scoped_ptr<content::StreamTextureHost> host_; | 43 scoped_ptr<content::StreamTextureHost> host_; |
44 scoped_refptr<base::MessageLoopProxy> loop_; | 44 scoped_refptr<base::MessageLoopProxy> loop_; |
45 | 45 |
46 base::Lock client_lock_; | 46 base::Lock client_lock_; |
47 WebKit::WebStreamTextureClient* client_; | 47 cc::VideoFrameProvider::Client* client_; |
48 bool initialized_; | 48 bool initialized_; |
49 | 49 |
50 DISALLOW_COPY_AND_ASSIGN(StreamTextureProxyImpl); | 50 DISALLOW_COPY_AND_ASSIGN(StreamTextureProxyImpl); |
51 }; | 51 }; |
52 | 52 |
53 StreamTextureProxyImpl::StreamTextureProxyImpl( | 53 StreamTextureProxyImpl::StreamTextureProxyImpl( |
54 content::StreamTextureHost* host) | 54 content::StreamTextureHost* host) |
55 : host_(host), | 55 : host_(host), |
56 client_(NULL), | 56 client_(NULL), |
57 initialized_(false) { | 57 initialized_(false) { |
58 DCHECK(host); | 58 DCHECK(host); |
59 host->SetListener(this); | 59 host->SetListener(this); |
60 } | 60 } |
61 | 61 |
62 StreamTextureProxyImpl::~StreamTextureProxyImpl() { | 62 StreamTextureProxyImpl::~StreamTextureProxyImpl() { |
63 SetClient(NULL); | 63 SetClient(NULL); |
64 // The StreamTextureHost instance needs to be deleted on the thread | 64 // The StreamTextureHost instance needs to be deleted on the thread |
65 // it receives messages on (where it uses a WeakPtr). | 65 // it receives messages on (where it uses a WeakPtr). |
66 if (loop_.get()) { | 66 if (loop_.get()) { |
67 loop_->PostTask(FROM_HERE, base::Bind(&DeleteStreamTextureHost, | 67 loop_->PostTask(FROM_HERE, base::Bind(&DeleteStreamTextureHost, |
68 host_.release())); | 68 host_.release())); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 void StreamTextureProxyImpl::SetClient(WebKit::WebStreamTextureClient* client) { | 72 void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { |
73 base::AutoLock lock(client_lock_); | 73 base::AutoLock lock(client_lock_); |
74 client_ = client; | 74 client_ = client; |
75 } | 75 } |
76 | 76 |
77 bool StreamTextureProxyImpl::Initialize(int stream_id, int width, int height) { | 77 bool StreamTextureProxyImpl::Initialize(int stream_id, int width, int height) { |
78 loop_ = base::MessageLoopProxy::current(); | 78 loop_ = base::MessageLoopProxy::current(); |
79 initialized_ = true; | 79 initialized_ = true; |
80 return host_->Initialize(stream_id, gfx::Size(width, height)); | 80 return host_->Initialize(stream_id, gfx::Size(width, height)); |
81 } | 81 } |
82 | 82 |
83 void StreamTextureProxyImpl::OnFrameAvailable() { | 83 void StreamTextureProxyImpl::OnFrameAvailable() { |
84 base::AutoLock lock(client_lock_); | 84 base::AutoLock lock(client_lock_); |
85 if (client_) | 85 if (client_) |
86 client_->didReceiveFrame(); | 86 client_->DidReceiveFrame(); |
87 } | 87 } |
88 | 88 |
89 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { | 89 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { |
90 base::AutoLock lock(client_lock_); | 90 base::AutoLock lock(client_lock_); |
91 if (client_) | 91 if (client_) |
92 client_->didUpdateMatrix(matrix); | 92 client_->DidUpdateMatrix(matrix); |
93 } | 93 } |
94 | 94 |
95 } // anonymous namespace | 95 } // anonymous namespace |
96 | 96 |
97 namespace content { | 97 namespace content { |
98 | 98 |
99 StreamTextureFactoryImpl::StreamTextureFactoryImpl( | 99 StreamTextureFactoryImpl::StreamTextureFactoryImpl( |
100 WebKit::WebGraphicsContext3D* context, | 100 WebKit::WebGraphicsContext3D* context, |
101 GpuChannelHost* channel, | 101 GpuChannelHost* channel, |
102 int view_id) | 102 int view_id) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 void StreamTextureFactoryImpl::DestroyStreamTexture(unsigned texture_id) { | 135 void StreamTextureFactoryImpl::DestroyStreamTexture(unsigned texture_id) { |
136 if (context_->makeContextCurrent()) { | 136 if (context_->makeContextCurrent()) { |
137 context_->destroyStreamTextureCHROMIUM(texture_id); | 137 context_->destroyStreamTextureCHROMIUM(texture_id); |
138 context_->deleteTexture(texture_id); | 138 context_->deleteTexture(texture_id); |
139 context_->flush(); | 139 context_->flush(); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 } // namespace content | 143 } // namespace content |
OLD | NEW |