| 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/browser/renderer_host/surface_texture_transport_client_android
.h" | 5 #include "content/browser/renderer_host/surface_texture_transport_client_android
.h" |
| 6 | 6 |
| 7 #include <android/native_window_jni.h> | 7 #include <android/native_window_jni.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "cc/video_layer.h" | 10 #include "cc/video_layer.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 texture_id_(0) { | 30 texture_id_(0) { |
| 31 } | 31 } |
| 32 | 32 |
| 33 SurfaceTextureTransportClient::~SurfaceTextureTransportClient() { | 33 SurfaceTextureTransportClient::~SurfaceTextureTransportClient() { |
| 34 if (window_) | 34 if (window_) |
| 35 ANativeWindow_release(window_); | 35 ANativeWindow_release(window_); |
| 36 } | 36 } |
| 37 | 37 |
| 38 scoped_refptr<cc::Layer> SurfaceTextureTransportClient::Initialize() { | 38 scoped_refptr<cc::Layer> SurfaceTextureTransportClient::Initialize() { |
| 39 // Use a SurfaceTexture to stream frames to the UI thread. | 39 // Use a SurfaceTexture to stream frames to the UI thread. |
| 40 video_layer_ = cc::VideoLayer::create(this, | 40 video_layer_ = cc::VideoLayer::create(this); |
| 41 base::Bind(webkit_media::WebVideoFrameImpl::toVideoFrame)); | |
| 42 | 41 |
| 43 surface_texture_ = new SurfaceTextureBridge(0); | 42 surface_texture_ = new SurfaceTextureBridge(0); |
| 44 surface_texture_->SetFrameAvailableCallback( | 43 surface_texture_->SetFrameAvailableCallback( |
| 45 base::Bind( | 44 base::Bind( |
| 46 &SurfaceTextureTransportClient::OnSurfaceTextureFrameAvailable, | 45 &SurfaceTextureTransportClient::OnSurfaceTextureFrameAvailable, |
| 47 base::Unretained(this))); | 46 base::Unretained(this))); |
| 48 surface_texture_->DetachFromGLContext(); | 47 surface_texture_->DetachFromGLContext(); |
| 49 return video_layer_.get(); | 48 return video_layer_.get(); |
| 50 } | 49 } |
| 51 | 50 |
| 52 gfx::GLSurfaceHandle | 51 gfx::GLSurfaceHandle |
| 53 SurfaceTextureTransportClient::GetCompositingSurface(int surface_id) { | 52 SurfaceTextureTransportClient::GetCompositingSurface(int surface_id) { |
| 54 DCHECK(surface_id); | 53 DCHECK(surface_id); |
| 55 if (!window_) | 54 if (!window_) |
| 56 window_ = surface_texture_->CreateSurface(); | 55 window_ = surface_texture_->CreateSurface(); |
| 57 | 56 |
| 58 GpuSurfaceTracker::Get()->SetNativeWidget(surface_id, window_); | 57 GpuSurfaceTracker::Get()->SetNativeWidget(surface_id, window_); |
| 59 return gfx::GLSurfaceHandle(gfx::kDummyPluginWindow, false); | 58 return gfx::GLSurfaceHandle(gfx::kDummyPluginWindow, false); |
| 60 } | 59 } |
| 61 | 60 |
| 62 void SurfaceTextureTransportClient::SetSize(const gfx::Size& size) { | 61 void SurfaceTextureTransportClient::SetSize(const gfx::Size& size) { |
| 63 surface_texture_->SetDefaultBufferSize(size.width(), size.height()); | 62 surface_texture_->SetDefaultBufferSize(size.width(), size.height()); |
| 64 video_layer_->setBounds(size); | 63 video_layer_->setBounds(size); |
| 65 video_frame_.reset(); | 64 video_frame_ = NULL; |
| 66 } | 65 } |
| 67 | 66 |
| 68 WebKit::WebVideoFrame* SurfaceTextureTransportClient::getCurrentFrame() { | 67 scoped_refptr<media::VideoFrame> SurfaceTextureTransportClient:: |
| 68 GetCurrentFrame() { |
| 69 if (!texture_id_) { | 69 if (!texture_id_) { |
| 70 WebKit::WebGraphicsContext3D* context = | 70 WebKit::WebGraphicsContext3D* context = |
| 71 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); | 71 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); |
| 72 context->makeContextCurrent(); | 72 context->makeContextCurrent(); |
| 73 texture_id_ = context->createTexture(); | 73 texture_id_ = context->createTexture(); |
| 74 surface_texture_->AttachToGLContext(texture_id_); | 74 surface_texture_->AttachToGLContext(texture_id_); |
| 75 } | 75 } |
| 76 if (!video_frame_.get()) { | 76 if (!video_frame_) { |
| 77 const gfx::Size size = video_layer_->bounds(); | 77 const gfx::Size size = video_layer_->bounds(); |
| 78 video_frame_.reset( | 78 video_frame_ = media::VideoFrame::WrapNativeTexture( |
| 79 new webkit_media::WebVideoFrameImpl( | 79 texture_id_, kGLTextureExternalOES, |
| 80 media::VideoFrame::WrapNativeTexture( | 80 size, |
| 81 texture_id_, kGLTextureExternalOES, | 81 gfx::Rect(gfx::Point(), size), |
| 82 size, | 82 size, |
| 83 gfx::Rect(gfx::Point(), size), | 83 base::TimeDelta(), |
| 84 size, | 84 media::VideoFrame::ReadPixelsCB(), |
| 85 base::TimeDelta(), | 85 base::Closure()); |
| 86 media::VideoFrame::ReadPixelsCB(), | |
| 87 base::Closure()))); | |
| 88 } | 86 } |
| 89 surface_texture_->UpdateTexImage(); | 87 surface_texture_->UpdateTexImage(); |
| 90 | 88 |
| 91 return video_frame_.get(); | 89 return video_frame_; |
| 92 } | 90 } |
| 93 | 91 |
| 94 void SurfaceTextureTransportClient::putCurrentFrame( | 92 void SurfaceTextureTransportClient::PutCurrentFrame( |
| 95 WebKit::WebVideoFrame* frame) { | 93 const scoped_refptr<media::VideoFrame>& frame) { |
| 96 } | 94 } |
| 97 | 95 |
| 98 void SurfaceTextureTransportClient::OnSurfaceTextureFrameAvailable() { | 96 void SurfaceTextureTransportClient::OnSurfaceTextureFrameAvailable() { |
| 99 video_layer_->setNeedsDisplay(); | 97 video_layer_->setNeedsDisplay(); |
| 100 } | 98 } |
| 101 | 99 |
| 102 } // namespace content | 100 } // namespace content |
| OLD | NEW |