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

Side by Side Diff: content/browser/renderer_host/render_widget_helper_mac.mm

Issue 370513002: Mac ÜC: Make resize smooth (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@enable_uc_for_reals
Patch Set: Add comments Created 6 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/renderer_host/render_widget_helper.h" 5 #include "content/browser/renderer_host/render_widget_helper.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <IOSurface/IOSurfaceAPI.h> 8 #include <IOSurface/IOSurfaceAPI.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/lazy_instance.h"
12 #include "base/synchronization/lock.h"
11 #include "content/browser/compositor/browser_compositor_view_mac.h" 13 #include "content/browser/compositor/browser_compositor_view_mac.h"
12 #include "content/browser/gpu/gpu_process_host.h" 14 #include "content/browser/gpu/gpu_process_host.h"
13 #include "content/browser/gpu/gpu_surface_tracker.h" 15 #include "content/browser/gpu/gpu_surface_tracker.h"
14 #include "content/common/gpu/gpu_messages.h" 16 #include "content/common/gpu/gpu_messages.h"
15 #include "content/common/gpu/surface_handle_types_mac.h" 17 #include "content/common/gpu/surface_handle_types_mac.h"
18 #include "content/common/view_messages.h"
16 19
20 namespace content {
17 namespace { 21 namespace {
22 typedef std::map<gfx::AcceleratedWidget,std::pair<int,int>> WidgetMap;
23 base::LazyInstance<WidgetMap> g_widget_map;
24 base::LazyInstance<base::Lock> g_lock;
25 } // namespace
18 26
19 void OnNativeSurfaceBuffersSwappedOnUIThread( 27 // static
20 base::ScopedCFTypeRef<IOSurfaceRef> io_surface, 28 void RenderWidgetHelper::SetRenderWidgetIDForWidget(
21 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { 29 gfx::AcceleratedWidget native_widget,
30 int render_process_id,
31 int render_widget_id) {
32 base::AutoLock lock(g_lock.Get());
33 g_widget_map.Get()[native_widget] = std::make_pair(
34 render_process_id, render_widget_id);
35 }
36
37 // static
38 void RenderWidgetHelper::ResetRenderWidgetIDForWidget(
39 gfx::AcceleratedWidget native_widget) {
40 base::AutoLock lock(g_lock.Get());
41 g_widget_map.Get().erase(native_widget);
42 }
43
44 // static
45 bool RenderWidgetHelper::GetRenderWidgetIDForWidget(
46 gfx::AcceleratedWidget native_widget,
47 int* render_process_id,
48 int* render_widget_id) {
49 base::AutoLock lock(g_lock.Get());
50
51 auto found = g_widget_map.Get().find(native_widget);
52 if (found != g_widget_map.Get().end()) {
53 *render_process_id = found->second.first;
54 *render_widget_id = found->second.second;
55 return true;
56 }
57
58 *render_process_id = 0;
59 *render_widget_id = 0;
60 return false;
61 }
62
63 // static
64 void RenderWidgetHelper::OnNativeSurfaceBuffersSwappedOnUIThread(
65 const ViewHostMsg_CompositorSurfaceBuffersSwapped_Params& params) {
22 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 66 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
23 gfx::AcceleratedWidget native_widget = 67 gfx::AcceleratedWidget native_widget =
24 content::GpuSurfaceTracker::Get()->AcquireNativeWidget(params.surface_id); 68 content::GpuSurfaceTracker::Get()->AcquireNativeWidget(params.surface_id);
25 IOSurfaceID io_surface_id = content::IOSurfaceIDFromSurfaceHandle( 69 IOSurfaceID io_surface_id = content::IOSurfaceIDFromSurfaceHandle(
26 params.surface_handle); 70 params.surface_handle);
27 [native_widget gotAcceleratedIOSurfaceFrame:io_surface_id 71 [native_widget gotAcceleratedIOSurfaceFrame:io_surface_id
28 withOutputSurfaceID:params.surface_id 72 withOutputSurfaceID:params.surface_id
29 withLatencyInfo:params.latency_info 73 withLatencyInfo:params.latency_info
30 withPixelSize:params.size 74 withPixelSize:params.size
31 withScaleFactor:params.scale_factor]; 75 withScaleFactor:params.scale_factor];
32 } 76 }
33 77
34 } // namespace
35
36 namespace content {
37
38 void RenderWidgetHelper::OnNativeSurfaceBuffersSwappedOnIOThread(
39 GpuProcessHost* gpu_process_host,
40 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) {
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
42
43 // Immediately acknowledge this frame on the IO thread instead of the UI
44 // thread. The UI thread will wait on the GPU process. If the UI thread
45 // were to be responsible for acking swaps, then there would be a cycle
46 // and a potential deadlock.
47 // TODO(ccameron): This immediate ack circumvents GPU back-pressure that
48 // is necessary to throttle renderers. Fix that.
49 AcceleratedSurfaceMsg_BufferPresented_Params ack_params;
50 ack_params.sync_point = 0;
51 ack_params.renderer_id = 0;
52 gpu_process_host->Send(new AcceleratedSurfaceMsg_BufferPresented(
53 params.route_id, ack_params));
54
55 // Open the IOSurface handle before returning, to ensure that it is not
56 // closed as soon as the frame is acknowledged.
57 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceLookup(
58 static_cast<uint32>(params.surface_handle)));
59
60 BrowserThread::PostTask(
61 BrowserThread::UI,
62 FROM_HERE,
63 base::Bind(&OnNativeSurfaceBuffersSwappedOnUIThread, io_surface, params));
64 }
65
66 } // namespace content 78 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_helper.h ('k') | content/browser/renderer_host/render_widget_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698