| 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/location.h" | 8 #include "base/location.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "content/browser/compositor/reflector_impl.h" | 10 #include "content/browser/compositor/reflector_impl.h" |
| 11 #include "content/common/gpu/client/context_provider_command_buffer.h" | 11 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( | 15 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( |
| 16 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, | 16 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, |
| 17 int surface_id, | 17 int surface_id, |
| 18 IDMap<BrowserCompositorOutputSurface>* output_surface_map, | 18 IDMap<BrowserCompositorOutputSurface>* output_surface_map) |
| 19 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager) | |
| 20 : OutputSurface(context_provider), | 19 : OutputSurface(context_provider), |
| 21 surface_id_(surface_id), | 20 surface_id_(surface_id), |
| 22 output_surface_map_(output_surface_map), | 21 output_surface_map_(output_surface_map) { |
| 23 vsync_manager_(vsync_manager) { | |
| 24 Initialize(); | 22 Initialize(); |
| 25 } | 23 } |
| 26 | 24 |
| 27 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( | 25 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( |
| 28 scoped_ptr<cc::SoftwareOutputDevice> software_device, | 26 scoped_ptr<cc::SoftwareOutputDevice> software_device, |
| 29 int surface_id, | 27 int surface_id, |
| 30 IDMap<BrowserCompositorOutputSurface>* output_surface_map, | 28 IDMap<BrowserCompositorOutputSurface>* output_surface_map) |
| 31 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager) | |
| 32 : OutputSurface(software_device.Pass()), | 29 : OutputSurface(software_device.Pass()), |
| 33 surface_id_(surface_id), | 30 surface_id_(surface_id), |
| 34 output_surface_map_(output_surface_map), | 31 output_surface_map_(output_surface_map) { |
| 35 vsync_manager_(vsync_manager) { | |
| 36 Initialize(); | 32 Initialize(); |
| 37 } | 33 } |
| 38 | 34 |
| 39 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() { | 35 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() { |
| 40 DCHECK(CalledOnValidThread()); | 36 DCHECK(CalledOnValidThread()); |
| 41 if (reflector_.get()) | 37 if (reflector_.get()) |
| 42 reflector_->DetachFromOutputSurface(); | 38 reflector_->DetachFromOutputSurface(); |
| 43 DCHECK(!reflector_.get()); | 39 DCHECK(!reflector_.get()); |
| 44 if (!HasClient()) | 40 if (!HasClient()) |
| 45 return; | 41 return; |
| 46 output_surface_map_->Remove(surface_id_); | 42 output_surface_map_->Remove(surface_id_); |
| 47 vsync_manager_->RemoveObserver(this); | |
| 48 } | 43 } |
| 49 | 44 |
| 50 void BrowserCompositorOutputSurface::Initialize() { | 45 void BrowserCompositorOutputSurface::Initialize() { |
| 51 capabilities_.max_frames_pending = 1; | 46 capabilities_.max_frames_pending = 1; |
| 52 capabilities_.adjust_deadline_for_parent = false; | 47 capabilities_.adjust_deadline_for_parent = false; |
| 53 | 48 |
| 54 DetachFromThread(); | 49 DetachFromThread(); |
| 55 } | 50 } |
| 56 | 51 |
| 57 bool BrowserCompositorOutputSurface::BindToClient( | 52 bool BrowserCompositorOutputSurface::BindToClient( |
| 58 cc::OutputSurfaceClient* client) { | 53 cc::OutputSurfaceClient* client) { |
| 59 DCHECK(CalledOnValidThread()); | 54 DCHECK(CalledOnValidThread()); |
| 60 | 55 |
| 61 if (!OutputSurface::BindToClient(client)) | 56 if (!OutputSurface::BindToClient(client)) |
| 62 return false; | 57 return false; |
| 63 | 58 |
| 64 output_surface_map_->AddWithID(this, surface_id_); | 59 output_surface_map_->AddWithID(this, surface_id_); |
| 65 if (reflector_.get()) | 60 if (reflector_.get()) |
| 66 reflector_->OnSourceSurfaceReady(this); | 61 reflector_->OnSourceSurfaceReady(this); |
| 67 vsync_manager_->AddObserver(this); | |
| 68 return true; | 62 return true; |
| 69 } | 63 } |
| 70 | 64 |
| 71 void BrowserCompositorOutputSurface::OnSwapBuffersComplete() { | 65 void BrowserCompositorOutputSurface::OnSwapBuffersComplete() { |
| 72 // On Mac, delay acknowledging the swap to the output surface client until | 66 // On Mac, delay acknowledging the swap to the output surface client until |
| 73 // it has been drawn. | 67 // it has been drawn. |
| 74 #if !defined(OS_MACOSX) | 68 #if !defined(OS_MACOSX) |
| 75 cc::OutputSurface::OnSwapBuffersComplete(); | 69 cc::OutputSurface::OnSwapBuffersComplete(); |
| 76 #endif | 70 #endif |
| 77 } | 71 } |
| 78 | 72 |
| 79 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters( | 73 void BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu( |
| 80 base::TimeTicks timebase, | 74 base::TimeTicks timebase, |
| 81 base::TimeDelta interval) { | 75 base::TimeDelta interval) { |
| 82 DCHECK(CalledOnValidThread()); | 76 DCHECK(CalledOnValidThread()); |
| 83 DCHECK(HasClient()); | 77 DCHECK(HasClient()); |
| 84 CommitVSyncParameters(timebase, interval); | 78 CommitVSyncParameters(timebase, interval); |
| 85 } | 79 } |
| 86 | 80 |
| 87 void BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu( | |
| 88 base::TimeTicks timebase, | |
| 89 base::TimeDelta interval) { | |
| 90 DCHECK(CalledOnValidThread()); | |
| 91 DCHECK(HasClient()); | |
| 92 vsync_manager_->UpdateVSyncParameters(timebase, interval); | |
| 93 } | |
| 94 | |
| 95 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl* reflector) { | 81 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl* reflector) { |
| 96 reflector_ = reflector; | 82 reflector_ = reflector; |
| 97 } | 83 } |
| 98 | 84 |
| 99 #if defined(OS_MACOSX) | 85 #if defined(OS_MACOSX) |
| 100 void BrowserCompositorOutputSurface::OnSurfaceDisplayed() { | 86 void BrowserCompositorOutputSurface::OnSurfaceDisplayed() { |
| 101 cc::OutputSurface::OnSwapBuffersComplete(); | 87 cc::OutputSurface::OnSwapBuffersComplete(); |
| 102 } | 88 } |
| 103 #endif | 89 #endif |
| 104 | 90 |
| 105 } // namespace content | 91 } // namespace content |
| OLD | NEW |