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

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: 287efe04 Rebase, oshima@ nits. 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"
15 #include "ui/compositor/compositor_switches.h" 13 #include "ui/compositor/compositor_switches.h"
16 14
17 namespace content { 15 namespace content {
18 16
19 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( 17 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface(
20 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, 18 const scoped_refptr<ContextProviderCommandBuffer>& context_provider,
21 int surface_id, 19 int surface_id,
22 IDMap<BrowserCompositorOutputSurface>* output_surface_map, 20 IDMap<BrowserCompositorOutputSurface>* output_surface_map,
23 base::MessageLoopProxy* compositor_message_loop, 21 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager)
24 base::WeakPtr<ui::Compositor> compositor)
25 : OutputSurface(context_provider), 22 : OutputSurface(context_provider),
26 surface_id_(surface_id), 23 surface_id_(surface_id),
27 output_surface_map_(output_surface_map), 24 output_surface_map_(output_surface_map),
28 compositor_message_loop_(compositor_message_loop), 25 vsync_manager_(vsync_manager) {
29 compositor_(compositor) {
30 Initialize(); 26 Initialize();
31 } 27 }
32 28
33 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( 29 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface(
34 scoped_ptr<cc::SoftwareOutputDevice> software_device, 30 scoped_ptr<cc::SoftwareOutputDevice> software_device,
35 int surface_id, 31 int surface_id,
36 IDMap<BrowserCompositorOutputSurface>* output_surface_map, 32 IDMap<BrowserCompositorOutputSurface>* output_surface_map,
37 base::MessageLoopProxy* compositor_message_loop, 33 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager)
38 base::WeakPtr<ui::Compositor> compositor)
39 : OutputSurface(software_device.Pass()), 34 : OutputSurface(software_device.Pass()),
40 surface_id_(surface_id), 35 surface_id_(surface_id),
41 output_surface_map_(output_surface_map), 36 output_surface_map_(output_surface_map),
42 compositor_message_loop_(compositor_message_loop), 37 vsync_manager_(vsync_manager) {
43 compositor_(compositor) {
44 Initialize(); 38 Initialize();
45 } 39 }
46 40
47 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() { 41 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() {
48 DCHECK(CalledOnValidThread()); 42 DCHECK(CalledOnValidThread());
49 if (!HasClient()) 43 if (!HasClient())
50 return; 44 return;
51 output_surface_map_->Remove(surface_id_); 45 output_surface_map_->Remove(surface_id_);
46 vsync_manager_->RemoveObserver(this);
52 } 47 }
53 48
54 void BrowserCompositorOutputSurface::Initialize() { 49 void BrowserCompositorOutputSurface::Initialize() {
55 CommandLine* command_line = CommandLine::ForCurrentProcess(); 50 CommandLine* command_line = CommandLine::ForCurrentProcess();
56 if (command_line->HasSwitch(switches::kUIMaxFramesPending)) { 51 if (command_line->HasSwitch(switches::kUIMaxFramesPending)) {
57 std::string string_value = command_line->GetSwitchValueASCII( 52 std::string string_value = command_line->GetSwitchValueASCII(
58 switches::kUIMaxFramesPending); 53 switches::kUIMaxFramesPending);
59 int int_value; 54 int int_value;
60 if (base::StringToInt(string_value, &int_value)) 55 if (base::StringToInt(string_value, &int_value))
61 capabilities_.max_frames_pending = int_value; 56 capabilities_.max_frames_pending = int_value;
62 else 57 else
63 LOG(ERROR) << "Trouble parsing --" << switches::kUIMaxFramesPending; 58 LOG(ERROR) << "Trouble parsing --" << switches::kUIMaxFramesPending;
64 } 59 }
65 capabilities_.adjust_deadline_for_parent = false; 60 capabilities_.adjust_deadline_for_parent = false;
66 61
67 DetachFromThread(); 62 DetachFromThread();
68 } 63 }
69 64
70 bool BrowserCompositorOutputSurface::BindToClient( 65 bool BrowserCompositorOutputSurface::BindToClient(
71 cc::OutputSurfaceClient* client) { 66 cc::OutputSurfaceClient* client) {
72 DCHECK(CalledOnValidThread()); 67 DCHECK(CalledOnValidThread());
73 68
74 if (!OutputSurface::BindToClient(client)) 69 if (!OutputSurface::BindToClient(client))
75 return false; 70 return false;
76 71
77 output_surface_map_->AddWithID(this, surface_id_); 72 output_surface_map_->AddWithID(this, surface_id_);
78 if (reflector_) 73 if (reflector_)
79 reflector_->OnSourceSurfaceReady(surface_id_); 74 reflector_->OnSourceSurfaceReady(surface_id_);
75 vsync_manager_->AddObserver(this);
80 return true; 76 return true;
81 } 77 }
82 78
83 void BrowserCompositorOutputSurface::Reshape(const gfx::Size& size, 79 void BrowserCompositorOutputSurface::Reshape(const gfx::Size& size,
84 float scale_factor) { 80 float scale_factor) {
85 OutputSurface::Reshape(size, scale_factor); 81 OutputSurface::Reshape(size, scale_factor);
86 if (reflector_.get()) 82 if (reflector_.get())
87 reflector_->OnReshape(size); 83 reflector_->OnReshape(size);
88 } 84 }
89 85
90 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters( 86 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters(
91 base::TimeTicks timebase, 87 base::TimeTicks timebase,
92 base::TimeDelta interval) { 88 base::TimeDelta interval) {
93 DCHECK(CalledOnValidThread()); 89 DCHECK(CalledOnValidThread());
94 DCHECK(HasClient()); 90 DCHECK(HasClient());
95 OnVSyncParametersChanged(timebase, interval); 91 CommitVSyncParameters(timebase, interval);
96 compositor_message_loop_->PostTask( 92 }
97 FROM_HERE, 93
98 base::Bind(&ui::Compositor::OnUpdateVSyncParameters, 94 void BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu(
99 compositor_, timebase, interval)); 95 base::TimeTicks timebase,
96 base::TimeDelta interval) {
97 DCHECK(CalledOnValidThread());
98 DCHECK(HasClient());
99 vsync_manager_->UpdateVSyncParameters(timebase, interval);
100 } 100 }
101 101
102 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl* reflector) { 102 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl* reflector) {
103 reflector_ = reflector; 103 reflector_ = reflector;
104 } 104 }
105 105
106 } // namespace content 106 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698