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

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

Issue 1878103002: Plumb a Browser->GPU surface destruction message for Android VDAs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a threadchecker Created 4 years, 8 months 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') | content/common/BUILD.gn » ('j') | 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"
8 #include "base/trace_event/trace_event.h"
7 #include "content/browser/android/child_process_launcher_android.h" 9 #include "content/browser/android/child_process_launcher_android.h"
8 #include "content/browser/android/content_view_core_impl.h" 10 #include "content/browser/android/content_view_core_impl.h"
11 #include "content/browser/gpu/gpu_process_host.h"
9 #include "content/browser/gpu/gpu_surface_tracker.h" 12 #include "content/browser/gpu/gpu_surface_tracker.h"
10 #include "content/browser/web_contents/web_contents_impl.h" 13 #include "content/browser/web_contents/web_contents_impl.h"
11 #include "content/common/media/surface_view_manager_messages_android.h" 14 #include "content/common/media/surface_view_manager_messages_android.h"
12 #include "content/public/browser/render_frame_host.h" 15 #include "content/public/browser/render_frame_host.h"
13 #include "media/base/surface_manager.h" 16 #include "media/base/surface_manager.h"
14 #include "ui/gfx/geometry/size.h" 17 #include "ui/gfx/geometry/size.h"
15 18
16 namespace content { 19 namespace content {
20 namespace {
21 void SendDestroyingVideoSurfaceOnIO(int surface_id,
22 const base::Closure& done_cb) {
23 GpuProcessHost* host =
24 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED,
25 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH);
26 if (host)
27 host->SendDestroyingVideoSurface(surface_id, done_cb);
28 else
29 done_cb.Run();
30 }
31 } // namespace
17 32
18 BrowserSurfaceViewManager::BrowserSurfaceViewManager( 33 BrowserSurfaceViewManager::BrowserSurfaceViewManager(
19 RenderFrameHost* render_frame_host) 34 RenderFrameHost* render_frame_host)
20 : render_frame_host_(render_frame_host), 35 : render_frame_host_(render_frame_host),
21 surface_id_(media::SurfaceManager::kNoSurfaceID) {} 36 surface_id_(media::SurfaceManager::kNoSurfaceID) {}
22 37
23 BrowserSurfaceViewManager::~BrowserSurfaceViewManager() {} 38 BrowserSurfaceViewManager::~BrowserSurfaceViewManager() {}
24 39
25 void BrowserSurfaceViewManager::SetVideoSurface( 40 void BrowserSurfaceViewManager::SetVideoSurface(
26 gfx::ScopedJavaSurface surface) { 41 gfx::ScopedJavaSurface surface) {
42 TRACE_EVENT0("media", "BrowserSurfaceViewManager::SetVideoSurface");
27 if (surface.IsEmpty()) { 43 if (surface.IsEmpty()) {
28 DCHECK_NE(surface_id_, media::SurfaceManager::kNoSurfaceID); 44 DCHECK_NE(surface_id_, media::SurfaceManager::kNoSurfaceID);
29 GpuSurfaceTracker::Get()->RemoveSurface(surface_id_); 45 GpuSurfaceTracker::Get()->RemoveSurface(surface_id_);
30 UnregisterViewSurface(surface_id_); 46 UnregisterViewSurface(surface_id_);
47 SendDestroyingVideoSurfaceIfRequired(surface_id_);
31 surface_id_ = media::SurfaceManager::kNoSurfaceID; 48 surface_id_ = media::SurfaceManager::kNoSurfaceID;
32 } else { 49 } else {
33 // We mainly use the surface tracker to allocate a surface id for us. The 50 // 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 51 // 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. 52 // surface directly, so there's no need to add a valid native widget here.
36 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForNativeWidget( 53 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForNativeWidget(
37 gfx::kNullAcceleratedWidget); 54 gfx::kNullAcceleratedWidget);
38 RegisterViewSurface(surface_id_, surface.j_surface().obj()); 55 RegisterViewSurface(surface_id_, surface.j_surface().obj());
39 SendSurfaceID(surface_id_); 56 SendSurfaceID(surface_id_);
40 } 57 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 if (content_video_view_) 93 if (content_video_view_)
77 content_video_view_->OnVideoSizeChanged(size.width(), size.height()); 94 content_video_view_->OnVideoSizeChanged(size.width(), size.height());
78 } 95 }
79 96
80 bool BrowserSurfaceViewManager::SendSurfaceID(int surface_id) { 97 bool BrowserSurfaceViewManager::SendSurfaceID(int surface_id) {
81 return render_frame_host_->Send( 98 return render_frame_host_->Send(
82 new SurfaceViewManagerMsg_FullscreenSurfaceCreated( 99 new SurfaceViewManagerMsg_FullscreenSurfaceCreated(
83 render_frame_host_->GetRoutingID(), surface_id)); 100 render_frame_host_->GetRoutingID(), surface_id));
84 } 101 }
85 102
103 void BrowserSurfaceViewManager::SendDestroyingVideoSurfaceIfRequired(
104 int surface_id) {
105 // Only send the surface destruction message on JB, where not doing it can
106 // cause a crash.
107 if (base::android::BuildInfo::GetInstance()->sdk_int() >= 18)
108 return;
109
110 base::WaitableEvent waiter(false, false);
111 // Unretained is okay because we're waiting on the callback.
112 if (BrowserThread::PostTask(
113 BrowserThread::IO, FROM_HERE,
114 base::Bind(&SendDestroyingVideoSurfaceOnIO, surface_id,
115 base::Bind(&base::WaitableEvent::Signal,
116 base::Unretained(&waiter))))) {
117 base::ThreadRestrictions::ScopedAllowWait allow_wait;
118 waiter.Wait();
119 }
120 }
121
86 } // namespace content 122 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/android/browser_surface_view_manager.h ('k') | content/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698