| 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/trace_event/trace_event.h" |    9 #include "base/trace_event/trace_event.h" | 
|   10 #include "cc/output/compositor_frame.h" |   10 #include "cc/output/compositor_frame.h" | 
|   11 #include "cc/output/copy_output_request.h" |   11 #include "cc/output/copy_output_request.h" | 
|   12 #include "cc/surfaces/surface.h" |   12 #include "cc/surfaces/surface.h" | 
|   13 #include "cc/surfaces/surface_factory_client.h" |   13 #include "cc/surfaces/surface_factory_client.h" | 
|   14 #include "cc/surfaces/surface_manager.h" |   14 #include "cc/surfaces/surface_manager.h" | 
|   15 #include "ui/gfx/geometry/size.h" |   15 #include "ui/gfx/geometry/size.h" | 
|   16  |   16  | 
|   17 namespace cc { |   17 namespace cc { | 
|   18 SurfaceFactory::SurfaceFactory(const FrameSinkId& frame_sink_id, |   18 SurfaceFactory::SurfaceFactory(const FrameSinkId& frame_sink_id, | 
|   19                                SurfaceManager* manager, |   19                                SurfaceManager* manager, | 
|   20                                SurfaceFactoryClient* client) |   20                                SurfaceFactoryClient* client) | 
|   21     : frame_sink_id_(frame_sink_id), |   21     : frame_sink_id_(frame_sink_id), | 
|   22       manager_(manager), |   22       manager_(manager), | 
|   23       client_(client), |   23       client_(client), | 
|   24       holder_(client), |   24       holder_(client), | 
|   25       needs_sync_points_(true) {} |   25       needs_sync_points_(true), | 
 |   26       weak_factory_(this) {} | 
|   26  |   27  | 
|   27 SurfaceFactory::~SurfaceFactory() { |   28 SurfaceFactory::~SurfaceFactory() { | 
|   28   if (!surface_map_.empty()) { |   29   if (!surface_map_.empty()) { | 
|   29     LOG(ERROR) << "SurfaceFactory has " << surface_map_.size() |   30     LOG(ERROR) << "SurfaceFactory has " << surface_map_.size() | 
|   30                << " entries in map on destruction."; |   31                << " entries in map on destruction."; | 
|   31   } |   32   } | 
|   32   DestroyAll(); |   33   DestroyAll(); | 
|   33 } |   34 } | 
|   34  |   35  | 
|   35 void SurfaceFactory::DestroyAll() { |   36 void SurfaceFactory::DestroyAll() { | 
|   36   if (manager_) { |   37   if (manager_) { | 
|   37     for (auto& pair : surface_map_) |   38     for (auto& pair : surface_map_) | 
|   38       manager_->Destroy(std::move(pair.second)); |   39       manager_->Destroy(std::move(pair.second)); | 
|   39   } |   40   } | 
|   40   surface_map_.clear(); |   41   surface_map_.clear(); | 
|   41 } |   42 } | 
|   42  |   43  | 
 |   44 void SurfaceFactory::Reset() { | 
 |   45   DestroyAll(); | 
 |   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  | 
|   43 void SurfaceFactory::Create(const LocalFrameId& local_frame_id) { |   52 void SurfaceFactory::Create(const LocalFrameId& local_frame_id) { | 
|   44   std::unique_ptr<Surface> surface(base::MakeUnique<Surface>( |   53   auto surface(base::MakeUnique<Surface>( | 
|   45       SurfaceId(frame_sink_id_, local_frame_id), this)); |   54       SurfaceId(frame_sink_id_, local_frame_id), weak_factory_.GetWeakPtr())); | 
|   46   manager_->RegisterSurface(surface.get()); |   55   manager_->RegisterSurface(surface.get()); | 
|   47   DCHECK(!surface_map_.count(local_frame_id)); |   56   DCHECK(!surface_map_.count(local_frame_id)); | 
|   48   surface_map_[local_frame_id] = std::move(surface); |   57   surface_map_[local_frame_id] = std::move(surface); | 
|   49 } |   58 } | 
|   50  |   59  | 
|   51 void SurfaceFactory::Destroy(const LocalFrameId& local_frame_id) { |   60 void SurfaceFactory::Destroy(const LocalFrameId& local_frame_id) { | 
|   52   OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id); |   61   OwningSurfaceMap::iterator it = surface_map_.find(local_frame_id); | 
|   53   DCHECK(it != surface_map_.end()); |   62   DCHECK(it != surface_map_.end()); | 
|   54   DCHECK(it->second->factory().get() == this); |   63   DCHECK(it->second->factory().get() == this); | 
|   55   std::unique_ptr<Surface> surface(std::move(it->second)); |   64   std::unique_ptr<Surface> surface(std::move(it->second)); | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  119  |  128  | 
|  120 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { |  129 void SurfaceFactory::RefResources(const TransferableResourceArray& resources) { | 
|  121   holder_.RefResources(resources); |  130   holder_.RefResources(resources); | 
|  122 } |  131 } | 
|  123  |  132  | 
|  124 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { |  133 void SurfaceFactory::UnrefResources(const ReturnedResourceArray& resources) { | 
|  125   holder_.UnrefResources(resources); |  134   holder_.UnrefResources(resources); | 
|  126 } |  135 } | 
|  127  |  136  | 
|  128 }  // namespace cc |  137 }  // namespace cc | 
| OLD | NEW |