| 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" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStreamTextureClien
t.h" |
| 17 #include "ui/gfx/size.h" | 17 #include "ui/gfx/size.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 static void DeleteStreamTextureHost(content::StreamTextureHost* host) { | 21 static void DeleteStreamTextureHost(content::StreamTextureHost* host) { |
| 22 delete host; | 22 delete host; |
| 23 } | 23 } |
| 24 | 24 |
| 25 // Implementation of the StreamTextureProxy class. This class listens to all | 25 // Implementation of the StreamTextureProxy class. This class listens to all |
| 26 // the stream texture updates and forward them to the WebStreamTextureClient. | 26 // the stream texture updates and forward them to the |
| 27 // cc::VideoFrameProvider::Client. |
| 27 class StreamTextureProxyImpl : public webkit_media::StreamTextureProxy, | 28 class StreamTextureProxyImpl : public webkit_media::StreamTextureProxy, |
| 28 public content::StreamTextureHost::Listener { | 29 public content::StreamTextureHost::Listener { |
| 29 public: | 30 public: |
| 30 explicit StreamTextureProxyImpl(content::StreamTextureHost* host); | 31 explicit StreamTextureProxyImpl(content::StreamTextureHost* host); |
| 31 virtual ~StreamTextureProxyImpl(); | 32 virtual ~StreamTextureProxyImpl(); |
| 32 | 33 |
| 33 // webkit_media::StreamTextureProxy implementation: | 34 // webkit_media::StreamTextureProxy implementation: |
| 34 virtual bool Initialize(int stream_id, int width, int height) OVERRIDE; | 35 virtual bool Initialize(int stream_id, int width, int height) OVERRIDE; |
| 35 virtual bool IsInitialized() OVERRIDE { return initialized_; } | 36 virtual bool IsInitialized() OVERRIDE { return initialized_; } |
| 37 #ifndef REMOVE_WEBVIDEOFRAME |
| 36 virtual void SetClient(WebKit::WebStreamTextureClient* client) OVERRIDE; | 38 virtual void SetClient(WebKit::WebStreamTextureClient* client) OVERRIDE; |
| 39 #else |
| 40 virtual void SetClient(cc::VideoFrameProvider::Client* client) OVERRIDE; |
| 41 #endif |
| 37 | 42 |
| 38 // StreamTextureHost::Listener implementation: | 43 // StreamTextureHost::Listener implementation: |
| 39 virtual void OnFrameAvailable() OVERRIDE; | 44 virtual void OnFrameAvailable() OVERRIDE; |
| 40 virtual void OnMatrixChanged(const float matrix[16]) OVERRIDE; | 45 virtual void OnMatrixChanged(const float matrix[16]) OVERRIDE; |
| 41 | 46 |
| 42 private: | 47 private: |
| 43 scoped_ptr<content::StreamTextureHost> host_; | 48 scoped_ptr<content::StreamTextureHost> host_; |
| 44 scoped_refptr<base::MessageLoopProxy> loop_; | 49 scoped_refptr<base::MessageLoopProxy> loop_; |
| 45 | 50 |
| 46 base::Lock client_lock_; | 51 base::Lock client_lock_; |
| 52 #ifndef REMOVE_WEBVIDEOFRAME |
| 47 WebKit::WebStreamTextureClient* client_; | 53 WebKit::WebStreamTextureClient* client_; |
| 54 #else |
| 55 cc::VideoFrameProvider::Client* client_; |
| 56 #endif |
| 48 bool initialized_; | 57 bool initialized_; |
| 49 | 58 |
| 50 DISALLOW_COPY_AND_ASSIGN(StreamTextureProxyImpl); | 59 DISALLOW_COPY_AND_ASSIGN(StreamTextureProxyImpl); |
| 51 }; | 60 }; |
| 52 | 61 |
| 53 StreamTextureProxyImpl::StreamTextureProxyImpl( | 62 StreamTextureProxyImpl::StreamTextureProxyImpl( |
| 54 content::StreamTextureHost* host) | 63 content::StreamTextureHost* host) |
| 55 : host_(host), | 64 : host_(host), |
| 56 client_(NULL), | 65 client_(NULL), |
| 57 initialized_(false) { | 66 initialized_(false) { |
| 58 DCHECK(host); | 67 DCHECK(host); |
| 59 host->SetListener(this); | 68 host->SetListener(this); |
| 60 } | 69 } |
| 61 | 70 |
| 62 StreamTextureProxyImpl::~StreamTextureProxyImpl() { | 71 StreamTextureProxyImpl::~StreamTextureProxyImpl() { |
| 63 SetClient(NULL); | 72 SetClient(NULL); |
| 64 // The StreamTextureHost instance needs to be deleted on the thread | 73 // The StreamTextureHost instance needs to be deleted on the thread |
| 65 // it receives messages on (where it uses a WeakPtr). | 74 // it receives messages on (where it uses a WeakPtr). |
| 66 if (loop_.get()) { | 75 if (loop_.get()) { |
| 67 loop_->PostTask(FROM_HERE, base::Bind(&DeleteStreamTextureHost, | 76 loop_->PostTask(FROM_HERE, base::Bind(&DeleteStreamTextureHost, |
| 68 host_.release())); | 77 host_.release())); |
| 69 } | 78 } |
| 70 } | 79 } |
| 71 | 80 |
| 81 #ifndef REMOVE_WEBVIDEOFRAME |
| 72 void StreamTextureProxyImpl::SetClient(WebKit::WebStreamTextureClient* client) { | 82 void StreamTextureProxyImpl::SetClient(WebKit::WebStreamTextureClient* client) { |
| 83 #else |
| 84 void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { |
| 85 #endif |
| 73 base::AutoLock lock(client_lock_); | 86 base::AutoLock lock(client_lock_); |
| 74 client_ = client; | 87 client_ = client; |
| 75 } | 88 } |
| 76 | 89 |
| 77 bool StreamTextureProxyImpl::Initialize(int stream_id, int width, int height) { | 90 bool StreamTextureProxyImpl::Initialize(int stream_id, int width, int height) { |
| 78 loop_ = base::MessageLoopProxy::current(); | 91 loop_ = base::MessageLoopProxy::current(); |
| 79 initialized_ = true; | 92 initialized_ = true; |
| 80 return host_->Initialize(stream_id, gfx::Size(width, height)); | 93 return host_->Initialize(stream_id, gfx::Size(width, height)); |
| 81 } | 94 } |
| 82 | 95 |
| 83 void StreamTextureProxyImpl::OnFrameAvailable() { | 96 void StreamTextureProxyImpl::OnFrameAvailable() { |
| 84 base::AutoLock lock(client_lock_); | 97 base::AutoLock lock(client_lock_); |
| 98 #ifndef REMOVE_WEBVIDEOFRAME |
| 85 if (client_) | 99 if (client_) |
| 86 client_->didReceiveFrame(); | 100 client_->didReceiveFrame(); |
| 101 #else |
| 102 if (client_) |
| 103 client_->DidReceiveFrame(); |
| 104 #endif |
| 87 } | 105 } |
| 88 | 106 |
| 89 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { | 107 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { |
| 90 base::AutoLock lock(client_lock_); | 108 base::AutoLock lock(client_lock_); |
| 109 #ifndef REMOVE_WEBVIDEOFRAME |
| 91 if (client_) | 110 if (client_) |
| 92 client_->didUpdateMatrix(matrix); | 111 client_->didUpdateMatrix(matrix); |
| 112 #else |
| 113 if (client_) |
| 114 client_->DidUpdateMatrix(matrix); |
| 115 #endif |
| 93 } | 116 } |
| 94 | 117 |
| 95 } // anonymous namespace | 118 } // anonymous namespace |
| 96 | 119 |
| 97 namespace content { | 120 namespace content { |
| 98 | 121 |
| 99 StreamTextureFactoryImpl::StreamTextureFactoryImpl( | 122 StreamTextureFactoryImpl::StreamTextureFactoryImpl( |
| 100 WebKit::WebGraphicsContext3D* context, | 123 WebKit::WebGraphicsContext3D* context, |
| 101 GpuChannelHost* channel, | 124 GpuChannelHost* channel, |
| 102 int view_id) | 125 int view_id) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 157 |
| 135 void StreamTextureFactoryImpl::DestroyStreamTexture(unsigned texture_id) { | 158 void StreamTextureFactoryImpl::DestroyStreamTexture(unsigned texture_id) { |
| 136 if (context_->makeContextCurrent()) { | 159 if (context_->makeContextCurrent()) { |
| 137 context_->destroyStreamTextureCHROMIUM(texture_id); | 160 context_->destroyStreamTextureCHROMIUM(texture_id); |
| 138 context_->deleteTexture(texture_id); | 161 context_->deleteTexture(texture_id); |
| 139 context_->flush(); | 162 context_->flush(); |
| 140 } | 163 } |
| 141 } | 164 } |
| 142 | 165 |
| 143 } // namespace content | 166 } // namespace content |
| OLD | NEW |