| 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 "content/browser/gpu/gpu_surface_tracker.h" | 11 #include "content/browser/gpu/gpu_surface_tracker.h" | 
| 11 #include "content/browser/renderer_host/compositor_impl_android.h" | 12 #include "content/browser/renderer_host/compositor_impl_android.h" | 
| 12 #include "content/browser/renderer_host/image_transport_factory_android.h" | 13 #include "content/browser/renderer_host/image_transport_factory_android.h" | 
| 13 #include "content/common/android/surface_texture_bridge.h" | 14 #include "content/common/android/surface_texture_bridge.h" | 
| 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
     D.h" | 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
     D.h" | 
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebVideoLayer.h" | 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebVideoLayer.h" | 
| 16 #include "webkit/compositor_bindings/web_compositor_support_impl.h" | 17 #include "webkit/compositor_bindings/web_compositor_support_impl.h" | 
| 17 #include "webkit/media/webvideoframe_impl.h" | 18 #include "webkit/media/webvideoframe_impl.h" | 
| 18 | 19 | 
| 19 namespace { | 20 namespace { | 
| 20 | 21 | 
| 21 static const uint32 kGLTextureExternalOES = 0x8D65; | 22 static const uint32 kGLTextureExternalOES = 0x8D65; | 
| 22 | 23 | 
| 23 } // anonymous namespace | 24 } // anonymous namespace | 
| 24 | 25 | 
| 25 namespace content { | 26 namespace content { | 
| 26 | 27 | 
| 27 SurfaceTextureTransportClient::SurfaceTextureTransportClient() | 28 SurfaceTextureTransportClient::SurfaceTextureTransportClient() | 
| 28     : window_(NULL), | 29     : window_(NULL), | 
| 29       texture_id_(0) { | 30       texture_id_(0) { | 
| 30 } | 31 } | 
| 31 | 32 | 
| 32 SurfaceTextureTransportClient::~SurfaceTextureTransportClient() { | 33 SurfaceTextureTransportClient::~SurfaceTextureTransportClient() { | 
| 33   if (window_) | 34   if (window_) | 
| 34     ANativeWindow_release(window_); | 35     ANativeWindow_release(window_); | 
| 35 } | 36 } | 
| 36 | 37 | 
| 37 WebKit::WebLayer* SurfaceTextureTransportClient::Initialize() { | 38 scoped_refptr<cc::Layer> SurfaceTextureTransportClient::Initialize() { | 
| 38   // Use a SurfaceTexture to stream frames to the UI thread. | 39   // Use a SurfaceTexture to stream frames to the UI thread. | 
| 39   video_layer_.reset( | 40   video_layer_ = cc::VideoLayer::create(this, | 
| 40       CompositorImpl::CompositorSupport()->createVideoLayer(this)); | 41           base::Bind(webkit_media::WebVideoFrameImpl::toVideoFrame)); | 
|  | 42 | 
| 41   surface_texture_ = new SurfaceTextureBridge(0); | 43   surface_texture_ = new SurfaceTextureBridge(0); | 
| 42   surface_texture_->SetFrameAvailableCallback( | 44   surface_texture_->SetFrameAvailableCallback( | 
| 43       base::Bind( | 45       base::Bind( | 
| 44           &SurfaceTextureTransportClient::OnSurfaceTextureFrameAvailable, | 46           &SurfaceTextureTransportClient::OnSurfaceTextureFrameAvailable, | 
| 45           base::Unretained(this))); | 47           base::Unretained(this))); | 
| 46   surface_texture_->DetachFromGLContext(); | 48   surface_texture_->DetachFromGLContext(); | 
| 47   return video_layer_->layer(); | 49   return video_layer_.get(); | 
| 48 } | 50 } | 
| 49 | 51 | 
| 50 gfx::GLSurfaceHandle | 52 gfx::GLSurfaceHandle | 
| 51 SurfaceTextureTransportClient::GetCompositingSurface(int surface_id) { | 53 SurfaceTextureTransportClient::GetCompositingSurface(int surface_id) { | 
| 52   DCHECK(surface_id); | 54   DCHECK(surface_id); | 
| 53   if (!window_) | 55   if (!window_) | 
| 54     window_ = surface_texture_->CreateSurface(); | 56     window_ = surface_texture_->CreateSurface(); | 
| 55 | 57 | 
| 56   GpuSurfaceTracker::Get()->SetNativeWidget(surface_id, window_); | 58   GpuSurfaceTracker::Get()->SetNativeWidget(surface_id, window_); | 
| 57   return gfx::GLSurfaceHandle(gfx::kDummyPluginWindow, false); | 59   return gfx::GLSurfaceHandle(gfx::kDummyPluginWindow, false); | 
| 58 } | 60 } | 
| 59 | 61 | 
| 60 void SurfaceTextureTransportClient::SetSize(const gfx::Size& size) { | 62 void SurfaceTextureTransportClient::SetSize(const gfx::Size& size) { | 
| 61   surface_texture_->SetDefaultBufferSize(size.width(), size.height()); | 63   surface_texture_->SetDefaultBufferSize(size.width(), size.height()); | 
| 62   video_layer_->layer()->setBounds(size); | 64   video_layer_->setBounds(size); | 
| 63   video_frame_.reset(); | 65   video_frame_.reset(); | 
| 64 } | 66 } | 
| 65 | 67 | 
| 66 WebKit::WebVideoFrame* SurfaceTextureTransportClient::getCurrentFrame() { | 68 WebKit::WebVideoFrame* SurfaceTextureTransportClient::getCurrentFrame() { | 
| 67   if (!texture_id_) { | 69   if (!texture_id_) { | 
| 68     WebKit::WebGraphicsContext3D* context = | 70     WebKit::WebGraphicsContext3D* context = | 
| 69         ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); | 71         ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); | 
| 70     context->makeContextCurrent(); | 72     context->makeContextCurrent(); | 
| 71     texture_id_ = context->createTexture(); | 73     texture_id_ = context->createTexture(); | 
| 72   } | 74   } | 
| 73   if (!video_frame_.get()) { | 75   if (!video_frame_.get()) { | 
| 74     surface_texture_->AttachToGLContext(texture_id_); | 76     surface_texture_->AttachToGLContext(texture_id_); | 
| 75     const gfx::Size size = video_layer_->layer()->bounds(); | 77     const gfx::Size size = video_layer_->bounds(); | 
| 76     video_frame_.reset( | 78     video_frame_.reset( | 
| 77         new webkit_media::WebVideoFrameImpl( | 79         new webkit_media::WebVideoFrameImpl( | 
| 78             media::VideoFrame::WrapNativeTexture( | 80             media::VideoFrame::WrapNativeTexture( | 
| 79                 texture_id_, kGLTextureExternalOES, | 81                 texture_id_, kGLTextureExternalOES, | 
| 80                 size, | 82                 size, | 
| 81                 gfx::Rect(gfx::Point(), size), | 83                 gfx::Rect(gfx::Point(), size), | 
| 82                 size, | 84                 size, | 
| 83                 base::TimeDelta(), | 85                 base::TimeDelta(), | 
| 84                 media::VideoFrame::ReadPixelsCB(), | 86                 media::VideoFrame::ReadPixelsCB(), | 
| 85                 base::Closure()))); | 87                 base::Closure()))); | 
| 86   } | 88   } | 
| 87   surface_texture_->UpdateTexImage(); | 89   surface_texture_->UpdateTexImage(); | 
| 88 | 90 | 
| 89   return video_frame_.get(); | 91   return video_frame_.get(); | 
| 90 } | 92 } | 
| 91 | 93 | 
| 92 void SurfaceTextureTransportClient::putCurrentFrame( | 94 void SurfaceTextureTransportClient::putCurrentFrame( | 
| 93     WebKit::WebVideoFrame* frame) { | 95     WebKit::WebVideoFrame* frame) { | 
| 94 } | 96 } | 
| 95 | 97 | 
| 96 void SurfaceTextureTransportClient::OnSurfaceTextureFrameAvailable() { | 98 void SurfaceTextureTransportClient::OnSurfaceTextureFrameAvailable() { | 
| 97   video_layer_->layer()->invalidate(); | 99   video_layer_->setNeedsDisplay(); | 
| 98 } | 100 } | 
| 99 | 101 | 
| 100 } // namespace content | 102 } // namespace content | 
| OLD | NEW | 
|---|