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