Chromium Code Reviews| Index: content/browser/media/android/browser_surface_view_manager.cc |
| diff --git a/content/browser/media/android/browser_surface_view_manager.cc b/content/browser/media/android/browser_surface_view_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3c299214bc8fc46601bc089f12a6aab77e143d34 |
| --- /dev/null |
| +++ b/content/browser/media/android/browser_surface_view_manager.cc |
| @@ -0,0 +1,81 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/media/android/browser_surface_view_manager.h" |
| + |
| +#include "content/browser/android/child_process_launcher_android.h" |
| +#include "content/browser/android/content_view_core_impl.h" |
| +#include "content/browser/gpu/gpu_surface_tracker.h" |
| +#include "content/browser/web_contents/web_contents_impl.h" |
| +#include "content/common/media/surface_view_manager_messages_android.h" |
| +#include "content/public/browser/render_frame_host.h" |
| +#include "media/base/surface_manager.h" |
| +#include "ui/gfx/geometry/size.h" |
| + |
| +namespace content { |
| + |
| +BrowserSurfaceViewManager::BrowserSurfaceViewManager( |
| + RenderFrameHost* render_frame_host) |
| + : render_frame_host_(render_frame_host), |
| + surface_id_(media::SurfaceManager::kNoSurfaceID) {} |
| + |
| +void BrowserSurfaceViewManager::SetVideoSurface( |
| + gfx::ScopedJavaSurface surface) { |
| + if (surface.IsEmpty()) { |
| + GpuSurfaceTracker::Get()->RemoveSurface(surface_id_); |
| + UnregisterViewSurface(surface_id_); |
| + surface_id_ = media::SurfaceManager::kNoSurfaceID; |
| + } else { |
| + // We mainly use the surface tracker to allocate a surface id for us. The |
| + // lookup will go through the Android specific path and get the java |
| + // surface directly, so there's no need to add a valid native widget here. |
| + surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForNativeWidget( |
| + gfx::kNullAcceleratedWidget); |
| + RegisterViewSurface(surface_id_, surface.j_surface().obj()); |
| + SendSurfaceID(surface_id_); |
| + } |
| +} |
| + |
| +void BrowserSurfaceViewManager::DidExitFullscreen(bool release_media_player) { |
| + DVLOG(3) << __FUNCTION__; |
| + content_video_view_.reset(); |
| +} |
| + |
| +void BrowserSurfaceViewManager::OnCreateFullscreenSurface( |
| + gfx::Size video_size) { |
| + // It's valid to get this call if we already own the fullscreen view. We just |
| + // return the existing surface id. |
| + if (content_video_view_) { |
| + // Send the surface now if we have it. Otherwise it will be returned by |
| + // |SetVideoSurface|. |
| + if (surface_id_ != media::SurfaceManager::kNoSurfaceID) |
| + SendSurfaceID(surface_id_); |
|
liberato (no reviews please)
2016/02/05 22:09:46
do we need to OnFullscreenVideoSizeChanged() too?
watk
2016/02/11 23:03:25
Oops, Done
|
| + return; |
| + } |
| + |
| + // If we don't own the fullscreen view, but one exists, it means another |
| + // WebContents has it. Ignore this request and return a null surface id. |
| + if (ContentVideoView::GetInstance()) { |
| + SendSurfaceID(media::SurfaceManager::kNoSurfaceID); |
| + return; |
| + } |
| + |
| + ContentViewCore* cvc = ContentViewCore::FromWebContents( |
| + WebContents::FromRenderFrameHost(render_frame_host_)); |
| + content_video_view_.reset(new ContentVideoView(this, cvc)); |
| + OnFullscreenVideoSizeChanged(video_size); |
| +} |
| + |
| +void BrowserSurfaceViewManager::OnFullscreenVideoSizeChanged(gfx::Size size) { |
|
liberato (no reviews please)
2016/02/05 22:09:46
OnNaturalSizeChanged (here and elsewhere)? i see
watk
2016/02/11 23:03:25
Done.
|
| + if (content_video_view_) |
| + content_video_view_->OnVideoSizeChanged(size.width(), size.height()); |
| +} |
| + |
| +bool BrowserSurfaceViewManager::SendSurfaceID(int surface_id) { |
| + return render_frame_host_->Send( |
| + new RendererSurfaceViewManagerMsg_FullscreenSurfaceCreated( |
| + render_frame_host_->GetRoutingID(), surface_id)); |
| +} |
| + |
| +} // namespace content |