OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/browser/media/android/browser_surface_view_manager.h" |
| 6 |
| 7 #include "content/browser/android/child_process_launcher_android.h" |
| 8 #include "content/browser/android/content_view_core_impl.h" |
| 9 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" |
| 11 #include "content/common/media/surface_view_manager_messages_android.h" |
| 12 #include "content/public/browser/render_frame_host.h" |
| 13 #include "media/base/surface_manager.h" |
| 14 #include "ui/gfx/geometry/size.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 BrowserSurfaceViewManager::BrowserSurfaceViewManager( |
| 19 RenderFrameHost* render_frame_host) |
| 20 : render_frame_host_(render_frame_host), |
| 21 surface_id_(media::SurfaceManager::kNoSurfaceID) {} |
| 22 |
| 23 BrowserSurfaceViewManager::~BrowserSurfaceViewManager() {} |
| 24 |
| 25 void BrowserSurfaceViewManager::SetVideoSurface( |
| 26 gfx::ScopedJavaSurface surface) { |
| 27 if (surface.IsEmpty()) { |
| 28 DCHECK_NE(surface_id_, media::SurfaceManager::kNoSurfaceID); |
| 29 GpuSurfaceTracker::Get()->RemoveSurface(surface_id_); |
| 30 UnregisterViewSurface(surface_id_); |
| 31 surface_id_ = media::SurfaceManager::kNoSurfaceID; |
| 32 } else { |
| 33 // We mainly use the surface tracker to allocate a surface id for us. The |
| 34 // lookup will go through the Android specific path and get the java |
| 35 // surface directly, so there's no need to add a valid native widget here. |
| 36 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForNativeWidget( |
| 37 gfx::kNullAcceleratedWidget); |
| 38 RegisterViewSurface(surface_id_, surface.j_surface().obj()); |
| 39 SendSurfaceID(surface_id_); |
| 40 } |
| 41 } |
| 42 |
| 43 void BrowserSurfaceViewManager::DidExitFullscreen(bool release_media_player) { |
| 44 DVLOG(3) << __FUNCTION__; |
| 45 content_video_view_.reset(); |
| 46 } |
| 47 |
| 48 void BrowserSurfaceViewManager::OnCreateFullscreenSurface( |
| 49 const gfx::Size& video_natural_size) { |
| 50 // It's valid to get this call if we already own the fullscreen view. We just |
| 51 // return the existing surface id. |
| 52 if (content_video_view_) { |
| 53 // Send the surface now if we have it. Otherwise it will be returned by |
| 54 // |SetVideoSurface|. |
| 55 if (surface_id_ != media::SurfaceManager::kNoSurfaceID) { |
| 56 SendSurfaceID(surface_id_); |
| 57 OnNaturalSizeChanged(video_natural_size); |
| 58 return; |
| 59 } |
| 60 } |
| 61 |
| 62 // If we don't own the fullscreen view, but one exists, it means another |
| 63 // WebContents has it. Ignore this request and return a null surface id. |
| 64 if (ContentVideoView::GetInstance()) { |
| 65 SendSurfaceID(media::SurfaceManager::kNoSurfaceID); |
| 66 return; |
| 67 } |
| 68 |
| 69 ContentViewCore* cvc = ContentViewCore::FromWebContents( |
| 70 WebContents::FromRenderFrameHost(render_frame_host_)); |
| 71 content_video_view_.reset(new ContentVideoView(this, cvc)); |
| 72 OnNaturalSizeChanged(video_natural_size); |
| 73 } |
| 74 |
| 75 void BrowserSurfaceViewManager::OnNaturalSizeChanged(const gfx::Size& size) { |
| 76 if (content_video_view_) |
| 77 content_video_view_->OnVideoSizeChanged(size.width(), size.height()); |
| 78 } |
| 79 |
| 80 bool BrowserSurfaceViewManager::SendSurfaceID(int surface_id) { |
| 81 return render_frame_host_->Send( |
| 82 new SurfaceViewManagerMsg_FullscreenSurfaceCreated( |
| 83 render_frame_host_->GetRoutingID(), surface_id)); |
| 84 } |
| 85 |
| 86 } // namespace content |
OLD | NEW |