Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: content/browser/media/android/browser_surface_view_manager.cc

Issue 2481583003: Send the video surface destruction message on all Android versions (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/media/android/browser_surface_view_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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/media/android/browser_surface_view_manager.h" 5 #include "content/browser/media/android/browser_surface_view_manager.h"
6 6
7 #include "base/android/build_info.h" 7 #include "base/android/build_info.h"
8 #include "base/trace_event/trace_event.h" 8 #include "base/trace_event/trace_event.h"
9 #include "content/browser/android/content_view_core_impl.h" 9 #include "content/browser/android/content_view_core_impl.h"
10 #include "content/browser/gpu/gpu_process_host.h" 10 #include "content/browser/gpu/gpu_process_host.h"
(...skipping 24 matching lines...) Expand all
35 surface_id_(media::SurfaceManager::kNoSurfaceID) {} 35 surface_id_(media::SurfaceManager::kNoSurfaceID) {}
36 36
37 BrowserSurfaceViewManager::~BrowserSurfaceViewManager() {} 37 BrowserSurfaceViewManager::~BrowserSurfaceViewManager() {}
38 38
39 void BrowserSurfaceViewManager::SetVideoSurface(gl::ScopedJavaSurface surface) { 39 void BrowserSurfaceViewManager::SetVideoSurface(gl::ScopedJavaSurface surface) {
40 TRACE_EVENT0("media", "BrowserSurfaceViewManager::SetVideoSurface"); 40 TRACE_EVENT0("media", "BrowserSurfaceViewManager::SetVideoSurface");
41 if (surface.IsEmpty()) { 41 if (surface.IsEmpty()) {
42 DCHECK_NE(surface_id_, media::SurfaceManager::kNoSurfaceID); 42 DCHECK_NE(surface_id_, media::SurfaceManager::kNoSurfaceID);
43 gpu::GpuSurfaceTracker::Get()->RemoveSurface(surface_id_); 43 gpu::GpuSurfaceTracker::Get()->RemoveSurface(surface_id_);
44 gpu::GpuSurfaceTracker::Get()->UnregisterViewSurface(surface_id_); 44 gpu::GpuSurfaceTracker::Get()->UnregisterViewSurface(surface_id_);
45 SendDestroyingVideoSurfaceIfRequired(surface_id_); 45 SendDestroyingVideoSurface(surface_id_);
46 surface_id_ = media::SurfaceManager::kNoSurfaceID; 46 surface_id_ = media::SurfaceManager::kNoSurfaceID;
47 } else { 47 } else {
48 // We mainly use the surface tracker to allocate a surface id for us. The 48 // We just use the surface tracker to allocate a surface id for us. The
49 // lookup will go through the Android specific path and get the java 49 // lookup will go through the Android specific path and get the java
50 // surface directly, so there's no need to add a valid native widget here. 50 // surface directly, so there's no need to add a valid native widget here.
51 surface_id_ = gpu::GpuSurfaceTracker::Get()->AddSurfaceForNativeWidget( 51 surface_id_ = gpu::GpuSurfaceTracker::Get()->AddSurfaceForNativeWidget(
52 gfx::kNullAcceleratedWidget); 52 gfx::kNullAcceleratedWidget);
53 gpu::GpuSurfaceTracker::GetInstance()->RegisterViewSurface( 53 gpu::GpuSurfaceTracker::GetInstance()->RegisterViewSurface(
54 surface_id_, surface.j_surface()); 54 surface_id_, surface.j_surface());
55 SendSurfaceID(surface_id_); 55 SendSurfaceID(surface_id_);
56 } 56 }
57 } 57 }
58 58
59 void BrowserSurfaceViewManager::DidExitFullscreen(bool release_media_player) { 59 void BrowserSurfaceViewManager::DidExitFullscreen(bool release_media_player) {
60 DVLOG(3) << __FUNCTION__; 60 DVLOG(3) << __func__;
61 content_video_view_.reset(); 61 content_video_view_.reset();
62 } 62 }
63 63
64 void BrowserSurfaceViewManager::OnCreateFullscreenSurface( 64 void BrowserSurfaceViewManager::OnCreateFullscreenSurface(
65 const gfx::Size& video_natural_size) { 65 const gfx::Size& video_natural_size) {
66 // It's valid to get this call if we already own the fullscreen view. We just 66 // It's valid to get this call if we already own the fullscreen view. We just
67 // return the existing surface id. 67 // return the existing surface id.
68 if (content_video_view_) { 68 if (content_video_view_) {
69 // Send the surface now if we have it. Otherwise it will be returned by 69 // Send the surface now if we have it. Otherwise it will be returned by
70 // |SetVideoSurface|. 70 // |SetVideoSurface|.
(...skipping 26 matching lines...) Expand all
97 if (content_video_view_) 97 if (content_video_view_)
98 content_video_view_->OnVideoSizeChanged(size.width(), size.height()); 98 content_video_view_->OnVideoSizeChanged(size.width(), size.height());
99 } 99 }
100 100
101 bool BrowserSurfaceViewManager::SendSurfaceID(int surface_id) { 101 bool BrowserSurfaceViewManager::SendSurfaceID(int surface_id) {
102 return render_frame_host_->Send( 102 return render_frame_host_->Send(
103 new SurfaceViewManagerMsg_FullscreenSurfaceCreated( 103 new SurfaceViewManagerMsg_FullscreenSurfaceCreated(
104 render_frame_host_->GetRoutingID(), surface_id)); 104 render_frame_host_->GetRoutingID(), surface_id));
105 } 105 }
106 106
107 void BrowserSurfaceViewManager::SendDestroyingVideoSurfaceIfRequired( 107 void BrowserSurfaceViewManager::SendDestroyingVideoSurface(int surface_id) {
108 int surface_id) {
109 // Only send the surface destruction message on JB, where not doing it can
110 // cause a crash.
111 if (base::android::BuildInfo::GetInstance()->sdk_int() >= 18)
112 return;
113
114 base::WaitableEvent waiter(base::WaitableEvent::ResetPolicy::AUTOMATIC, 108 base::WaitableEvent waiter(base::WaitableEvent::ResetPolicy::AUTOMATIC,
115 base::WaitableEvent::InitialState::NOT_SIGNALED); 109 base::WaitableEvent::InitialState::NOT_SIGNALED);
116 // Unretained is okay because we're waiting on the callback. 110 // Unretained is okay because we're waiting on the callback.
117 if (BrowserThread::PostTask( 111 if (BrowserThread::PostTask(
118 BrowserThread::IO, FROM_HERE, 112 BrowserThread::IO, FROM_HERE,
119 base::Bind(&SendDestroyingVideoSurfaceOnIO, surface_id, 113 base::Bind(&SendDestroyingVideoSurfaceOnIO, surface_id,
120 base::Bind(&base::WaitableEvent::Signal, 114 base::Bind(&base::WaitableEvent::Signal,
121 base::Unretained(&waiter))))) { 115 base::Unretained(&waiter))))) {
122 base::ThreadRestrictions::ScopedAllowWait allow_wait; 116 base::ThreadRestrictions::ScopedAllowWait allow_wait;
123 waiter.Wait(); 117 waiter.Wait();
124 } 118 }
125 } 119 }
126 120
127 } // namespace content 121 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/android/browser_surface_view_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698