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

Side by Side Diff: content/browser/compositor/browser_compositor_output_surface.cc

Issue 138903025: Read compositor VSync information from platform, when possible (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 4b969456 piman@ comments; refactor logic into CompositorVSyncManager Created 6 years, 10 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 | Annotate | Revision Log
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_output_surface.h" 5 #include "content/browser/compositor/browser_compositor_output_surface.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
12 #include "content/browser/compositor/reflector_impl.h" 11 #include "content/browser/compositor/reflector_impl.h"
13 #include "content/common/gpu/client/context_provider_command_buffer.h" 12 #include "content/common/gpu/client/context_provider_command_buffer.h"
14 #include "ui/compositor/compositor.h" 13 #include "ui/compositor/compositor.h"
15 #include "ui/compositor/compositor_switches.h" 14 #include "ui/compositor/compositor_switches.h"
16 15
17 namespace content { 16 namespace content {
18 17
19 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( 18 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface(
20 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, 19 const scoped_refptr<ContextProviderCommandBuffer>& context_provider,
21 int surface_id, 20 int surface_id,
22 IDMap<BrowserCompositorOutputSurface>* output_surface_map, 21 IDMap<BrowserCompositorOutputSurface>* output_surface_map,
23 base::MessageLoopProxy* compositor_message_loop, 22 ui::Compositor* compositor)
piman 2014/02/04 04:51:01 nit: pass in the vsync_manager() to the constructo
sheu 2014/02/04 22:01:45 I was under the impression that passing a raw poin
24 base::WeakPtr<ui::Compositor> compositor)
25 : OutputSurface(context_provider), 23 : OutputSurface(context_provider),
26 surface_id_(surface_id), 24 surface_id_(surface_id),
27 output_surface_map_(output_surface_map), 25 output_surface_map_(output_surface_map),
28 compositor_message_loop_(compositor_message_loop), 26 vsync_manager_(compositor->vsync_manager()) {
29 compositor_(compositor) {
30 Initialize(); 27 Initialize();
31 } 28 }
32 29
33 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( 30 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface(
34 scoped_ptr<cc::SoftwareOutputDevice> software_device, 31 scoped_ptr<cc::SoftwareOutputDevice> software_device,
35 int surface_id, 32 int surface_id,
36 IDMap<BrowserCompositorOutputSurface>* output_surface_map, 33 IDMap<BrowserCompositorOutputSurface>* output_surface_map,
37 base::MessageLoopProxy* compositor_message_loop, 34 ui::Compositor* compositor)
38 base::WeakPtr<ui::Compositor> compositor)
39 : OutputSurface(software_device.Pass()), 35 : OutputSurface(software_device.Pass()),
40 surface_id_(surface_id), 36 surface_id_(surface_id),
41 output_surface_map_(output_surface_map), 37 output_surface_map_(output_surface_map),
42 compositor_message_loop_(compositor_message_loop), 38 vsync_manager_(compositor->vsync_manager()) {
43 compositor_(compositor) {
44 Initialize(); 39 Initialize();
45 } 40 }
46 41
47 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() { 42 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() {
48 DCHECK(CalledOnValidThread()); 43 DCHECK(CalledOnValidThread());
44 vsync_manager_->RemoveObserver(this);
49 if (!HasClient()) 45 if (!HasClient())
50 return; 46 return;
51 output_surface_map_->Remove(surface_id_); 47 output_surface_map_->Remove(surface_id_);
52 } 48 }
53 49
54 void BrowserCompositorOutputSurface::Initialize() { 50 void BrowserCompositorOutputSurface::Initialize() {
55 CommandLine* command_line = CommandLine::ForCurrentProcess(); 51 CommandLine* command_line = CommandLine::ForCurrentProcess();
56 if (command_line->HasSwitch(switches::kUIMaxFramesPending)) { 52 if (command_line->HasSwitch(switches::kUIMaxFramesPending)) {
57 std::string string_value = command_line->GetSwitchValueASCII( 53 std::string string_value = command_line->GetSwitchValueASCII(
58 switches::kUIMaxFramesPending); 54 switches::kUIMaxFramesPending);
59 int int_value; 55 int int_value;
60 if (base::StringToInt(string_value, &int_value)) 56 if (base::StringToInt(string_value, &int_value))
61 capabilities_.max_frames_pending = int_value; 57 capabilities_.max_frames_pending = int_value;
62 else 58 else
63 LOG(ERROR) << "Trouble parsing --" << switches::kUIMaxFramesPending; 59 LOG(ERROR) << "Trouble parsing --" << switches::kUIMaxFramesPending;
64 } 60 }
65 capabilities_.adjust_deadline_for_parent = false; 61 capabilities_.adjust_deadline_for_parent = false;
62 vsync_manager_->AddObserver(this);
66 63
67 DetachFromThread(); 64 DetachFromThread();
68 } 65 }
69 66
70 bool BrowserCompositorOutputSurface::BindToClient( 67 bool BrowserCompositorOutputSurface::BindToClient(
71 cc::OutputSurfaceClient* client) { 68 cc::OutputSurfaceClient* client) {
72 DCHECK(CalledOnValidThread()); 69 DCHECK(CalledOnValidThread());
73 70
74 if (!OutputSurface::BindToClient(client)) 71 if (!OutputSurface::BindToClient(client))
75 return false; 72 return false;
76 73
77 output_surface_map_->AddWithID(this, surface_id_); 74 output_surface_map_->AddWithID(this, surface_id_);
78 if (reflector_) 75 if (reflector_)
79 reflector_->OnSourceSurfaceReady(surface_id_); 76 reflector_->OnSourceSurfaceReady(surface_id_);
80 return true; 77 return true;
81 } 78 }
82 79
83 void BrowserCompositorOutputSurface::Reshape(const gfx::Size& size, 80 void BrowserCompositorOutputSurface::Reshape(const gfx::Size& size,
84 float scale_factor) { 81 float scale_factor) {
85 OutputSurface::Reshape(size, scale_factor); 82 OutputSurface::Reshape(size, scale_factor);
86 if (reflector_.get()) 83 if (reflector_.get())
87 reflector_->OnReshape(size); 84 reflector_->OnReshape(size);
88 } 85 }
89 86
90 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters( 87 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters(
91 base::TimeTicks timebase, 88 base::TimeTicks timebase,
92 base::TimeDelta interval) { 89 base::TimeDelta interval) {
93 DCHECK(CalledOnValidThread()); 90 DCHECK(CalledOnValidThread());
94 DCHECK(HasClient()); 91 DCHECK(HasClient());
95 OnVSyncParametersChanged(timebase, interval); 92 CommitVSyncParameters(timebase, interval);
96 compositor_message_loop_->PostTask( 93 }
97 FROM_HERE, 94
98 base::Bind(&ui::Compositor::OnUpdateVSyncParameters, 95 void BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu(
99 compositor_, timebase, interval)); 96 base::TimeTicks timebase,
97 base::TimeDelta interval) {
98 DCHECK(CalledOnValidThread());
99 DCHECK(HasClient());
100 vsync_manager_->UpdateVSyncParameters(timebase, interval);
100 } 101 }
101 102
102 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl* reflector) { 103 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl* reflector) {
103 reflector_ = reflector; 104 reflector_ = reflector;
104 } 105 }
105 106
106 } // namespace content 107 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698