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

Side by Side Diff: content/browser/compositor/browser_compositor_view_mac.mm

Issue 638123003: Prepare to move BrowserCompositorViewMac to ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporate review feedback Created 6 years, 2 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/compositor/browser_compositor_view_mac.h" 5 #include "content/browser/compositor/browser_compositor_view_mac.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "content/browser/gpu/gpu_process_host_ui_shim.h" 9 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
10 #include "content/browser/compositor/browser_compositor_ca_layer_tree_mac.h" 10 #include "content/browser/compositor/browser_compositor_ca_layer_tree_mac.h"
(...skipping 10 matching lines...) Expand all
21 // |g_recyclable_ca_layer_tree|, will be freed. 21 // |g_recyclable_ca_layer_tree|, will be freed.
22 uint32 g_placeholder_count = 0; 22 uint32 g_placeholder_count = 0;
23 23
24 // A spare BrowserCompositorCALayerTreeMac kept around for recycling. 24 // A spare BrowserCompositorCALayerTreeMac kept around for recycling.
25 base::LazyInstance<scoped_ptr<BrowserCompositorCALayerTreeMac>> 25 base::LazyInstance<scoped_ptr<BrowserCompositorCALayerTreeMac>>
26 g_recyclable_ca_layer_tree; 26 g_recyclable_ca_layer_tree;
27 27
28 } // namespace 28 } // namespace
29 29
30 BrowserCompositorViewMac::BrowserCompositorViewMac( 30 BrowserCompositorViewMac::BrowserCompositorViewMac(
31 BrowserCompositorViewMacClient* client) : client_(client) { 31 BrowserCompositorViewMacClient* client,
32 NSView* native_view,
33 ui::Layer* ui_root_layer)
34 : client_(client),
35 native_view_(native_view),
36 ui_root_layer_(ui_root_layer) {
32 // Try to use the recyclable BrowserCompositorCALayerTreeMac if there is one, 37 // Try to use the recyclable BrowserCompositorCALayerTreeMac if there is one,
33 // otherwise allocate a new one. 38 // otherwise allocate a new one.
34 // TODO(ccameron): If there exists a frame in flight (swap has been called 39 // TODO(ccameron): If there exists a frame in flight (swap has been called
35 // by the compositor, but the frame has not arrived from the GPU process 40 // by the compositor, but the frame has not arrived from the GPU process
36 // yet), then that frame may inappropriately flash in the new view. 41 // yet), then that frame may inappropriately flash in the new view.
37 ca_layer_tree_ = g_recyclable_ca_layer_tree.Get().Pass(); 42 ca_layer_tree_ = g_recyclable_ca_layer_tree.Get().Pass();
38 if (!ca_layer_tree_) 43 if (!ca_layer_tree_)
39 ca_layer_tree_.reset(new BrowserCompositorCALayerTreeMac); 44 ca_layer_tree_.reset(new BrowserCompositorCALayerTreeMac);
40 ca_layer_tree_->SetClient(client_); 45 ca_layer_tree_->SetView(this);
41 } 46 }
42 47
43 BrowserCompositorViewMac::~BrowserCompositorViewMac() { 48 BrowserCompositorViewMac::~BrowserCompositorViewMac() {
44 // Make this BrowserCompositorCALayerTreeMac recyclable for future instances. 49 // Make this BrowserCompositorCALayerTreeMac recyclable for future instances.
45 ca_layer_tree_->ResetClient(); 50 ca_layer_tree_->ResetView();
46 g_recyclable_ca_layer_tree.Get() = ca_layer_tree_.Pass(); 51 g_recyclable_ca_layer_tree.Get() = ca_layer_tree_.Pass();
47 52
48 // If there are no placeholders allocated, destroy the recyclable 53 // If there are no placeholders allocated, destroy the recyclable
49 // BrowserCompositorCALayerTreeMac that we just populated. 54 // BrowserCompositorCALayerTreeMac that we just populated.
50 if (!g_placeholder_count) 55 if (!g_placeholder_count)
51 g_recyclable_ca_layer_tree.Get().reset(); 56 g_recyclable_ca_layer_tree.Get().reset();
52 } 57 }
53 58
54 ui::Compositor* BrowserCompositorViewMac::GetCompositor() const { 59 ui::Compositor* BrowserCompositorViewMac::GetCompositor() const {
55 DCHECK(ca_layer_tree_); 60 DCHECK(ca_layer_tree_);
(...skipping 10 matching lines...) Expand all
66 void BrowserCompositorViewMac::BeginPumpingFrames() { 71 void BrowserCompositorViewMac::BeginPumpingFrames() {
67 if (ca_layer_tree_) 72 if (ca_layer_tree_)
68 ca_layer_tree_->BeginPumpingFrames(); 73 ca_layer_tree_->BeginPumpingFrames();
69 } 74 }
70 75
71 void BrowserCompositorViewMac::EndPumpingFrames() { 76 void BrowserCompositorViewMac::EndPumpingFrames() {
72 if (ca_layer_tree_) 77 if (ca_layer_tree_)
73 ca_layer_tree_->EndPumpingFrames(); 78 ca_layer_tree_->EndPumpingFrames();
74 } 79 }
75 80
76 // static
77 void BrowserCompositorViewMac::GotAcceleratedFrame(
78 gfx::AcceleratedWidget widget,
79 uint64 surface_handle, int surface_id,
80 const std::vector<ui::LatencyInfo>& latency_info,
81 gfx::Size pixel_size, float scale_factor,
82 int gpu_host_id, int gpu_route_id) {
83 BrowserCompositorCALayerTreeMac* ca_layer_tree =
84 BrowserCompositorCALayerTreeMac::FromAcceleratedWidget(widget);
85 bool disable_throttling = false;
86 int renderer_id = 0;
87 if (ca_layer_tree) {
88 ca_layer_tree->GotAcceleratedFrame(
89 surface_handle, surface_id, latency_info, pixel_size, scale_factor);
90 disable_throttling = ca_layer_tree->IsRendererThrottlingDisabled();
91 renderer_id = ca_layer_tree->GetRendererID();
92 }
93
94 // Acknowledge the swap, now that it has been processed.
95 AcceleratedSurfaceMsg_BufferPresented_Params ack_params;
96 ack_params.disable_throttling = disable_throttling;
97 ack_params.renderer_id = renderer_id;
98 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id);
99 if (ui_shim) {
100 ui_shim->Send(new AcceleratedSurfaceMsg_BufferPresented(
101 gpu_route_id, ack_params));
102 }
103 }
104
105 // static
106 void BrowserCompositorViewMac::GotSoftwareFrame(
107 gfx::AcceleratedWidget widget,
108 cc::SoftwareFrameData* frame_data, float scale_factor, SkCanvas* canvas) {
109 BrowserCompositorCALayerTreeMac* ca_layer_tree =
110 BrowserCompositorCALayerTreeMac::FromAcceleratedWidget(widget);
111 if (ca_layer_tree)
112 ca_layer_tree->GotSoftwareFrame(frame_data, scale_factor, canvas);
113 }
114
115 //////////////////////////////////////////////////////////////////////////////// 81 ////////////////////////////////////////////////////////////////////////////////
116 // BrowserCompositorViewPlaceholderMac 82 // BrowserCompositorViewPlaceholderMac
117 83
118 BrowserCompositorViewPlaceholderMac::BrowserCompositorViewPlaceholderMac() { 84 BrowserCompositorViewPlaceholderMac::BrowserCompositorViewPlaceholderMac() {
119 g_placeholder_count += 1; 85 g_placeholder_count += 1;
120 } 86 }
121 87
122 BrowserCompositorViewPlaceholderMac::~BrowserCompositorViewPlaceholderMac() { 88 BrowserCompositorViewPlaceholderMac::~BrowserCompositorViewPlaceholderMac() {
123 DCHECK_GT(g_placeholder_count, 0u); 89 DCHECK_GT(g_placeholder_count, 0u);
124 g_placeholder_count -= 1; 90 g_placeholder_count -= 1;
125 91
126 // If there are no placeholders allocated, destroy the recyclable 92 // If there are no placeholders allocated, destroy the recyclable
127 // BrowserCompositorCALayerTreeMac. 93 // BrowserCompositorCALayerTreeMac.
128 if (!g_placeholder_count) 94 if (!g_placeholder_count)
129 g_recyclable_ca_layer_tree.Get().reset(); 95 g_recyclable_ca_layer_tree.Get().reset();
130 } 96 }
131 97
132 } // namespace content 98 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698