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 int width, |
| 36 int height) { |
| 37 loop_ = base::MessageLoopProxy::current(); |
| 38 host_->Initialize(stream_id, gfx::Size(width, height)); |
| 39 } |
| 40 |
| 41 void StreamTextureProxy::OnFrameAvailable() { |
| 42 base::AutoLock lock(client_lock_); |
| 43 if (client_) |
| 44 client_->DidReceiveFrame(); |
| 45 } |
| 46 |
| 47 void StreamTextureProxy::OnMatrixChanged(const float matrix[16]) { |
| 48 base::AutoLock lock(client_lock_); |
| 49 if (client_) |
| 50 client_->DidUpdateMatrix(matrix); |
| 51 } |
| 52 |
| 53 StreamTextureFactory::StreamTextureFactory( |
| 54 WebKit::WebGraphicsContext3D* context, |
| 55 GpuChannelHost* channel, |
| 56 int view_id) |
| 57 : context_(context), channel_(channel), view_id_(view_id) { |
| 58 DCHECK(context_); |
| 59 DCHECK(channel); |
| 60 } |
| 61 |
| 62 StreamTextureFactory::~StreamTextureFactory() {} |
| 63 |
| 64 StreamTextureProxy* StreamTextureFactory::CreateProxy() { |
| 65 DCHECK(channel_.get()); |
| 66 StreamTextureHost* host = new StreamTextureHost(channel_.get()); |
| 67 return new StreamTextureProxy(host); |
| 68 } |
| 69 |
| 70 void StreamTextureFactory::EstablishPeer(int stream_id, int player_id) { |
| 71 DCHECK(channel_.get()); |
| 72 channel_->Send( |
| 73 new GpuChannelMsg_EstablishStreamTexture(stream_id, view_id_, player_id)); |
| 74 } |
| 75 |
| 76 unsigned StreamTextureFactory::CreateStreamTexture(unsigned* texture_id) { |
| 77 unsigned stream_id = 0; |
| 78 if (context_->makeContextCurrent()) { |
| 79 *texture_id = context_->createTexture(); |
| 80 stream_id = context_->createStreamTextureCHROMIUM(*texture_id); |
| 81 context_->flush(); |
| 82 } |
| 83 return stream_id; |
| 84 } |
| 85 |
| 86 void StreamTextureFactory::DestroyStreamTexture(unsigned texture_id) { |
| 87 if (context_->makeContextCurrent()) { |
| 88 context_->destroyStreamTextureCHROMIUM(texture_id); |
| 89 context_->deleteTexture(texture_id); |
| 90 context_->flush(); |
| 91 } |
| 92 } |
| 93 |
| 94 } // namespace content |
OLD | NEW |