| 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 "cc/surfaces/surface_factory.h" | 5 #include "cc/surfaces/surface_factory.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 // could cause a crash or some unexpected behaviour. | 34 // could cause a crash or some unexpected behaviour. |
| 35 DCHECK(!current_surface_) << "Please call EvictSurface before destruction"; | 35 DCHECK(!current_surface_) << "Please call EvictSurface before destruction"; |
| 36 } | 36 } |
| 37 | 37 |
| 38 void SurfaceFactory::EvictSurface() { | 38 void SurfaceFactory::EvictSurface() { |
| 39 if (!current_surface_) | 39 if (!current_surface_) |
| 40 return; | 40 return; |
| 41 Destroy(std::move(current_surface_)); | 41 Destroy(std::move(current_surface_)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void SurfaceFactory::Reset() { | |
| 45 EvictSurface(); | |
| 46 // Disown Surfaces that are still alive so that they don't try to unref | |
| 47 // resources that we're not tracking any more. | |
| 48 weak_factory_.InvalidateWeakPtrs(); | |
| 49 holder_.Reset(); | |
| 50 } | |
| 51 | |
| 52 void SurfaceFactory::SubmitCompositorFrame( | 44 void SurfaceFactory::SubmitCompositorFrame( |
| 53 const LocalSurfaceId& local_surface_id, | 45 const LocalSurfaceId& local_surface_id, |
| 54 CompositorFrame frame, | 46 CompositorFrame frame, |
| 55 const DrawCallback& callback) { | 47 const DrawCallback& callback) { |
| 56 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); | 48 TRACE_EVENT0("cc", "SurfaceFactory::SubmitCompositorFrame"); |
| 57 DCHECK(local_surface_id.is_valid()); | 49 DCHECK(local_surface_id.is_valid()); |
| 58 std::unique_ptr<Surface> surface; | 50 std::unique_ptr<Surface> surface; |
| 59 bool create_new_surface = | 51 bool create_new_surface = |
| 60 (!current_surface_ || | 52 (!current_surface_ || |
| 61 local_surface_id != current_surface_->surface_id().local_surface_id()); | 53 local_surface_id != current_surface_->surface_id().local_surface_id()); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 surface->AddObserver(this); | 148 surface->AddObserver(this); |
| 157 return surface; | 149 return surface; |
| 158 } | 150 } |
| 159 | 151 |
| 160 void SurfaceFactory::Destroy(std::unique_ptr<Surface> surface) { | 152 void SurfaceFactory::Destroy(std::unique_ptr<Surface> surface) { |
| 161 surface->RemoveObserver(this); | 153 surface->RemoveObserver(this); |
| 162 manager_->DestroySurface(std::move(surface)); | 154 manager_->DestroySurface(std::move(surface)); |
| 163 } | 155 } |
| 164 | 156 |
| 165 } // namespace cc | 157 } // namespace cc |
| OLD | NEW |