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

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 missing ifdefs 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
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 "content/browser/android/child_process_launcher_android.h" 8 #include "content/browser/android/child_process_launcher_android.h"
8 #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_ui_shim.h"
9 #include "content/browser/gpu/gpu_surface_tracker.h" 11 #include "content/browser/gpu/gpu_surface_tracker.h"
10 #include "content/browser/web_contents/web_contents_impl.h" 12 #include "content/browser/web_contents/web_contents_impl.h"
11 #include "content/common/media/surface_view_manager_messages_android.h" 13 #include "content/common/media/surface_view_manager_messages_android.h"
12 #include "content/public/browser/render_frame_host.h" 14 #include "content/public/browser/render_frame_host.h"
13 #include "media/base/surface_manager.h" 15 #include "media/base/surface_manager.h"
14 #include "ui/gfx/geometry/size.h" 16 #include "ui/gfx/geometry/size.h"
15 17
16 namespace content { 18 namespace content {
17 19
18 BrowserSurfaceViewManager::BrowserSurfaceViewManager( 20 BrowserSurfaceViewManager::BrowserSurfaceViewManager(
19 RenderFrameHost* render_frame_host) 21 RenderFrameHost* render_frame_host)
20 : render_frame_host_(render_frame_host), 22 : render_frame_host_(render_frame_host),
21 surface_id_(media::SurfaceManager::kNoSurfaceID) {} 23 surface_id_(media::SurfaceManager::kNoSurfaceID) {}
22 24
23 BrowserSurfaceViewManager::~BrowserSurfaceViewManager() {} 25 BrowserSurfaceViewManager::~BrowserSurfaceViewManager() {}
24 26
25 void BrowserSurfaceViewManager::SetVideoSurface( 27 void BrowserSurfaceViewManager::SetVideoSurface(
26 gfx::ScopedJavaSurface surface) { 28 gfx::ScopedJavaSurface surface) {
27 if (surface.IsEmpty()) { 29 if (surface.IsEmpty()) {
28 DCHECK_NE(surface_id_, media::SurfaceManager::kNoSurfaceID); 30 DCHECK_NE(surface_id_, media::SurfaceManager::kNoSurfaceID);
29 GpuSurfaceTracker::Get()->RemoveSurface(surface_id_); 31 GpuSurfaceTracker::Get()->RemoveSurface(surface_id_);
30 UnregisterViewSurface(surface_id_); 32 UnregisterViewSurface(surface_id_);
33 // Only send the surface destruction message on JB, where not doing it can
34 // cause crashes.
35 if (base::android::BuildInfo::GetInstance()->sdk_int() < 18)
36 SendDestroyingVideoSurface(surface_id_);
31 surface_id_ = media::SurfaceManager::kNoSurfaceID; 37 surface_id_ = media::SurfaceManager::kNoSurfaceID;
32 } else { 38 } else {
33 // We mainly use the surface tracker to allocate a surface id for us. The 39 // 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 40 // 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. 41 // surface directly, so there's no need to add a valid native widget here.
36 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForNativeWidget( 42 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForNativeWidget(
37 gfx::kNullAcceleratedWidget); 43 gfx::kNullAcceleratedWidget);
38 RegisterViewSurface(surface_id_, surface.j_surface().obj()); 44 RegisterViewSurface(surface_id_, surface.j_surface().obj());
39 SendSurfaceID(surface_id_); 45 SendSurfaceID(surface_id_);
40 } 46 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 if (content_video_view_) 82 if (content_video_view_)
77 content_video_view_->OnVideoSizeChanged(size.width(), size.height()); 83 content_video_view_->OnVideoSizeChanged(size.width(), size.height());
78 } 84 }
79 85
80 bool BrowserSurfaceViewManager::SendSurfaceID(int surface_id) { 86 bool BrowserSurfaceViewManager::SendSurfaceID(int surface_id) {
81 return render_frame_host_->Send( 87 return render_frame_host_->Send(
82 new SurfaceViewManagerMsg_FullscreenSurfaceCreated( 88 new SurfaceViewManagerMsg_FullscreenSurfaceCreated(
83 render_frame_host_->GetRoutingID(), surface_id)); 89 render_frame_host_->GetRoutingID(), surface_id));
84 } 90 }
85 91
92 void BrowserSurfaceViewManager::SendDestroyingVideoSurface(int surface_id) {
93 TRACE_EVENT0("media",
94 "BrowserSurfaceViewManager::SendDestroyingVideoSurface");
95 // XXX: How do we loop over all instances?
no sievers 2016/04/19 23:30:17 Can you move the thread bouncing code from GpuProc
watk 2016/04/22 02:48:55 Done. This is much better
96 GpuProcessHostUIShim* shim = GpuProcessHostUIShim::GetOneInstance();
97 base::WaitableEvent waiter(false, false);
98 // Unretained is okay because we're waiting on the callback below.
99 shim->DestroyingVideoSurface(
100 surface_id,
101 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&waiter)));
102 base::ThreadRestrictions::ScopedAllowWait allow_wait;
103 waiter.Wait();
104 }
105
86 } // namespace content 106 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698