OLD | NEW |
| (Empty) |
1 // Copyright 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 #include "content/renderer/media/android/stream_texture_factory_android.h" | |
6 | |
7 #include "content/common/gpu/client/gpu_channel_host.h" | |
8 #include "content/common/gpu/gpu_messages.h" | |
9 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | |
10 #include "ui/gfx/size.h" | |
11 | |
12 namespace content { | |
13 | |
14 StreamTextureProxy::StreamTextureProxy(StreamTextureHost* host) | |
15 : host_(host), client_(NULL) { | |
16 host->SetListener(this); | |
17 } | |
18 | |
19 StreamTextureProxy::~StreamTextureProxy() {} | |
20 | |
21 void StreamTextureProxy::Release() { | |
22 SetClient(NULL); | |
23 if (loop_.get() && loop_.get() != base::MessageLoopProxy::current()) | |
24 loop_->DeleteSoon(FROM_HERE, this); | |
25 else | |
26 delete this; | |
27 } | |
28 | |
29 void StreamTextureProxy::SetClient(cc::VideoFrameProvider::Client* client) { | |
30 base::AutoLock lock(client_lock_); | |
31 client_ = client; | |
32 } | |
33 | |
34 void StreamTextureProxy::BindToCurrentThread(int stream_id) { | |
35 loop_ = base::MessageLoopProxy::current(); | |
36 host_->Initialize(stream_id); | |
37 } | |
38 | |
39 void StreamTextureProxy::OnFrameAvailable() { | |
40 base::AutoLock lock(client_lock_); | |
41 if (client_) | |
42 client_->DidReceiveFrame(); | |
43 } | |
44 | |
45 void StreamTextureProxy::OnMatrixChanged(const float matrix[16]) { | |
46 base::AutoLock lock(client_lock_); | |
47 if (client_) | |
48 client_->DidUpdateMatrix(matrix); | |
49 } | |
50 | |
51 StreamTextureFactory::StreamTextureFactory( | |
52 WebKit::WebGraphicsContext3D* context, | |
53 GpuChannelHost* channel, | |
54 int view_id) | |
55 : context_(context), channel_(channel), view_id_(view_id) { | |
56 DCHECK(context_); | |
57 DCHECK(channel); | |
58 } | |
59 | |
60 StreamTextureFactory::~StreamTextureFactory() {} | |
61 | |
62 StreamTextureProxy* StreamTextureFactory::CreateProxy() { | |
63 DCHECK(channel_.get()); | |
64 StreamTextureHost* host = new StreamTextureHost(channel_.get()); | |
65 return new StreamTextureProxy(host); | |
66 } | |
67 | |
68 void StreamTextureFactory::EstablishPeer(int32 stream_id, int player_id) { | |
69 DCHECK(channel_.get()); | |
70 channel_->Send( | |
71 new GpuChannelMsg_EstablishStreamTexture(stream_id, view_id_, player_id)); | |
72 } | |
73 | |
74 unsigned StreamTextureFactory::CreateStreamTexture( | |
75 unsigned texture_target, | |
76 unsigned* texture_id, | |
77 gpu::Mailbox* texture_mailbox, | |
78 unsigned* texture_mailbox_sync_point) { | |
79 unsigned stream_id = 0; | |
80 if (context_->makeContextCurrent()) { | |
81 *texture_id = context_->createTexture(); | |
82 stream_id = context_->createStreamTextureCHROMIUM(*texture_id); | |
83 | |
84 context_->genMailboxCHROMIUM(texture_mailbox->name); | |
85 context_->bindTexture(texture_target, *texture_id); | |
86 context_->produceTextureCHROMIUM(texture_target, texture_mailbox->name); | |
87 | |
88 context_->flush(); | |
89 *texture_mailbox_sync_point = context_->insertSyncPoint(); | |
90 } | |
91 return stream_id; | |
92 } | |
93 | |
94 void StreamTextureFactory::DestroyStreamTexture(unsigned texture_id) { | |
95 if (context_->makeContextCurrent()) { | |
96 // TODO(sievers): Make the destroyStreamTexture implicit when the last | |
97 // texture referencing it is lost. | |
98 context_->destroyStreamTextureCHROMIUM(texture_id); | |
99 context_->deleteTexture(texture_id); | |
100 context_->flush(); | |
101 } | |
102 } | |
103 | |
104 void StreamTextureFactory::SetStreamTextureSize( | |
105 int32 stream_id, const gfx::Size& size) { | |
106 channel_->Send(new GpuChannelMsg_SetStreamTextureSize(stream_id, size)); | |
107 } | |
108 | |
109 } // namespace content | |
OLD | NEW |