Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: content/renderer/media/stream_texture_factory_impl_android.cc

Issue 10695181: [Android] Upstream all the IPC communications/handlings for stream texture (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 #include "content/renderer/media/stream_texture_factory_impl_android.h"
6
7 #include "base/bind.h"
8 #include "base/compiler_specific.h"
9 #include "base/message_loop_proxy.h"
10 #include "base/synchronization/lock.h"
11 #include "content/common/android/surface_texture_peer.h"
12 #include "content/common/gpu/client/gpu_channel_host.h"
13 #include "content/common/gpu/gpu_messages.h"
14 #include "content/renderer/render_thread_impl.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStreamTextureClien t.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsC ontext3D.h"
17 #include "ui/gfx/size.h"
18
19 namespace {
20
21 static void DeleteStreamTextureHost(content::StreamTextureHost* host) {
22 delete host;
23 }
24
25 // Implementation of the StreamTextureProxy class. This class listens to all
26 // the stream texture updates and forward them to the WebStreamTextureClient.
27 class StreamTextureProxyImpl : public webkit_media::StreamTextureProxy,
28 public content::StreamTextureHost::Listener {
29 public:
30 StreamTextureProxyImpl(content::StreamTextureHost* host);
apatrick_chromium 2012/07/12 23:51:31 explicit
qinmin 2012/07/13 00:41:33 Done.
31 virtual ~StreamTextureProxyImpl() OVERRIDE;
apatrick_chromium 2012/07/12 23:51:31 this isn't an override.
qinmin 2012/07/13 00:41:33 Done.
32
33 // webkit_media::StreamTextureProxy implementation:
34 virtual bool Initialize(int stream_id, int width, int height) OVERRIDE;
35 virtual bool IsInitialized() OVERRIDE { return initialized_; }
36 virtual void SetClient(WebKit::WebStreamTextureClient* client) OVERRIDE;
37
38 // StreamTextureHost::Listener implementation:
39 virtual void OnFrameAvailable() OVERRIDE;
40 virtual void OnMatrixChanged(const float matrix[16]) OVERRIDE;
41
42 private:
43 scoped_ptr<content::StreamTextureHost> host_;
44 scoped_refptr<base::MessageLoopProxy> loop_;
45
46 base::Lock client_lock_;
47 WebKit::WebStreamTextureClient* client_;
48 bool initialized_;
49
50 DISALLOW_COPY_AND_ASSIGN(StreamTextureProxyImpl);
51 };
52
53 StreamTextureProxyImpl::StreamTextureProxyImpl(
54 content::StreamTextureHost* host)
55 : host_(host),
56 client_(NULL),
57 initialized_(false) {
58 DCHECK(host);
59 host->SetListener(this);
60 }
61
62 StreamTextureProxyImpl::~StreamTextureProxyImpl() {
63 SetClient(NULL);
64 // The StreamTextureHost instance needs to be deleted on the thread
65 // it receives messages on (where it uses a WeakPtr).
66 if (loop_.get())
67 loop_->PostTask(FROM_HERE, base::Bind(&DeleteStreamTextureHost,
68 host_.release()));
69 }
70
71 void StreamTextureProxyImpl::SetClient(WebKit::WebStreamTextureClient* client) {
72 base::AutoLock lock(client_lock_);
73 client_ = client;
74 }
75
76 bool StreamTextureProxyImpl::Initialize(int stream_id, int width, int height) {
77 loop_ = base::MessageLoopProxy::current();
78 initialized_ = true;
79 return host_->Initialize(stream_id, gfx::Size(width, height));
80 }
81
82 void StreamTextureProxyImpl::OnFrameAvailable() {
83 base::AutoLock lock(client_lock_);
84 if (client_)
85 client_->didReceiveFrame();
86 }
87
88 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) {
89 base::AutoLock lock(client_lock_);
90 if (client_)
91 client_->didUpdateMatrix(matrix);
92 }
93
94 } // anonymous namespace
95
96 namespace content {
97
98 StreamTextureFactoryImpl::StreamTextureFactoryImpl(
99 WebKit::WebGraphicsContext3D* context,
100 GpuChannelHost* channel,
101 int view_id)
102 : context_(context),
103 channel_(channel),
104 view_id_(view_id) {
105 DCHECK(context_);
106 DCHECK(channel);
107 }
108
109 StreamTextureFactoryImpl::~StreamTextureFactoryImpl() {
110 }
111
112 webkit_media::StreamTextureProxy* StreamTextureFactoryImpl::CreateProxy() {
113 DCHECK(channel_.get());
114 StreamTextureHost* host = new StreamTextureHost(channel_.get());
115 return new StreamTextureProxyImpl(host);
116 }
117
118 void StreamTextureFactoryImpl::EstablishPeer(int stream_id, int player_id) {
119 DCHECK(channel_.get());
120 channel_->Send(new GpuChannelMsg_EstablishStreamTexture(
121 stream_id, content::SurfaceTexturePeer::SET_VIDEO_SURFACE_TEXTURE,
122 view_id_, player_id));
123 }
124
125 unsigned StreamTextureFactoryImpl::CreateStreamTexture(unsigned* texture_id) {
126 unsigned stream_id = 0;
127 if (context_->makeContextCurrent()) {
128 *texture_id = context_->createTexture();
129 // TODO(qinmin): upstream the implementation of
130 // WebGraphicsContext::createStreamTextureCHROMIUM().
131 // stream_id = context_->createStreamTextureCHROMIUM(*texture_id);
132 context_->flush();
133 }
134 return stream_id;
135 }
136
137 void StreamTextureFactoryImpl::DestroyStreamTexture(unsigned texture_id) {
138 if (context_->makeContextCurrent()) {
139 // TODO(qinmin): upstream the implementation of
140 // WebGraphicsContext::destroyStreamTextureCHROMIUM().
141 // context_->destroyStreamTextureCHROMIUM(texture_id);
142 context_->deleteTexture(texture_id);
143 context_->flush();
144 }
145 }
146
147 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698